mirror of
https://gitee.com/jiuyilian/embedded-framework.git
synced 2025-01-06 10:16:51 -05:00
106 lines
4.5 KiB
C++
106 lines
4.5 KiB
C++
/*
|
|
* 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.
|
|
*/
|
|
/**
|
|
* @file IConfigBase.h
|
|
* @brief Defines the interface for configuration base operations.
|
|
*
|
|
* This header file declares the IConfigBase interface and associated types for
|
|
* managing configuration settings. It provides a common set of functions for
|
|
* interacting with configuration data, which can be implemented by various
|
|
* configuration backends.
|
|
*/
|
|
#ifndef I_CONFIG_BASE_H
|
|
#define I_CONFIG_BASE_H
|
|
#include "StatusCode.h"
|
|
#include <memory>
|
|
/**
|
|
* @class IConfigBase
|
|
* @brief Interface for configuration management.
|
|
*
|
|
* IConfigBase is an abstract interface that defines the contract for configuration
|
|
* operations. Concrete implementations of this interface will provide the
|
|
* functionality for opening, modifying, and saving configuration settings.
|
|
*/
|
|
class 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);
|
|
};
|
|
/**
|
|
* @struct IConfigBaseHeader
|
|
* @brief A structure that may be used for validation or recognition purposes.
|
|
*
|
|
* This structure is meant to contain a pointer to a character which could be
|
|
* utilized for some form of validation or recognition check.
|
|
*/
|
|
typedef struct i_config_base_header // Defined a struct i_config.base_header containing a pointer mCheckName to a
|
|
// character, which may be used for some form of validation or recognition.
|
|
{
|
|
const char *mCheckName;
|
|
} IConfigBaseHeader;
|
|
/**
|
|
* @struct ConfigBase
|
|
* @brief A structure that combines the IConfigBaseHeader with a shared pointer to IConfigBase.
|
|
*
|
|
* This structure is intended to provide additional context or metadata along with
|
|
* the actual configuration base object.
|
|
*/
|
|
typedef struct config_base
|
|
{
|
|
IConfigBaseHeader mHeader;
|
|
std::shared_ptr<IConfigBase> mIConfigBase;
|
|
} ConfigBase;
|
|
/**
|
|
* @brief Gets the module name of the configuration base.
|
|
*
|
|
* This function returns a constant character pointer to the module name as a string.
|
|
*
|
|
* @return A constant character pointer to the module name.
|
|
*/
|
|
const char *GetConfigBaseModuleName(void);
|
|
/**
|
|
* @brief Creates a new instance of the IConfigBase implementation.
|
|
*
|
|
* This function constructs a new ConfigBase structure with a shared pointer to an
|
|
* IConfigBase object, initialized with the provided file name.
|
|
*
|
|
* @param fileName The name of the configuration file to associate with the new object.
|
|
* @return A pointer to a new ConfigBase structure.
|
|
*/
|
|
std::shared_ptr<IConfigBase> *NewConfigBase(const char *fileName);
|
|
#endif
|