embedded-framework/utils/ConfigBaseImpl.h
张耀 cacb6dcbf8
configbasee
Signed-off-by: 张耀 <3213487792@qq.com>
2024-07-27 08:40:25 +00:00

52 lines
3.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Copyright (c) 2023 Fancy Code.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef CONFIG_BASE_IMPL_H
#define CONFIG_BASE_IMPL_H
//标准的头文件保护,用于防止头文件被重复包含。
#include "IConfigBase.h"//这是一个接口定义文件ConfigBaseImpl类实现了这个接口中声明的所有纯虚函数。
#include <libconfig.h>//这是libconfig库的头文件提供了处理配置文件的API。
#include <string>//C++标准库中的字符串处理类。
class ConfigBaseImpl : public IConfigBase//ConfigBaseImpl类继承自IConfigBase接口这意味着它需要实现接口中声明的所有纯虚函数。
{
public:
ConfigBaseImpl(const std::string &fileName);
virtual ~ConfigBaseImpl() = default;
bool OpenConfigFile(void) override;//打开配置文件
void CloseConfigFile(void) override;//关闭配置文件
StatusCode ConfigSaveFile(void) override;//用于将配置更改保存回文件但返回类型是StatusCode
StatusCode ConfigGetInt(const char *name, int *value) override;
StatusCode ConfigSetInt(const char *name, const int value) override;
StatusCode ConfigGetShort(const char *name, short *value) override;
StatusCode ConfigSetShort(const char *name, const short value) override;
StatusCode ConfigGetLong(const char *name, long *value) override;
StatusCode ConfigSetLong(const char *name, const long value) override;
StatusCode ConfigGetLLong(const char *name, long long *value) override;
StatusCode ConfigSetLLong(const char *name, const long long value) override;
StatusCode ConfigGetChar(const char *name, char *value) override;
StatusCode ConfigSetChar(const char *name, const char value) override;
StatusCode ConfigGetBool(const char *name, bool *value) override;
StatusCode ConfigSetBool(const char *name, const bool value) override;
StatusCode ConfigGetFloat(const char *name, float *value) override;
StatusCode ConfigSetFloat(const char *name, const float value) override;
StatusCode ConfigGetDouble(const char *name, double *value) override;
StatusCode ConfigSetDouble(const char *name, const double value) override;
StatusCode ConfigGetString(const char *name, const char **value) override;
StatusCode ConfigSetString(const char *name, const char *value) override;
//这些函数提供了从配置文件中获取和设置各种数据类型如整数、浮点数、字符串等的接口。它们接受一个配置项的名称和一个指向值的指针对于Get函数或值本身对于Set函数并返回一个StatusCode表示操作结果。
private:
const std::string mFileName;// 存储配置文件的路径。
config_t mCfg;//libconfig库中的config_t类型用于表示配置文件的内部结构。
};
#endif