• <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>

            網(wǎng)絡(luò)服務(wù)器軟件開發(fā)/中間件開發(fā),關(guān)注ACE/ICE/boost

            C++博客 首頁 新隨筆 聯(lián)系 聚合 管理
              152 Posts :: 3 Stories :: 172 Comments :: 0 Trackbacks
                 自從做公司的SNS社區(qū)以來,寫了不少的C#代碼,與C++相比,C#是易于使用的,開發(fā)效率提高很多倍,其中印象比較深刻的是,在一個C#工程中,可以通過向?qū)砑优渲梦募J(rèn)文件名為App.Config,是XML格式,一般內(nèi)容為:
            <?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元素,即可實現(xiàn)通常的配置功能,更重要的是,可以進(jìn)一步擴展為多級的樹形結(jié)構(gòu),與Ini格式相比,更直觀,可讀性更強,下面是基于CMarkup(http://www.firstobject.com/)的一個簡單實現(xiàn):
            頭文件如下:
            #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 : 定義控制臺應(yīng)用程序的入口點。
            //

            #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 閱讀(2567) 評論(0)  編輯 收藏 引用 所屬分類: 其它開源庫C++基礎(chǔ)
            久久精品夜夜夜夜夜久久| 国产精品久久久久国产A级| 亚洲国产精品热久久| 2020最新久久久视精品爱| 久久九色综合九色99伊人| 日本WV一本一道久久香蕉| 亚洲国产另类久久久精品小说| 久久av无码专区亚洲av桃花岛| www.久久99| 欧美色综合久久久久久| 久久久久人妻精品一区二区三区 | 97久久香蕉国产线看观看| 久久91精品国产91久久户| 四虎亚洲国产成人久久精品| 久久久久人妻精品一区| 久久性生大片免费观看性| 久久精品中文騷妇女内射| 伊人伊成久久人综合网777| 国产精品久久久久久福利69堂| 无码国内精品久久综合88 | 人妻无码精品久久亚瑟影视| 99久久精品国产高清一区二区| 亚洲精品无码久久久久AV麻豆| 狠狠精品久久久无码中文字幕| 久久精品aⅴ无码中文字字幕不卡| 久久久国产视频| 日韩中文久久| 久久高潮一级毛片免费| 国产精品99久久不卡| 国产一级做a爰片久久毛片| 少妇久久久久久久久久| 中文字幕久久精品| 久久免费香蕉视频| 国产午夜精品久久久久九九电影| 久久精品成人免费看| 久久精品嫩草影院| www.久久热.com| 国内精品久久久久久中文字幕| 99精品伊人久久久大香线蕉| 办公室久久精品| 亚洲国产精品嫩草影院久久 |