Skip to content

Commit 0a85571

Browse files
committed
Completed implementation of issue #28
Renamed `usefilemanager` argument to `registerfile`. Renamed IGenerator::setManagerEnabled() to setRegisterFileEnabled() Renamed IGenerator::isManagerEnabled() to isRegisterFileEnabled() Created unit tests for --managerfile and --registerfile command line argument.
1 parent e1ad441 commit 0a85571

File tree

9 files changed

+262
-47
lines changed

9 files changed

+262
-47
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ bin2cpp --version
9696
| --identifier=\<name> | Identifier of the function name that is used to get an instance of the file. ie: SplashScreen |
9797
| --chunksize=\<value> | Size in bytes of each string segments (bytes per row). [default: 200]. |
9898
| --baseclass=\<value> | The name of the interface for embedded files. [default: File]. |
99-
| --managerfile=\<name> | File name of the generated C++ Header file for the FileManager class. ie: FileManager.h. |
10099
| --namespace=\<value> | The namespace of the generated source code [default: bin2cpp]. |
101-
| --usefilemanager | Register the generated file to the FileManager class. [default: false]. |
100+
| --managerfile=\<name> | File name of the generated C++ Header file for the FileManager class. ie: FileManager.h. |
101+
| --registerfile | Register the generated file to the FileManager class. [default: false]. |
102102
| --override | Tells bin2cpp to overwrite the destination files. |
103103
| --noheader | Do not print program header to standard output. |
104104
| --quiet | Do not log any message to standard output. |

src/bin2cpp/BaseGenerator.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ namespace bin2cpp
120120
return mManagerFile.c_str();
121121
}
122122

123-
void BaseGenerator::setManagerEnabled(bool iManagerEnabled)
123+
void BaseGenerator::setRegisterFileEnabled(bool iRegisterFileEnabled)
124124
{
125-
mManagerEnabled = iManagerEnabled;
125+
mManagerEnabled = iRegisterFileEnabled;
126126
}
127127

128-
bool BaseGenerator::isManagerEnabled() const
128+
bool BaseGenerator::isRegisterFileEnabled() const
129129
{
130130
return mManagerEnabled;
131131
}
@@ -197,7 +197,7 @@ namespace bin2cpp
197197

