Skip to content

Commit a38f439

Browse files
committed
* Moved functions in argumentparser.h to 'cmdline' namespace
* Moved loggers functions to 'logger' namespace.
1 parent c7582d0 commit a38f439

File tree

6 files changed

+50
-50
lines changed

6 files changed

+50
-50
lines changed

src/argumentparser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "argumentparser.h"
44

5-
namespace bin2cpp
5+
namespace cmdline
66
{
77
bool parseArgument(const std::string & name, std::string & value, int argc, char **argv)
88
{
@@ -75,4 +75,4 @@ namespace bin2cpp
7575
return false;
7676
}
7777

78-
}; //bin2cpp
78+
}; //cmdline

src/argumentparser.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include <string>
44

5-
namespace bin2cpp
5+
namespace cmdline
66
{
77
///<summary>
88
///Parses an argument from the command line parameters (argc, argv)
@@ -37,4 +37,4 @@ namespace bin2cpp
3737
///<return>True when an argument named [name] is found. False otherwise.<return>
3838
bool parseArgument(const std::string & name, size_t & value, int argc, char **argv);
3939

40-
}; //bin2cpp
40+
}; //cmdline

src/logger.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <stdarg.h>
77
#include <shlobj.h>
88

9-
namespace bin2cpp
9+
namespace logger
1010
{
1111
bool gQuietMode = false;
1212

@@ -52,4 +52,4 @@ namespace bin2cpp
5252
}
5353
}
5454

55-
}; //bin2cpp
55+
}; //logger

src/logger.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include <string>
44

5-
namespace bin2cpp
5+
namespace logger
66
{
77

88
///<summary>
@@ -34,4 +34,4 @@ namespace bin2cpp
3434
///<param name="iFormat">The format of the given argument. Same as printf's format.</param>
3535
void log(LOGGER_LEVEL iLevel, const char * iFormat, ...);
3636

37-
}; //bin2cpp
37+
}; //logger

