<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          myconfconf 配置文件解析庫(kù)

          聯(lián)合創(chuàng)作 · 2023-09-28 18:24

          myconf是一個(gè)可以方便讀取key-value配置的C/C++庫(kù)。
          1 規(guī)則如下 
          1)、配置為 key : value 格式 
          2)、可以支持讀取int(正負(fù)數(shù)), unsigend int, char *, 支持默認(rèn)缺省值。
          3)、string如果有特殊字符(如空格等)需要加上""(如"你 好");
          4)、使用完必須調(diào)用關(guān)閉日志文件句柄,否則有內(nèi)存泄漏。
          5)、需要使用mylog編譯依賴, 編譯主要修改Makefile置頂工作目錄WORKROOT,然后通過(guò)makefile.env指定MYLOG、MYCONF的路徑

          2 API
          1) 初始化日志句柄

          MY_CONF_INS* my_conf_init(const char* file_path, const char* file_name); 

          file_path: 配置目錄
          file_name: 配置文件

          2) 獲得int

          MY_CONF_GET_INT32(key, confs, input_value) 

          key :獲得key
          confs: 配置文件句柄
          input_value : 配置返回的結(jié)果引用
          注意:成功返回true,否則返回false

          3) 缺省獲得int

          MY_CONF_GET_INT32_DEFAULT(key, confs, input_value, default_value) 

          key :獲得key
          confs: 配置文件句柄
          input_value : 配置返回的結(jié)果引用
          default_value :如果沒(méi)有結(jié)果,返回default_value
          注意:成功返回true,否則返回false

          4) 獲得unsigned int

          MY_CONF_GET_UINT32(key, confs, input_value) 

          key :獲得key
          confs: 配置文件句柄
          input_value : 配置返回的結(jié)果引用
          注意:成功返回true,否則返回false

          5) 缺省獲得unsigned int

          MY_CONF_GET_INT32_DEFAULT(key, confs, input_value, default_value) 

          key :獲得key
          confs: 配置文件句柄
          input_value : 配置返回的結(jié)果引用
          default_value :如果沒(méi)有結(jié)果,返回default_value
          注意:成功返回true,否則返回false

          6) 獲得string

          MY_CONF_GET_STR(key, confs, input_str) 

          key :獲得key
          confs: 配置文件句柄
          input_str : 配置返回的結(jié)果引用
          注意:成功返回true,否則返回false, input_str必須申請(qǐng)初始化大小

          7) 缺省獲得string

          MY_CONF_GET_STR_DEFAULT(key, confs, input_str, default_str) 

          key :獲得key
          confs: 配置文件句柄
          input_str : 配置返回的結(jié)果引用
          default_str : 如果沒(méi)有結(jié)果返回缺省值
          注意:成功返回true,否則返回false, input_str必須申請(qǐng)初始化大小

          3 示例

           1) 代碼

          #include "mylog.h"
          #include "myconf.h"
          #include 
          using namespace std;
          
          
          int main()
          {
              my_log_init("./log", "sample.log", "sample.log.wf", 16);
              MY_LOG_DEBUG("main begin");
          
              MY_CONF_INS* my_ins = my_conf_init("./conf", "sample.conf");
              if( my_ins == NULL)
              {
                  MY_LOG_FATAL("file is not exist or not vaild");
                  return -1;
              }
          
              bool ret;
              //get int
              int int_a1;
              ret = MY_CONF_GET_INT32("int_a", my_ins, int_a1);
              if(ret == true)
              {
                  cout << "int_a1 is " << int_a1 << endl;
              }
              else
              {
                  cout << "get int_a1 fail";
              }
          
              //get uint32
              uint32 uint32_b1;
              ret = MY_CONF_GET_UINT32("int_b", my_ins, uint32_b1);
              cout << "uint32_b1 is " << uint32_b1 << endl;
          
              //get int 缺省值
              uint32 int_a2;
              ret = MY_CONF_GET_UINT32_DEFAULT("int_a_default", my_ins, int_a2, 100);
              cout << "int_a_default " << int_a2 << endl;
          
              char string_noraml[1024];
              ret = MY_CONF_GET_STR("string_noraml", my_ins, string_noraml);
              cout << "string_noraml is " <<  string_noraml << endl;
          
              char string_quoto[1024];
              ret = MY_CONF_GET_STR("string_quoto", my_ins, string_quoto);
              cout << "string_quoto is " <<  string_quoto << endl;
          
              my_conf_close(my_ins);
              MY_LOG_DEBUG("main end");
              return 0;
          
          }

          b) 運(yùn)行結(jié)果

          瀏覽 25
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  色综合系列婷婷 | 国产精品久久网 | 天天天天爽夜夜夜夜爽? | 一级特黄60分钟免费 | 欧美黑人一级视频 |