198198
std::string BaseGenerator::getFileManagerRegistrationTemplate()
199199
{
200-
if (!this->isManagerEnabled())
200+
if (!this->isRegisterFileEnabled())
201201
return std::string();
202202

203203
//Build class name

src/bin2cpp/BaseGenerator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ namespace bin2cpp
5454
virtual CppEncoderEnum getCppEncoder() const;
5555
virtual void setManagerHeaderFile(const char * iManagerFile);
5656
virtual const char * getManagerHeaderFile() const;
57-
virtual void setManagerEnabled(bool iManagerEnabled);
58-
virtual bool isManagerEnabled() const;
57+
virtual void setRegisterFileEnabled(bool iRegisterFileEnabled);
58+
virtual bool isRegisterFileEnabled() const;
5959

6060
//same header file for all generators
6161
virtual bool createCppHeaderFile(const char * iHeaderFilePath);

src/bin2cpp/IGenerator.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,16 @@ namespace bin2cpp
113113
virtual const char * getManagerHeaderFile() const = 0;
114114

115115
///<summary>
116-
///Enable or disable the usage of the FileManager in generated code.
116+
///Enable or disable the registration of the generated file to the FileManager.
117117
///</summary>
118118
///<param name="iFileManagerEnabled">The new value of the flag.</param>
119-
virtual void setManagerEnabled(bool iManagerEnabled) = 0;
119+
virtual void setRegisterFileEnabled(bool iRegisterFileEnabled) = 0;
120120

121121
///<summary>
122-
///Returns true if the FileManager should be used in generated code.
122+
///Returns true if the generated file should be registated FileManager should be used in generated code.
123123
///</summary>
124124
///<returns>Returns true if the FileManager should be used in generated code. Returns false otherwise.</returns>
125-
virtual bool isManagerEnabled() const = 0;
125+
virtual bool isRegisterFileEnabled() const = 0;
126126

127127
///<summary>
128128
///Defines the different type of cpp encoding.

src/bin2cpp/SegmentGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ namespace bin2cpp
144144
fprintf(cpp, " std::string mBuffer;\n");
145145
fprintf(cpp, " };\n");
146146
fprintf(cpp, " const %s & %s() { static %s _instance; return _instance; }\n", mBaseClass.c_str(), getterFunctionName.c_str(), className.c_str());
147-
if (isManagerEnabled())
147+
if (isRegisterFileEnabled())
148148
{
149149
std::string fileManagerTemplate = getFileManagerRegistrationTemplate();
150150
fprintf(cpp, "%s", fileManagerTemplate.c_str());

src/bin2cpp/main.cpp

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ using namespace bin2cpp;
4646

4747
enum APP_ERROR_CODES
4848
{
49-
APP_ERROR_SUCCESS,
49+
APP_ERROR_SUCCESS = 0,
5050
APP_ERROR_MISSINGARGUMENTS,
5151
APP_ERROR_INPUTFILENOTFOUND,
5252
APP_ERROR_UNABLETOCREATEOUTPUTFILES,
@@ -152,6 +152,7 @@ struct ARGUMENTS
152152
bool version;
153153
bool hasFile;
154154
bool hasDir;
155+
bool hasManagerFile;
155156
std::string inputFile;
156157
std::string inputDir;
157158
std::string outputFolder;
@@ -162,7 +163,7 @@ struct ARGUMENTS
162163
std::string codeNamespace;
163164
std::string baseClass;
164165
std::string managerHeaderFilename;
165-
bool usefilemanager;
166+
bool registerfile;
166167
IGenerator::CppEncoderEnum encoding;
167168
std::string generatorName;
168169
};
@@ -185,7 +186,7 @@ void printUsage()
185186
//usage string in docopt format. See http://docopt.org/
186187
static const char usage[] =
187188
"Usage:\n"
188-
" bin2cpp --file=<path> --output=<path> --headerfile=<name> --identifier=<name> [--generator=<name>] [--encoding=<name>] [--chunksize=<value>] [--namespace=<value>] [--baseclass=<value>] [--managerfile=<name>] [--override] [--noheader] [--quiet]\n"
189+
" bin2cpp --file=<path> --output=<path> --headerfile=<name> --identifier=<name> [--generator=<name>] [--encoding=<name>] [--chunksize=<value>] [--namespace=<value>] [--baseclass=<value>] [--managerfile=<name>] [--registerfile] [--override] [--noheader] [--quiet]\n"
189190
" bin2cpp --help\n"
190191
" bin2cpp --version\n"
191192
"\n"
@@ -205,9 +206,9 @@ void printUsage()
205206
" --identifier=<name> Identifier of the function name that is used to get an instance of the file. ie: SplashScreen\n"
206207
" --chunksize=<value> Size in bytes of each string segments (bytes per row). [default: 200].\n"
207208
" --baseclass=<value> The name of the interface for embedded files. [default: File].\n"
208-
" --managerfile=<name> File name of the generated C++ Header file for the FileManager class. ie: FileManager.h\n"
209209
" --namespace=<value> The namespace of the generated source code [default: bin2cpp].\n"
210-
" --usefilemanager Register the generated file to the FileManager class. [default: false].\n"
210+
" --managerfile=<name> File name of the generated C++ Header file for the FileManager class. ie: FileManager.h\n"
211+
" --registerfile Register the generated file to the FileManager class. [default: false].\n"
211212
" --override Tells bin2cpp to overwrite the destination files.\n"
212213
" --noheader Do not print program header to standard output.\n"
213214
" --quiet Do not log any message to standard output.\n"
@@ -224,9 +225,10 @@ int main(int argc, char* argv[])
224225
args.version = false;
225226
args.hasFile = false;
226227
args.hasDir = false;
228+
args.hasManagerFile = false;
227229
args.chunkSize = 0;
228230
args.overrideExisting;
229-
args.usefilemanager = false;
231+
args.registerfile = false;
230232

231233
std::string dummy;
232234

@@ -266,11 +268,12 @@ int main(int argc, char* argv[])
266268
//mandatory arguments
267269
args.hasFile = ra::cli::ParseArgument("file", args.inputFile, argc, argv);
268270
args.hasDir = ra::cli::ParseArgument("dir", args.inputDir, argc, argv);
269-
if (!args.hasFile && !args.hasDir)
271+
args.hasManagerFile = ra::cli::ParseArgument("managerfile", args.managerHeaderFilename, argc, argv);
272+
if (!args.hasFile && !args.hasDir && !args.hasManagerFile)
270273
{
271-
//file or dir must be specified
274+
//file, dir or managerfile must be specified
272275
APP_ERROR_CODES error = APP_ERROR_MISSINGARGUMENTS;
273-
ra::logging::Log(ra::logging::LOG_ERROR, "%s (file, dir)", getErrorCodeDescription(error));
276+
ra::logging::Log(ra::logging::LOG_ERROR, "%s (file, dir, managerfile)", getErrorCodeDescription(error));
274277
printUsage();
275278
return error;
276279
}
@@ -356,14 +359,12 @@ int main(int argc, char* argv[])
356359
args.baseClass = DEFAULT_BASECLASSNAME;
357360
}
358361

359-
ra::cli::ParseArgument("managerfile", args.managerHeaderFilename, argc, argv);
360-
361-
args.usefilemanager = ra::cli::ParseArgument("usefilemanager", dummy, argc, argv);
362+
args.registerfile = ra::cli::ParseArgument("registerfile", dummy, argc, argv);
362363

363-
//force usefilemanager if managerfile is specified
364-
if (!args.managerHeaderFilename.empty())
364+
//force registerfile if managerfile is specified
365+
if (args.hasManagerFile)
365366
{
366-
args.usefilemanager = true;
367+
args.registerfile = true;
367368
}
368369

369370
std::string encodingStr;
@@ -435,19 +436,8 @@ int main(int argc, char* argv[])
435436
if (error != APP_ERROR_SUCCESS)
436437
{
437438
ra::logging::Log(ra::logging::LOG_ERROR, "%s", getErrorCodeDescription(error));
439+
return error;
438440
}
439-
440-
//should we also generate the FileManager class?
441-
if (!args.managerHeaderFilename.empty())
442-
{
443-
error = processManagerFiles(args, generator);
444-
if (error != APP_ERROR_SUCCESS)
445-
{
446-
ra::logging::Log(ra::logging::LOG_ERROR, "%s", getErrorCodeDescription(error));
447-
}
448-
}
449-
450-
return error;
451441
}
452442
else if (args.hasDir)
453443
{
@@ -517,10 +507,20 @@ int main(int argc, char* argv[])
517507
}
518508

