Skip to content

Commit 14f0be7

Browse files
authored
Merge pull request #81 from end2endzone/feature-issue78
Move duplicated enums from main.cpp to enums.h
2 parents 00721b9 + fb8d1d8 commit 14f0be7

File tree

6 files changed

+100
-87
lines changed

6 files changed

+100
-87
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Changes for 3.1.0:
88
* Fixed issue #72: Move the code FileManager class generation code into its own IGenerator implementation.
99
* Fixed issue #74: Invalid generated output file name: index.cpptml.cpp.
1010
* Fixed issue #77: Refactor generating code to use full file templates with markers.
11+
* Fixed issue #78: Move duplicated enums from main.cpp to enums.h.
1112

1213

1314
Changes for 3.0.1:

src/bin2cpp/common.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,59 @@ namespace bin2cpp
4141
return BIN2CPP_VERSION;
4242
}
4343

44+
const char* getErrorCodeDescription(const APP_ERROR_CODES& error_code)
45+
{
46+
switch ( error_code )
47+
{
48+
case APP_ERROR_SUCCESS:
49+
return "Success";
50+
break;
51+
case APP_ERROR_MISSINGARGUMENTS:
52+
return "Missing arguments";
53+
break;
54+
case APP_ERROR_INPUTFILENOTFOUND:
55+
return "Unable to open input file";
56+
break;
57+
case APP_ERROR_UNABLETOCREATEOUTPUTFILES:
58+
return "Unable to create output files";
59+
break;
60+
case APP_ERROR_TOOMANYARGUMENTS:
61+
return "Too many arguments";
62+
break;
63+
case APP_ERROR_INPUTDIRNOTFOUND:
64+
return "Input directory not found";
65+
break;
66+
case AAP_ERROR_NOTSUPPORTED:
67+
return "Operation not supported";
68+
break;
69+
case APP_ERROR_OPERATIONHASFAILED:
70+
return "Operation has failed";
71+
break;
72+
case APP_ERROR_INVALIDVALUE:
73+
return "Invalid value";
74+
break;
75+
default:
76+
return "Unknown error";
77+
};
78+
}
79+
80+
const char* getUpdateModeText(const FILE_UPDATE_MODE& mode)
81+
{
82+
switch ( mode )
83+
{
84+
case WRITING:
85+
return "Writing";
86+
case UPDATING:
87+
return "Updating";
88+
case OVERWRITING:
89+
return "Overwriting";
90+
case SKIPPING:
91+
return "Skipping";
92+
default:
93+
return "Unknown";
94+
};
95+
}
96+
4497
uint64_t getOutputFileModifiedDate(const std::string & path)
4598
{
4699
uint64_t mod_time = 0;

src/bin2cpp/common.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@ namespace bin2cpp
4242
///</summary>
4343
const char * getVersionString();
4444

45+
///<summary>
46+
///Get the desription of the given application error code.
47+
///</summary>
48+
///<param name="error_code">The error code.</param>
49+
///<return>Returns a string description of the given error code. Returns 'Unknown error' for unknown codes.<return>
50+
const char* getErrorCodeDescription(const APP_ERROR_CODES& error_code);
51+
52+
///<summary>
53+
///Get the desription of the given file update mode.
54+
///</summary>
55+
///<param name="mode">The file update mode.</param>
56+
///<return>Returns a string description of the given file update mode. Returns 'Unknown' for unknown modes.<return>
57+
const char* getUpdateModeText(const FILE_UPDATE_MODE& mode);
58+
4559
///<summary>
4660
///Returns the modified date from an embedded file's c++ header/source file.
4761
///Note that the function returns the number of seconds elapsed since epoch since Jan 1st 1970.

src/bin2cpp/enums.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,33 @@
2828
namespace bin2cpp
2929
{
3030

31+
///<summary>
32+
///Error codes returned by the application
33+
///</summary>
34+
enum APP_ERROR_CODES
35+
{
36+
APP_ERROR_SUCCESS = 0,
37+
APP_ERROR_MISSINGARGUMENTS,
38+
APP_ERROR_INPUTFILENOTFOUND,
39+
APP_ERROR_UNABLETOCREATEOUTPUTFILES,
40+
APP_ERROR_TOOMANYARGUMENTS,
41+
APP_ERROR_INPUTDIRNOTFOUND,
42+
AAP_ERROR_NOTSUPPORTED,
43+
APP_ERROR_OPERATIONHASFAILED,
44+
APP_ERROR_INVALIDVALUE,
45+
};
46+
47+
///<summary>
48+
///File update modes.
49+
///</summary>
50+
enum FILE_UPDATE_MODE
51+
{
52+
WRITING,
53+
UPDATING,
54+
OVERWRITING,
55+
SKIPPING,
56+
};
57+
3158
///<summary>
3259
///Defines the different types of cpp encoding.
3360
///</summary>

src/bin2cpp/main.cpp

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -45,32 +45,12 @@
4545
#include "rapidassist/process.h"
4646
#include "rapidassist/timing.h"
4747

48+
#include "enums.h"
4849
#include "common.h"
4950
#include "wildcard.h"
5051

5152
using namespace bin2cpp;
5253

53-
enum APP_ERROR_CODES
54-
{
55-
APP_ERROR_SUCCESS = 0,
56-
APP_ERROR_MISSINGARGUMENTS,
57-
APP_ERROR_INPUTFILENOTFOUND,
58-
APP_ERROR_UNABLETOCREATEOUTPUTFILES,
59-
APP_ERROR_TOOMANYARGUMENTS,
60-
APP_ERROR_INPUTDIRNOTFOUND,
61-
AAP_ERROR_NOTSUPPORTED,
62-
APP_ERROR_OPERATIONHASFAILED,
63-
APP_ERROR_INVALIDVALUE,
64-
};
65-
66-
enum FILE_UPDATE_MODE
67-
{
68-
WRITING,
69-
UPDATING,
70-
OVERWRITING,
71-
SKIPPING,
72-
};
73-
7454
//default values
7555
static const size_t DEFAULT_CHUNK_SIZE = 200;
7656
static const char * DEFAULT_NAMESPACE_CPP = "bin2cpp";
@@ -84,59 +64,6 @@ static Dictionary output_files_dictionary; // unique values for output file nam
8464
#define DIRECTORY_FILTER_SEPARATOR_STR ":"
8565
static const char DIRECTORY_FILTER_SEPARATOR = DIRECTORY_FILTER_SEPARATOR_STR[0];
8666

87-
const char * getErrorCodeDescription(const APP_ERROR_CODES & error_code)
88-
{
89-
switch(error_code)
90-
{
91-
case APP_ERROR_SUCCESS:
92-
return "Success";
93-
break;
94-
case APP_ERROR_MISSINGARGUMENTS:
95-
return "Missing arguments";
96-
break;
97-
case APP_ERROR_INPUTFILENOTFOUND:
98-
return "Unable to open input file";
99-
break;
100-
case APP_ERROR_UNABLETOCREATEOUTPUTFILES:
101-
return "Unable to create output files";
102-
break;
103-
case APP_ERROR_TOOMANYARGUMENTS:
104-
return "Too many arguments";
105-
break;
106-
case APP_ERROR_INPUTDIRNOTFOUND:
107-
return "Input directory not found";
108-
break;
109-
case AAP_ERROR_NOTSUPPORTED:
110-
return "Operation not supported";
111-
break;
112-
case APP_ERROR_OPERATIONHASFAILED:
113-
return "Operation has failed";
114-
break;
115-
case APP_ERROR_INVALIDVALUE:
116-
return "Invalid value";
117-
break;
118-
default:
119-
return "Unknown error";
120-
};
121-
}
122-
123-
const char * getUpdateModeText(const FILE_UPDATE_MODE & mode)
124-
{
125-
switch(mode)
126-
{
127-
case WRITING:
128-
return "Writing";
129-
case UPDATING:
130-
return "Updating";
131-
case OVERWRITING:
132-
return "Overwriting";
133-
case SKIPPING:
134-
return "Skipping";
135-
default:
136-
return "Unknown";
137-
};
138-
}
139-
14067
struct ARGUMENTS
14168
{
14269
bool help;

test/bin2cpp_unittest/TestCLI.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
#include "rapidassist/strings.h"
3131
#include "rapidassist/timing.h"
3232

33+
#include "enums.h"
34+
35+
using namespace bin2cpp;
36+
3337
extern const std::string & gGeneratedFilesDir;
3438
#ifdef _WIN32
3539
const std::string & gGeneratedFilesDir = "generated_files\\";
@@ -46,19 +50,6 @@ extern const std::string & gGeneratedFilesDir;
4650
}\
4751
}
4852

49-
enum APP_ERROR_CODES
50-
{
51-
APP_ERROR_SUCCESS = 0,
52-
APP_ERROR_MISSINGARGUMENTS,
53-
APP_ERROR_INPUTFILENOTFOUND,
54-
APP_ERROR_UNABLETOCREATEOUTPUTFILES,
55-
APP_ERROR_TOOMANYARGUMENTS,
56-
APP_ERROR_INPUTDIRNOTFOUND,
57-
AAP_ERROR_NOTSUPPORTED,
58-
APP_ERROR_OPERATIONHASFAILED,
59-
APP_ERROR_INVALIDVALUE,
60-
};
61-
6253
namespace TestCLIUtils
6354
{
6455
std::string getExpectedFilePath()

0 commit comments

Comments
 (0)