From 6782441f4683334e184a3a3e0f5adc7f72506ce2 Mon Sep 17 00:00:00 2001 From: Antoine Beauchamp Date: Sun, 1 Jun 2025 16:54:45 -0400 Subject: [PATCH 1/2] Moved enums definitions from main.cpp to enums.h. Moved code related to these enums to common.h. --- src/bin2cpp/common.cpp | 53 ++++++++++++++++++++++ src/bin2cpp/common.h | 14 ++++++ src/bin2cpp/enums.h | 27 +++++++++++ src/bin2cpp/main.cpp | 75 +------------------------------ test/bin2cpp_unittest/TestCLI.cpp | 17 ++----- 5 files changed, 99 insertions(+), 87 deletions(-) diff --git a/src/bin2cpp/common.cpp b/src/bin2cpp/common.cpp index 62c7c01..eb4300e 100755 --- a/src/bin2cpp/common.cpp +++ b/src/bin2cpp/common.cpp @@ -41,6 +41,59 @@ namespace bin2cpp return BIN2CPP_VERSION; } + const char* getErrorCodeDescription(const APP_ERROR_CODES& error_code) + { + switch ( error_code ) + { + case APP_ERROR_SUCCESS: + return "Success"; + break; + case APP_ERROR_MISSINGARGUMENTS: + return "Missing arguments"; + break; + case APP_ERROR_INPUTFILENOTFOUND: + return "Unable to open input file"; + break; + case APP_ERROR_UNABLETOCREATEOUTPUTFILES: + return "Unable to create output files"; + break; + case APP_ERROR_TOOMANYARGUMENTS: + return "Too many arguments"; + break; + case APP_ERROR_INPUTDIRNOTFOUND: + return "Input directory not found"; + break; + case AAP_ERROR_NOTSUPPORTED: + return "Operation not supported"; + break; + case APP_ERROR_OPERATIONHASFAILED: + return "Operation has failed"; + break; + case APP_ERROR_INVALIDVALUE: + return "Invalid value"; + break; + default: + return "Unknown error"; + }; + } + + const char* getUpdateModeText(const FILE_UPDATE_MODE& mode) + { + switch ( mode ) + { + case WRITING: + return "Writing"; + case UPDATING: + return "Updating"; + case OVERWRITING: + return "Overwriting"; + case SKIPPING: + return "Skipping"; + default: + return "Unknown"; + }; + } + uint64_t getOutputFileModifiedDate(const std::string & path) { uint64_t mod_time = 0; diff --git a/src/bin2cpp/common.h b/src/bin2cpp/common.h index af7eec6..096ddae 100644 --- a/src/bin2cpp/common.h +++ b/src/bin2cpp/common.h @@ -42,6 +42,20 @@ namespace bin2cpp /// const char * getVersionString(); + /// + ///Get the desription of the given application error code. + /// + ///The error code. + ///Returns a string description of the given error code. Returns 'Unknown error' for unknown codes. + const char* getErrorCodeDescription(const APP_ERROR_CODES& error_code); + + /// + ///Get the desription of the given file update mode. + /// + ///The file update mode. + ///Returns a string description of the given file update mode. Returns 'Unknown' for unknown modes. + const char* getUpdateModeText(const FILE_UPDATE_MODE& mode); + /// ///Returns the modified date from an embedded file's c++ header/source file. ///Note that the function returns the number of seconds elapsed since epoch since Jan 1st 1970. diff --git a/src/bin2cpp/enums.h b/src/bin2cpp/enums.h index 82a7539..eb9bdca 100644 --- a/src/bin2cpp/enums.h +++ b/src/bin2cpp/enums.h @@ -28,6 +28,33 @@ namespace bin2cpp { + /// + ///Error codes returned by the application + /// + enum APP_ERROR_CODES + { + APP_ERROR_SUCCESS = 0, + APP_ERROR_MISSINGARGUMENTS, + APP_ERROR_INPUTFILENOTFOUND, + APP_ERROR_UNABLETOCREATEOUTPUTFILES, + APP_ERROR_TOOMANYARGUMENTS, + APP_ERROR_INPUTDIRNOTFOUND, + AAP_ERROR_NOTSUPPORTED, + APP_ERROR_OPERATIONHASFAILED, + APP_ERROR_INVALIDVALUE, + }; + + /// + ///File update modes. + /// + enum FILE_UPDATE_MODE + { + WRITING, + UPDATING, + OVERWRITING, + SKIPPING, + }; + /// ///Defines the different types of cpp encoding. /// diff --git a/src/bin2cpp/main.cpp b/src/bin2cpp/main.cpp index c70cdab..0ef661e 100755 --- a/src/bin2cpp/main.cpp +++ b/src/bin2cpp/main.cpp @@ -45,32 +45,12 @@ #include "rapidassist/process.h" #include "rapidassist/timing.h" +#include "enums.h" #include "common.h" #include "wildcard.h" using namespace bin2cpp; -enum APP_ERROR_CODES -{ - APP_ERROR_SUCCESS = 0, - APP_ERROR_MISSINGARGUMENTS, - APP_ERROR_INPUTFILENOTFOUND, - APP_ERROR_UNABLETOCREATEOUTPUTFILES, - APP_ERROR_TOOMANYARGUMENTS, - APP_ERROR_INPUTDIRNOTFOUND, - AAP_ERROR_NOTSUPPORTED, - APP_ERROR_OPERATIONHASFAILED, - APP_ERROR_INVALIDVALUE, -}; - -enum FILE_UPDATE_MODE -{ - WRITING, - UPDATING, - OVERWRITING, - SKIPPING, -}; - //default values static const size_t DEFAULT_CHUNK_SIZE = 200; static const char * DEFAULT_NAMESPACE_CPP = "bin2cpp"; @@ -84,59 +64,6 @@ static Dictionary output_files_dictionary; // unique values for output file nam #define DIRECTORY_FILTER_SEPARATOR_STR ":" static const char DIRECTORY_FILTER_SEPARATOR = DIRECTORY_FILTER_SEPARATOR_STR[0]; -const char * getErrorCodeDescription(const APP_ERROR_CODES & error_code) -{ - switch(error_code) - { - case APP_ERROR_SUCCESS: - return "Success"; - break; - case APP_ERROR_MISSINGARGUMENTS: - return "Missing arguments"; - break; - case APP_ERROR_INPUTFILENOTFOUND: - return "Unable to open input file"; - break; - case APP_ERROR_UNABLETOCREATEOUTPUTFILES: - return "Unable to create output files"; - break; - case APP_ERROR_TOOMANYARGUMENTS: - return "Too many arguments"; - break; - case APP_ERROR_INPUTDIRNOTFOUND: - return "Input directory not found"; - break; - case AAP_ERROR_NOTSUPPORTED: - return "Operation not supported"; - break; - case APP_ERROR_OPERATIONHASFAILED: - return "Operation has failed"; - break; - case APP_ERROR_INVALIDVALUE: - return "Invalid value"; - break; - default: - return "Unknown error"; - }; -} - -const char * getUpdateModeText(const FILE_UPDATE_MODE & mode) -{ - switch(mode) - { - case WRITING: - return "Writing"; - case UPDATING: - return "Updating"; - case OVERWRITING: - return "Overwriting"; - case SKIPPING: - return "Skipping"; - default: - return "Unknown"; - }; -} - struct ARGUMENTS { bool help; diff --git a/test/bin2cpp_unittest/TestCLI.cpp b/test/bin2cpp_unittest/TestCLI.cpp index 1ce7046..c23556c 100755 --- a/test/bin2cpp_unittest/TestCLI.cpp +++ b/test/bin2cpp_unittest/TestCLI.cpp @@ -30,6 +30,10 @@ #include "rapidassist/strings.h" #include "rapidassist/timing.h" +#include "enums.h" + +using namespace bin2cpp; + extern const std::string & gGeneratedFilesDir; #ifdef _WIN32 const std::string & gGeneratedFilesDir = "generated_files\\"; @@ -46,19 +50,6 @@ extern const std::string & gGeneratedFilesDir; }\ } -enum APP_ERROR_CODES -{ - APP_ERROR_SUCCESS = 0, - APP_ERROR_MISSINGARGUMENTS, - APP_ERROR_INPUTFILENOTFOUND, - APP_ERROR_UNABLETOCREATEOUTPUTFILES, - APP_ERROR_TOOMANYARGUMENTS, - APP_ERROR_INPUTDIRNOTFOUND, - AAP_ERROR_NOTSUPPORTED, - APP_ERROR_OPERATIONHASFAILED, - APP_ERROR_INVALIDVALUE, -}; - namespace TestCLIUtils { std::string getExpectedFilePath() From fb8d1d86f54302ee216c617dba8437b183d24b73 Mon Sep 17 00:00:00 2001 From: Antoine Beauchamp Date: Sun, 1 Jun 2025 16:55:18 -0400 Subject: [PATCH 2/2] * Fixed issue #78: Move duplicated enums from main.cpp to enums.h. --- CHANGES | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES b/CHANGES index be92adb..9a8a93b 100644 --- a/CHANGES +++ b/CHANGES @@ -8,6 +8,7 @@ Changes for 3.1.0: * Fixed issue #72: Move the code FileManager class generation code into its own IGenerator implementation. * Fixed issue #74: Invalid generated output file name: index.cpptml.cpp. * Fixed issue #77: Refactor generating code to use full file templates with markers. +* Fixed issue #78: Move duplicated enums from main.cpp to enums.h. Changes for 3.0.1: