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

62 lines
4.0 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 I_CONFIG_BASE_H
#define I_CONFIG_BASE_H
//头文件保护(防止头文件被重复包含)。
#include "StatusCode.h"
#include <memory>
//StatusCode.h可能是一个定义状态码枚举或类的文件用于表示操作成功或失败的状态和<memory>C++标准库中的一部分,提供智能指针等内存管理功能)。
class IConfigBase// IConfigBase 接口
{
public:
IConfigBase() = default;
virtual ~IConfigBase() = default;
virtual bool OpenConfigFile(void);
virtual void CloseConfigFile(void);
virtual StatusCode ConfigSaveFile(void);
virtual StatusCode ConfigGetInt(const char *name, int *value);
virtual StatusCode ConfigSetInt(const char *name, const int value);
virtual StatusCode ConfigGetShort(const char *name, short *value);
virtual StatusCode ConfigSetShort(const char *name, const short value);
virtual StatusCode ConfigGetLong(const char *name, long *value);
virtual StatusCode ConfigSetLong(const char *name, const long value);
virtual StatusCode ConfigGetLLong(const char *name, long long *value);
virtual StatusCode ConfigSetLLong(const char *name, const long long value);
virtual StatusCode ConfigGetChar(const char *name, char *value);
virtual StatusCode ConfigSetChar(const char *name, const char value);
virtual StatusCode ConfigGetBool(const char *name, bool *value);
virtual StatusCode ConfigSetBool(const char *name, const bool value);
virtual StatusCode ConfigGetFloat(const char *name, float *value);
virtual StatusCode ConfigSetFloat(const char *name, const float value);
virtual StatusCode ConfigGetDouble(const char *name, double *value);
virtual StatusCode ConfigSetDouble(const char *name, const double value);
virtual StatusCode ConfigGetString(const char *name, const char **value);
virtual StatusCode ConfigSetString(const char *name, const char *value);
};
//IConfigBase是一个抽象基类定义了与配置管理相关的接口。它包含了构造函数和析构函数的默认实现即不执行任何操作以及一系列虚函数用于打开和关闭配置文件、保存配置以及获取和设置各种数据类型的配置值。这些虚函数的具体实现将由派生类提供。
typedef struct i_config_base_header//定义了一个结构体i_config_base_header包含一个指向字符的指针mCheckName可能用于某种形式的验证或识别。
{
const char *mCheckName;
} IConfigBaseHeader;
typedef struct config_base//定义了一个结构体config_base它包含一个IConfigBaseHeader类型的成员mHeader和一个指向IConfigBase的智能指针mIConfigBase。这个结构体可能用于在应用程序中存储和管理配置实例。
{
IConfigBaseHeader mHeader;
std::shared_ptr<IConfigBase> mIConfigBase;
} ConfigBase;
const char *GetConfigBaseModuleName(void);
std::shared_ptr<IConfigBase> *NewConfigBase(const char *fileName);
//声明了两个函数GetConfigBaseModuleName可能用于获取配置模块的名称和NewConfigBase接受一个文件名作为参数并返回一个指向IConfigBase智能指针的指针用于创建和返回一个新的配置实例
#endif
//这段代码定义了一个用于配置管理的C++接口和相关数据结构以及与之相关的函数声明。它使用了C++的抽象基类、虚函数、智能指针等特性来实现灵活的配置管理功能。