src/main.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ int main(int argc, char* argv[])
117117
{
118118
//help
119119
std::string dummy;
120-
if (bin2cpp::parseArgument("help", dummy, argc, argv))
120+
if (cmdline::parseArgument("help", dummy, argc, argv))
121121
{
122122
printHeader();
123123
printUsage();
@@ -126,14 +126,14 @@ int main(int argc, char* argv[])
126126

127127
//noheader
128128
bool noheader = false;
129-
if (bin2cpp::parseArgument("noheader", dummy, argc, argv))
129+
if (cmdline::parseArgument("noheader", dummy, argc, argv))
130130
{
131131
noheader = true;
132132
}
133133

134134
//quiet
135135
bool quiet = false;
136-
if (bin2cpp::parseArgument("quiet", dummy, argc, argv))
136+
if (cmdline::parseArgument("quiet", dummy, argc, argv))
137137
{
138138
quiet = true;
139139
}
@@ -142,10 +142,10 @@ int main(int argc, char* argv[])
142142
if (quiet)
143143
noheader = true;
144144

145-
bin2cpp::setQuietMode(quiet);
145+
logger::setQuietMode(quiet);
146146

147147
//version
148-
if (bin2cpp::parseArgument("version", dummy, argc, argv))
148+
if (cmdline::parseArgument("version", dummy, argc, argv))
149149
{
150150
if (!noheader)
151151
printHeader();
@@ -161,34 +161,34 @@ int main(int argc, char* argv[])
161161
std::string headerFilename;
162162
std::string functionIdentifier;
163163

164-
if (!bin2cpp::parseArgument("file", inputFile, argc, argv))
164+
if (!cmdline::parseArgument("file", inputFile, argc, argv))
165165
{
166166
APP_ERROR_CODES error = APP_ERROR_MISSINGARGUMENTS;
167-
bin2cpp::log(bin2cpp::LOG_ERROR, "%s (file)", getErrorCodeDescription(error));
167+
logger::log(logger::LOG_ERROR, "%s (file)", getErrorCodeDescription(error));
168168
printUsage();
169169
return error;
170170
}
171171

172-
if (!bin2cpp::parseArgument("output", outputFolder, argc, argv))
172+
if (!cmdline::parseArgument("output", outputFolder, argc, argv))
173173
{
174174
APP_ERROR_CODES error = APP_ERROR_MISSINGARGUMENTS;
175-
bin2cpp::log(bin2cpp::LOG_ERROR, "%s (output)", getErrorCodeDescription(error));
175+
logger::log(logger::LOG_ERROR, "%s (output)", getErrorCodeDescription(error));
176176
printUsage();
177177
return error;
178178
}
179179

180-
if (!bin2cpp::parseArgument("headerfile", headerFilename, argc, argv))
180+
if (!cmdline::parseArgument("headerfile", headerFilename, argc, argv))
181181
{
182182
APP_ERROR_CODES error = APP_ERROR_MISSINGARGUMENTS;
183-
bin2cpp::log(bin2cpp::LOG_ERROR, "%s (headerfile)", getErrorCodeDescription(error));
183+
logger::log(logger::LOG_ERROR, "%s (headerfile)", getErrorCodeDescription(error));
184184
printUsage();
185185
return error;
186186
}
187187

188-
if (!bin2cpp::parseArgument("identifier", functionIdentifier, argc, argv))
188+
if (!cmdline::parseArgument("identifier", functionIdentifier, argc, argv))
189189
{
190190
APP_ERROR_CODES error = APP_ERROR_MISSINGARGUMENTS;
191-
bin2cpp::log(bin2cpp::LOG_ERROR, "%s (identifier)", getErrorCodeDescription(error));
191+
logger::log(logger::LOG_ERROR, "%s (identifier)", getErrorCodeDescription(error));
192192
printUsage();
193193
return error;
194194
}
@@ -206,27 +206,27 @@ int main(int argc, char* argv[])
206206
std::string encodingStr;
207207

208208
size_t tmpChunkSize = 0;
209-
if (bin2cpp::parseArgument("chunksize", tmpChunkSize, argc, argv))
209+
if (cmdline::parseArgument("chunksize", tmpChunkSize, argc, argv))
210210
{
211211
chunkSize = tmpChunkSize;
212212
}
213213

214-
if (bin2cpp::parseArgument("override", dummy, argc, argv))
214+
if (cmdline::parseArgument("override", dummy, argc, argv))
215215
{
216216
overrideExisting = true;
217217
}
218218

219-
if (!bin2cpp::parseArgument("namespace", codeNamespace, argc, argv))
219+
if (!cmdline::parseArgument("namespace", codeNamespace, argc, argv))
220220
{
221221
codeNamespace = DEFAULT_NAMESPACE;
222222
}
223223

224-
if (!bin2cpp::parseArgument("baseclass", baseClass, argc, argv))
224+
if (!cmdline::parseArgument("baseclass", baseClass, argc, argv))
225225
{
226226
baseClass = DEFAULT_BASECLASSNAME;
227227
}
228228

229-
if (bin2cpp::parseArgument("encoding", encodingStr, argc, argv))
229+
if (cmdline::parseArgument("encoding", encodingStr, argc, argv))
230230
{
231231
if (uppercase(encodingStr) == "OCT")
232232
encoding = IGenerator::CPP_ENCODER_OCT;
@@ -235,7 +235,7 @@ int main(int argc, char* argv[])
235235
else
236236
{
237237
APP_ERROR_CODES error = APP_ERROR_MISSINGARGUMENTS;
238-
bin2cpp::log(bin2cpp::LOG_ERROR, "%s (encoding)", getErrorCodeDescription(error));
238+
logger::log(logger::LOG_ERROR, "%s (encoding)", getErrorCodeDescription(error));
239239
printUsage();
240240
return error;
241241
}
@@ -252,7 +252,7 @@ int main(int argc, char* argv[])
252252
bin2cpp::IGenerator * generator = NULL;
253253

254254
std::string generatorName;
255-
if (bin2cpp::parseArgument("generator", generatorName, argc, argv))
255+
if (cmdline::parseArgument("generator", generatorName, argc, argv))
256256
{
257257
if (generatorName == "segment")
258258
{
@@ -271,7 +271,7 @@ int main(int argc, char* argv[])
271271
if (generator == NULL)
272272
{
273273
APP_ERROR_CODES error = APP_ERROR_MISSINGARGUMENTS;
274-
bin2cpp::log(bin2cpp::LOG_ERROR, "%s, unknown values for 'generator' argument!", getErrorCodeDescription(error));
274+
logger::log(logger::LOG_ERROR, "%s, unknown values for 'generator' argument!", getErrorCodeDescription(error));
275275
printUsage();
276276
return error;
277277
}
@@ -295,7 +295,7 @@ int main(int argc, char* argv[])
295295
if (overrideExisting)
296296
info << " overriding existing files";
297297
info << "...";
298-
bin2cpp::log(bin2cpp::LOG_INFO, info.c_str());
298+
logger::log(logger::LOG_INFO, info.c_str());
299299

300300
//prepare output files path
301301
std::string outputHeaderPath = outputFolder + "\\" + headerFilename;
@@ -340,7 +340,7 @@ FILE_UPDATE_MODE getFileUpdateMode(const std::string & inputFile, const std::str
340340
uint64_t lastModifiedDate = getFileModifiedDate(inputFile);
341341
uint64_t outputModifiedDate = getOutputFileModifiedDate(iOutputFilePath);
342342
if (outputModifiedDate == 0)
343-
bin2cpp::log(bin2cpp::LOG_WARNING, "Unable to get last modified date of file \'%s\'", iOutputFilePath.c_str());
343+
logger::log(logger::LOG_WARNING, "Unable to get last modified date of file \'%s\'", iOutputFilePath.c_str());
344344
if (lastModifiedDate == outputModifiedDate)
345345
return SKIPPING;
346346

@@ -353,7 +353,7 @@ bool processFile(const std::string & inputFile, const std::string & iOutputFileP
353353
FILE_UPDATE_MODE mode = getFileUpdateMode(inputFile, iOutputFilePath, overrideExisting);
354354

355355
//writing message
356-
bin2cpp::log(bin2cpp::LOG_INFO, "%s file \"%s\"...", getUpdateModeText(mode), iOutputFilePath.c_str());
356+
logger::log(logger::LOG_INFO, "%s file \"%s\"...", getUpdateModeText(mode), iOutputFilePath.c_str());
357357

358358
if (mode == SKIPPING)
359359
return true; //skipping is success
@@ -373,8 +373,8 @@ bool processFile(const std::string & inputFile, const std::string & iOutputFileP
373373
if (!result)
374374
{
375375
//there was an error generating file
376-
bin2cpp::log(bin2cpp::LOG_ERROR, "%s", getErrorCodeDescription(APP_ERROR_UNABLETOCREATEOUTPUTFILES));
377-
bin2cpp::log(bin2cpp::LOG_ERROR, "Embedding failed!");
376+
logger::log(logger::LOG_ERROR, "%s", getErrorCodeDescription(APP_ERROR_UNABLETOCREATEOUTPUTFILES));
377+
logger::log(logger::LOG_ERROR, "Embedding failed!");
378378
}
379379
return result;
380380
}

test/testfilegenerator.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,74 +84,74 @@ int main(int argc, char **argv)
8484

8585
//help
8686
std::string tmp;
87-
if (bin2cpp::parseArgument("help", tmp, argc, argv))
87+
if (cmdline::parseArgument("help", tmp, argc, argv))
8888
{
8989
printVersion();
9090
printUsage();
9191
return EXIT_NO_ERROR;
9292
}
9393

9494
//version
95-
if (bin2cpp::parseArgument("version", tmp, argc, argv))
95+
if (cmdline::parseArgument("version", tmp, argc, argv))
9696
{
9797
printVersion();
9898
return EXIT_NO_ERROR;
9999
}
100100

101101
//quiet
102102
std::string tmpQuiet;
103-
if (bin2cpp::parseArgument("quiet", tmpQuiet, argc, argv))
103+
if (cmdline::parseArgument("quiet", tmpQuiet, argc, argv))
104104
{
105-
bin2cpp::setQuietMode(true);
105+
logger::setQuietMode(true);
106106
}
107107

108108
//file
109-
if (!bin2cpp::parseArgument("file", file, argc, argv))
109+
if (!cmdline::parseArgument("file", file, argc, argv))
110110
{
111-
bin2cpp::log(bin2cpp::LOG_ERROR, "Missing 'file' argument!");
111+
logger::log(logger::LOG_ERROR, "Missing 'file' argument!");
112112
printUsage();
113113
return MISSING_FILE;
114114
}
115115

116116
//size
117117
int tmpSize = 0;
118-
if (bin2cpp::parseArgument("size", tmpSize, argc, argv))
118+
if (cmdline::parseArgument("size", tmpSize, argc, argv))
119119
{
120120
size = tmpSize;
121121
if (size <= 0)
122122
{
123-
bin2cpp::log(bin2cpp::LOG_ERROR, "Invalid file size!");
123+
logger::log(logger::LOG_ERROR, "Invalid file size!");
124124
return INVALID_FILE_SIZE;
125125
}
126126
}
127127

128128
//seed
129129
int tmpSeed = 0;
130-
if (bin2cpp::parseArgument("seed", tmpSeed, argc, argv))
130+
if (cmdline::parseArgument("seed", tmpSeed, argc, argv))
131131
{
132132
seed = tmpSeed;
133133
if (seed < 0)
134134
{
135-
bin2cpp::log(bin2cpp::LOG_ERROR, "Invalid seed value!");
135+
logger::log(logger::LOG_ERROR, "Invalid seed value!");
136136
return INVALID_SEED;
137137
}
138138
}
139139

140140
//skip
141141
int tmpSkip = 0;
142-
if (bin2cpp::parseArgument("skip", tmpSkip, argc, argv))
142+
if (cmdline::parseArgument("skip", tmpSkip, argc, argv))
143143
{
144144
skip = tmpSkip;
145145
if (skip < 0)
146146
{
147-
bin2cpp::log(bin2cpp::LOG_ERROR, "Invalid skip value!");
147+
logger::log(logger::LOG_ERROR, "Invalid skip value!");
148148
return INVALID_SKIP;
149149
}
150150
}
151151

152152
//fill
153153
std::string tmpFill;
154-
if (bin2cpp::parseArgument("fill", tmpFill, argc, argv))
154+
if (cmdline::parseArgument("fill", tmpFill, argc, argv))
155155
{
156156
if (tmpFill == "sequential" ||
157157
tmpFill == "random" ||
@@ -162,21 +162,21 @@ int main(int argc, char **argv)
162162
}
163163
else
164164
{
165-
bin2cpp::log(bin2cpp::LOG_ERROR, "Invalid fill parameter!");
165+
logger::log(logger::LOG_ERROR, "Invalid fill parameter!");
166166
return INVALID_FILL_PARAMETER;
167167
}
168168
}
169169

170170
//building info string
171171
std::string infostr;
172172
infostr << "Writing " << size << " bytes" << getSizeAdditionalInfo(size) << " of " << fill << " data into \'" << file << "\'.";
173-
bin2cpp::log(bin2cpp::LOG_INFO, "%s", infostr.c_str());
173+
logger::log(logger::LOG_INFO, "%s", infostr.c_str());
174174

175175
//process with file generation
176176
FILE * f = fopen(file.c_str(), "wb");
177177
if (!f)
178178
{
179-
bin2cpp::log(bin2cpp::LOG_ERROR, "Cannot create file '%s'!", file.c_str());
179+
logger::log(logger::LOG_ERROR, "Cannot create file '%s'!", file.c_str());
180180
return 4;
181181
}
182182

0 commit comments

Comments
 (0)