• <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精品久久精品一区二区| 伊人久久大香线蕉综合5g| 久久久久亚洲av无码专区| 国产毛片久久久久久国产毛片| 久久99热这里只频精品6| 精品久久久久久99人妻| 国产激情久久久久影院老熟女免费| 欧美牲交A欧牲交aⅴ久久| 国产成人精品综合久久久| 亚洲中文字幕无码久久综合网| 久久99热这里只有精品国产| 久久AV无码精品人妻糸列| 午夜不卡久久精品无码免费| 天天躁日日躁狠狠久久| 精品久久一区二区| 国产99久久久国产精免费| 99久久国产精品免费一区二区| av午夜福利一片免费看久久| 99久久无码一区人妻a黑| 成人午夜精品无码区久久| 久久久久久国产a免费观看黄色大片| 久久婷婷五月综合97色直播| 香蕉久久永久视频| 成人a毛片久久免费播放| 久久久精品午夜免费不卡| 少妇久久久久久被弄到高潮 | 久久精品国产免费| 久久精品国内一区二区三区| 久久精品国产精品亚洲人人| 亚洲中文字幕无码久久2020| 国产亚洲色婷婷久久99精品91| 国内精品久久久久影院优| 亚洲中文字幕无码久久2020| 久久久久亚洲爆乳少妇无| 国内精品久久久久影院优| 97r久久精品国产99国产精| 久久精品99久久香蕉国产色戒| 99久久无码一区人妻|