- 论坛徽章:
- 0
|
可以从环境变量/命令行参数/ini文件/xml文件中读配置, 下面是一个具体的用例.
- typedef struct
- {
- char Db_Type_Name[60];
- int Db_Type;
- char Db_Name[300];
- char User_Name[60];
- char Password[60];
- char Host[60];
- int Port;
- int Direct_Mode;
- }Db_Set_Info_Stru;
- #include <opt.h>
- class TDb_Opt : public TOpt
- {
- public:
- Db_Set_Info_Stru * mInfo;
- public:
- TDb_Opt(Db_Set_Info_Stru * ptr);
- int Get_Ext();
- int Show_Ext();
- };
- TDb_Opt::TDb_Opt(Db_Set_Info_Stru * ptr)
- {
- mInfo = ptr;
- mOpt_Num = 0;
- memset(ptr,0,sizeof(Db_Set_Info_Stru));
- Def("type",ptr->Db_Type_Name);
- Def("dbname",ptr->Db_Name);
- Def("user",ptr->User_Name);
- Def("password",ptr->Password);
- Def("host",ptr->Host);
- Def("port",&ptr->Port);
- Def("direct_mode",&ptr->Direct_Mode);
- };
- int TDb_Opt::Get_Ext()
- {
- mInfo->Db_Type = Get_Db_Type(mInfo->Db_Type_Name);
- return 1;
- };
- int TDb_Opt::Show_Ext()
- {
- printf("DB_TYPE : %d\n",mInfo->Db_Type);
- return 1;
- };
复制代码 |
|