/* * 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. */ #include "ConfigBase.h" #include "IConfigBase.h" #include "ILog.h" static bool ObjectCheck(void *object) { if (nullptr == object) { LogError("nullptr object!\n"); return false; } if (*((const char **)(((char *)object) - sizeof(IConfigBase))) != GetConfigBaseModuleName()) { LogError("Illegal object!\n"); return false; } return true; } void *OpenConfigFile(const char *fileName) { std::shared_ptr *configObject = NewConfigBase(fileName); if (nullptr != configObject) { (*configObject)->OpenConfigFile(); } return configObject; } StatusCode ConfigSaveFile(void *object) { if (ObjectCheck(object) == true) { return (*(std::shared_ptr *)object)->ConfigSaveFile(); } return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER); } void CloseConfigFile(void *object) { if (ObjectCheck(object) == true) { (*(std::shared_ptr *)object)->CloseConfigFile(); (*(std::shared_ptr *)object).reset(); free(((char *)object) - sizeof(IConfigBase)); // TODO: bug? } } StatusCode ConfigGetInt(void *object, const char *name, int *value) { if (ObjectCheck(object) == true) { return (*(std::shared_ptr *)object)->ConfigGetInt(name, value); } return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER); } StatusCode ConfigSetInt(void *object, const char *name, const int value) { if (ObjectCheck(object) == true) { return (*(std::shared_ptr *)object)->ConfigSetInt(name, value); } return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER); } StatusCode ConfigGetShort(void *object, const char *name, short *value) { if (ObjectCheck(object) == true) { return (*(std::shared_ptr *)object)->ConfigGetShort(name, value); } return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER); } StatusCode ConfigSetShort(void *object, const char *name, const short value) { if (ObjectCheck(object) == true) { return (*(std::shared_ptr *)object)->ConfigSetShort(name, value); } return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER); } StatusCode ConfigGetLong(void *object, const char *name, long *value) { if (ObjectCheck(object) == true) { return (*(std::shared_ptr *)object)->ConfigGetLong(name, value); } return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER); } StatusCode ConfigSetLong(void *object, const char *name, const long value) { if (ObjectCheck(object) == true) { return (*(std::shared_ptr *)object)->ConfigSetLong(name, value); } return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER); } StatusCode ConfigGetLLong(void *object, const char *name, long long *value) { if (ObjectCheck(object) == true) { return (*(std::shared_ptr *)object)->ConfigGetLLong(name, value); } return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER); } StatusCode ConfigSetLLong(void *object, const char *name, const long long value) { if (ObjectCheck(object) == true) { return (*(std::shared_ptr *)object)->ConfigSetLLong(name, value); } return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER); } StatusCode ConfigGetChar(void *object, const char *name, char *value) { if (ObjectCheck(object) == true) { return (*(std::shared_ptr *)object)->ConfigGetChar(name, value); } return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER); } StatusCode ConfigSetChar(void *object, const char *name, const char value) { if (ObjectCheck(object) == true) { return (*(std::shared_ptr *)object)->ConfigSetChar(name, value); } return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER); } StatusCode ConfigGetBool(void *object, const char *name, bool *value) { if (ObjectCheck(object) == true) { return (*(std::shared_ptr *)object)->ConfigGetBool(name, value); } return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER); } StatusCode ConfigSetBool(void *object, const char *name, const bool value) { if (ObjectCheck(object) == true) { return (*(std::shared_ptr *)object)->ConfigSetBool(name, value); } return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER); } StatusCode ConfigGetFloat(void *object, const char *name, float *value) { if (ObjectCheck(object) == true) { return (*(std::shared_ptr *)object)->ConfigGetFloat(name, value); } return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER); } StatusCode ConfigSetFloat(void *object, const char *name, const float value) { if (ObjectCheck(object) == true) { return (*(std::shared_ptr *)object)->ConfigSetFloat(name, value); } return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER); } StatusCode ConfigGetDouble(void *object, const char *name, double *value) { if (ObjectCheck(object) == true) { return (*(std::shared_ptr *)object)->ConfigGetDouble(name, value); } return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER); } StatusCode ConfigSetDouble(void *object, const char *name, const double value) { if (ObjectCheck(object) == true) { return (*(std::shared_ptr *)object)->ConfigSetDouble(name, value); } return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER); } StatusCode ConfigGetString(void *object, const char *name, const char **value) { if (ObjectCheck(object) == true) { return (*(std::shared_ptr *)object)->ConfigGetString(name, value); } return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER); } StatusCode ConfigSetString(void *object, const char *name, const char *value) { if (ObjectCheck(object) == true) { return (*(std::shared_ptr *)object)->ConfigSetString(name, value); } return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER); }