• <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 閱讀(2566) 評論(0)  編輯 收藏 引用 所屬分類: 其它開源庫C++基礎
            精品久久久久成人码免费动漫| 久久久久久综合网天天| 99久久免费国产精精品| 久久精品国产99久久无毒不卡| 久久无码av三级| 天天综合久久一二三区| 色偷偷88888欧美精品久久久| 久久久久久亚洲精品成人| 国产亚州精品女人久久久久久 | 色综合久久天天综合| A级毛片无码久久精品免费| 亚洲综合久久夜AV | a级成人毛片久久| 久久久久亚洲AV片无码下载蜜桃| 精品国产乱码久久久久久郑州公司 | 国产综合久久久久| 久久精品国产精品亜洲毛片| 久久人人爽爽爽人久久久| 国产成人久久精品麻豆一区| 亚洲中文字幕无码久久2017| 国产成人综合久久久久久| 伊人久久久AV老熟妇色| 美女久久久久久| 日本精品久久久中文字幕 | 国产精品久久久久久吹潮| 亚洲精品成人久久久| 中文字幕亚洲综合久久| 人妻无码久久一区二区三区免费| 欧美伊人久久大香线蕉综合69 | 亚洲国产精品无码久久SM| 亚洲欧美成人久久综合中文网| 精品国产91久久久久久久| 久久综合噜噜激激的五月天| 久久精品国产亚洲AV忘忧草18| 人妻无码精品久久亚瑟影视| 国产香蕉97碰碰久久人人| 久久久久久免费一区二区三区 | 久久久久亚洲AV无码专区网站| 久久精品国产亚洲网站| 99久久无码一区人妻a黑| 久久天天躁狠狠躁夜夜网站|