• <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文件名為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)通常的配置功能,更重要的是,可以進一步擴展為多級的樹形結(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ǔ)
            久久综合给合久久狠狠狠97色| 久久久久久a亚洲欧洲aⅴ| 日产精品久久久久久久| 亚洲va中文字幕无码久久不卡| 久久久久综合网久久| 国产精品久久久久久久久软件| 精品熟女少妇av免费久久| 久久亚洲AV无码西西人体| 97久久超碰国产精品2021| 综合久久一区二区三区| 一本一道久久精品综合| 久久国产色AV免费观看| 日韩精品无码久久一区二区三| 国产国产成人精品久久| 精品国产99久久久久久麻豆| 久久国产综合精品五月天| 国产91色综合久久免费| 亚洲精品美女久久久久99| 热RE99久久精品国产66热| 国内精品久久久久久久久| 91精品国产综合久久婷婷| 久久久久亚洲AV无码永不| 久久天天躁狠狠躁夜夜2020一 | 久久青草国产手机看片福利盒子| 久久这里的只有是精品23| 欧洲国产伦久久久久久久| 精品久久久无码中文字幕| 91久久精品国产免费直播| 久久久国产精品福利免费| 久久精品国产一区| 欧美一区二区精品久久| 久久香蕉国产线看观看99| 久久91精品国产91久久小草 | 久久久亚洲精品蜜桃臀| 久久国产精品视频| 久久青青草原精品国产软件| 久久久99精品成人片中文字幕| 久久精品国产亚洲AV不卡| 久久久久成人精品无码| 四虎亚洲国产成人久久精品| 久久亚洲中文字幕精品一区|