Skip to content

Commit fc9feda

Browse files
committed
Created CodeGenerationEnum enum and supporting function parseCode() and getDefaultCodeSourceFileExtension().
1 parent 8d89e58 commit fc9feda

File tree

3 files changed

+54
-5
lines changed

3 files changed

+54
-5
lines changed

src/bin2cpp/common.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,4 +364,32 @@ namespace bin2cpp
364364
return output;
365365
}
366366

367+
CodeGenerationEnum parseCode(const std::string& value)
368+
{
369+
std::string value_upper = ra::strings::Uppercase(value);
370+
if ( value_upper == "C" )
371+
return CodeGenerationEnum::CODE_GENERATION_C;
372+
if ( value_upper == "CPP" || value_upper == "C++" )
373+
return CodeGenerationEnum::CODE_GENERATION_CPP;
374+
return CodeGenerationEnum::CODE_GENERATION_UNKNOW;
375+
}
376+
377+
const std::string& getDefaultCodeSourceFileExtension(CodeGenerationEnum code)
378+
{
379+
static const std::string EMPTY = "";
380+
static const std::string CPP = "cpp";
381+
static const std::string C = "c";
382+
switch ( code )
383+
{
384+
case CODE_GENERATION_UNKNOW:
385+
return EMPTY;
386+
case CODE_GENERATION_CPP:
387+
return CPP;
388+
case CODE_GENERATION_C:
389+
return C;
390+
default:
391+
return EMPTY;
392+
};
393+
}
394+
367395
}; //bin2cpp

src/bin2cpp/common.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <vector>
3333

3434
#include "types.h"
35+
#include "enums.h"
3536

3637
namespace bin2cpp
3738
{
@@ -142,6 +143,20 @@ namespace bin2cpp
142143
///<return>Returns the combined string.<return>
143144
std::string strJoin(const std::vector<std::string>& values, char separator);
144145

146+
///<summary>
147+
///Parse a CodeGenerationEnum from a string.
148+
///</summary>
149+
///<param name="value">The string value representing of the code language.</param>
150+
///<return>Returns a valid CodeGenerationEnum value. Returns CODE_GENERATION_UNKNOW on parsing error.<return>
151+
CodeGenerationEnum parseCode(const std::string& value);
152+
153+
///<summary>
154+
///Get the default source file extension for the given CodeGenerationEnum.
155+
///</summary>
156+
///<param name="code">The code generation language.</param>
157+
///<return>Returns a valid file extension valu that matches the given code. Returns an empty string otherwise.<return>
158+
const std::string & getDefaultCodeSourceFileExtension(CodeGenerationEnum code);
159+
145160
}; //bin2cpp
146161

147162
#endif //BIN2CPP_COMMON_H

src/bin2cpp/enums.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,28 @@
2424

2525
#ifndef ENUMS_H
2626
#define ENUMS_H
27-
28-
#include <string>
29-
#include "Context.h"
3027

3128
namespace bin2cpp
3229
{
3330

3431
///<summary>
35-
///Defines the different type of cpp encoding.
36-
///See setCppEncoder() and getCppEncoder() functions.
32+
///Defines the different types of cpp encoding.
3733
///</summary>
3834
enum CppEncoderEnum
3935
{
4036
CPP_ENCODER_OCT,
4137
CPP_ENCODER_HEX,
4238
};
39+
40+
///<summary>
41+
///Defines the different types of programming language code output.
42+
///</summary>
43+
enum CodeGenerationEnum
44+
{
45+
CODE_GENERATION_UNKNOW,
46+
CODE_GENERATION_CPP,
47+
CODE_GENERATION_C,
48+
};
4349

4450
}; //bin2cpp
4551

0 commit comments

Comments
 (0)