519509
//all files processed
520-
return APP_ERROR_SUCCESS;
521510
}
522511

523-
return APP_ERROR_UNABLETOCREATEOUTPUTFILES;
512+
//should we also generate the FileManager class?
513+
if (args.hasManagerFile)
514+
{
515+
APP_ERROR_CODES error = processManagerFiles(args, generator);
516+
if (error != APP_ERROR_SUCCESS)
517+
{
518+
ra::logging::Log(ra::logging::LOG_ERROR, "%s", getErrorCodeDescription(error));
519+
return error;
520+
}
521+
}
522+
523+
return APP_ERROR_SUCCESS;
524524
}
525525

526526
APP_ERROR_CODES processSingleFile(const ARGUMENTS & args, bin2cpp::IGenerator * generator)
@@ -558,7 +558,7 @@ APP_ERROR_CODES processSingleFile(const ARGUMENTS & args, bin2cpp::IGenerator *
558558
generator->setBaseClass(args.baseClass.c_str());
559559
generator->setCppEncoder(args.encoding);
560560
generator->setManagerHeaderFile(args.managerHeaderFilename.c_str());
561-
generator->setManagerEnabled(args.usefilemanager);
561+
generator->setRegisterFileEnabled(args.registerfile);
562562

563563
//process files
564564
bool headerResult = generateFile(args.inputFile, outputHeaderPath, generator, args.overrideExisting);
@@ -651,7 +651,6 @@ bool generateManagerFile(const std::string & iOutputFilePath, bin2cpp::IGenerato
651651
if (!result)
652652
{
653653
//there was an error generating file
654-
ra::logging::Log(ra::logging::LOG_ERROR, "%s", getErrorCodeDescription(APP_ERROR_UNABLETOCREATEOUTPUTFILES));
655654
ra::logging::Log(ra::logging::LOG_ERROR, "%s failed!", getUpdateModeText(mode));
656655
}
657656
return result;

0 commit comments

Comments
 (0)