• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            網絡服務器軟件開發/中間件開發,關注ACE/ICE/boost

            C++博客 首頁 新隨筆 聯系 聚合 管理
              152 Posts :: 3 Stories :: 172 Comments :: 0 Trackbacks
                 自從做公司的SNS社區以來,寫了不少的C#代碼,與C++相比,C#是易于使用的,開發效率提高很多倍,其中印象比較深刻的是,在一個C#工程中,可以通過向導添加配置文件,默認文件名為App.Config,是XML格式,一般內容為:
            <?xml version="1.0" encoding="utf-8" ?>
            <configuration>
                 
                
            <appSettings>

                    
            <add key="Ip" value="localhost"/>
                    
            <add key="Port" value="8888"/>
                    
            <add key="ServiceName" value="Indexer"/>


                
            </appSettings>
                
            </configuration>
            通過在appSettings里面添加add元素,即可實現通常的配置功能,更重要的是,可以進一步擴展為多級的樹形結構,與Ini格式相比,更直觀,可讀性更強,下面是基于CMarkup(http://www.firstobject.com/)的一個簡單實現:
            頭文件如下:
            #pragma once

            #include 
            <string>
            #include 
            <map>


            class AppConfig
            {
            public:
                AppConfig(
            void);
                
            ~AppConfig(void);

                
            int        GetInt(std::string key);
                std::
            string    GetString(std::string key);
            private:
                std::map
            <std::string,std::string> config_map_;
            }
            ;
             
            extern AppConfig appConfig;
            源文件如下:

            #include 
            "AppConfig.h"
            #include 
            "Markup.h"

            AppConfig appConfig;


            AppConfig::AppConfig(
            void)
            {
                CMarkup parser;
                
            if (!parser.Load( "App.Config"  ))
                
            {
                    
            return;        
                }

                
            if (parser.FindChildElem("appSettings"))
                
            {
                    parser.IntoElem();
                    
            while (parser.FindChildElem("add"))
                    
            {
                        std::
            string key = parser.GetChildAttrib("key");
                        std::
            string value = parser.GetChildAttrib("value");
                        config_map_[key] 
            = value;
                    }

                    parser.OutOfElem();
                }

                
            }


            AppConfig::
            ~AppConfig(void)
            {
            }


            int AppConfig::GetInt( std::string key )
            {
                
            if (config_map_.find(key) != config_map_.end())
                
            {
                    
            return atoi(config_map_[key].c_str());
                }

                
            else
                
            {
                    
            return 0;
                }

            }


            std::
            string AppConfig::GetString( std::string key )
            {
                
            if (config_map_.find(key) != config_map_.end())
                
            {
                    
            return config_map_[key];
                }

                
            else
                
            {
                    
            return "";
                }

            }

            測試代碼為:
            // MarkupTest.cpp : 定義控制臺應用程序的入口點。
            //

            #include 
            "stdafx.h"

            #include 
            "AppConfig.h"
            #include 
            <iostream>
            using namespace std;

            int _tmain(int argc, _TCHAR* argv[])
            {    
                cout 
            << appConfig.GetString("Ip")  << "-----" << appConfig.GetInt("Port")  << "----" << appConfig.GetString("ServiceName"<< endl;
                
            return 0;
            }


            posted on 2010-12-29 00:25 true 閱讀(2561) 評論(0)  編輯 收藏 引用 所屬分類: 其它開源庫C++基礎
            亚洲国产精品久久久久| 热综合一本伊人久久精品| 亚洲欧美国产日韩综合久久| 婷婷久久五月天| 亚洲av日韩精品久久久久久a| 欧洲成人午夜精品无码区久久| 久久丫精品国产亚洲av| 88久久精品无码一区二区毛片| 一级做a爰片久久毛片看看 | 狠狠狠色丁香婷婷综合久久俺| 久久亚洲国产午夜精品理论片| 合区精品久久久中文字幕一区| 久久精品国产亚洲AV高清热| 韩国三级中文字幕hd久久精品 | 久久精品综合一区二区三区| 2019久久久高清456| av无码久久久久不卡免费网站| 久久国产影院| 成人妇女免费播放久久久| 亚洲国产香蕉人人爽成AV片久久 | 日韩一区二区三区视频久久| 69SEX久久精品国产麻豆| 中文字幕精品久久| 久久精品国产亚洲7777| 久久精品aⅴ无码中文字字幕不卡 久久精品aⅴ无码中文字字幕重口 | 久久久久国产成人精品亚洲午夜| 久久狠狠爱亚洲综合影院| 色婷婷综合久久久久中文字幕 | 久久伊人精品青青草原日本| 99久久精品费精品国产一区二区| 99久久精品免费看国产一区二区三区 | 亚洲午夜久久久久妓女影院| 久久久久国产一级毛片高清板| av午夜福利一片免费看久久 | 久久线看观看精品香蕉国产| 午夜精品久久久久久久久| 国产精品久久久香蕉| 亚洲精品国产综合久久一线| 日韩中文久久| 伊人久久亚洲综合影院| 中文字幕精品久久|