logplus/Workflow/WFCrystal/SysUtility/configuration/include/Configure.h
2026-01-16 17:18:41 +08:00

163 lines
3.1 KiB
C++

/*
* Configure.h
*
* Created on: 2011-11-16
*
* @file Configure.h
* @brief 定义配置文件操作类
*/
#ifndef PAI_FRAME_SYSUTILITY_CONFIGURE_H
#define PAI_FRAME_SYSUTILITY_CONFIGURE_H
#include <string>
#include <map>
#include <stdio.h>
#include <vector>
#include <iostream>
#include <string.h>
#include "Turtle.h"
namespace pai {
namespace conf {
typedef std::map<std::string, std::string> map_type;
/**
* @class CConfigure
* @brief 配置文件操作类
*
*/
class PAI_CONFIGURE_EXPORT CConfigure
{
public:
/**
* @brief 默认构造函数
*
*/
CConfigure();
/**
* @brief 构造函数
*
* @param[in] path 配置文件路径及名称
*
*/
CConfigure(const std::string& configureFileName);
/**
* @brief 构造函数
*
* @param[in] path 配置文件路径及名称
*
*/
CConfigure(const char* configureFileName);
/**
* @brief 拷贝构造
*/
CConfigure(const CConfigure & lrh);
/**
* @brief 赋值
*/
CConfigure & operator = (const CConfigure & lrh);
/**
* @brief 析构函数
*
*/
~CConfigure();
/**
* @brief 根据关键字获取值
*
* @param[in] key 关键字
* @return 与关键字对应的值
*/
std::string GetValueByKey(const std::string& key);
/**
* @brief 根据关键字获取值
*
* @param[in] key 关键字
* @return 与关键字对应的值
*/
std::string GetValueByKey(const char* key);
/**
* @brief 获取配置文件中所有的关键字列表
*
* @param[out] key 关键字列表
*/
void GetKeys(std::vector<std::string>& key) const;
/**
* @brief 获得关键字 map
*/
std::map<std::string, std::string> GetKeys() const;
/**
* @brief 打印配置文件信息
*
*/
void Print();
/**
* @brief 获取文件的有效行数
*
*/
int GetMapSize();
private:
/**
* @brief 通过配置文件名设置配置文件值
*
* @param[in] configureFileName 文件名
*/
void SetFromFile(const std::string& path);
/**
* @brief 读取PAI_HOME环境变量
*/
std::string GetPaiHomePath();
void SetFromLine(const char* configureLine);
std::string ParseRawKey(std::string& rawKey);
std::string ParseRawValue(std::string& rawValue);
/**
* @brief replace specific word
*
* @param[in] word to replace.
*
* @param[in] using env value to replace or not.
*
*/
std::string replaceWord(std::string& word,bool usingEnv);
std::string replaceWithEnvValue(const std::string& key);
//std::string FindEnvValue(std::string& str);
/**
* @brief get absolute file path.
*
* @param[in] relative path or absolute path.
*/
std::string GetConfigureFilePath(const std::string& str);
/**
* @brief check the file existence using absolute path
*
* @param[in] absolute path
*
*/
bool ExistFile(const char* path);
void replaceEnvromentValue();
int recount;
map_type m_configureValue;
protected:
};
}
}
#endif