Skip to content

Commit 98bf8e8

Browse files
committed
Simplified return values of IGenerator interface. Removed usage of ErrorCodes and replaced by a boolean value.
1 parent 8cb3d80 commit 98bf8e8

12 files changed

+40
-62
lines changed

src/ArrayGenerator.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ namespace bin2cpp
2525
return "array";
2626
}
2727

28-
bin2cpp::ErrorCodes ArrayGenerator::createCppSourceFile(const char * iInputFilename, const char * iCppFilePath, const char * iFunctionIdentifier, size_t iChunkSize)
28+
bool ArrayGenerator::createCppSourceFile(const char * iInputFilename, const char * iCppFilePath, const char * iFunctionIdentifier, size_t iChunkSize)
2929
{
3030
//check if input file exists
3131
FILE * input = fopen(iInputFilename, "rb");
3232
if (!input)
33-
return bin2cpp::ErrorCodes::InputFileNotFound;
33+
return false;
3434

3535
//Uppercase function identifier
3636
std::string functionIdentifier = iFunctionIdentifier;
@@ -47,7 +47,7 @@ namespace bin2cpp
4747
if (!cpp)
4848
{
4949
fclose(input);
50-
return bin2cpp::ErrorCodes::UnableToCreateOutputFiles;
50+
return false;
5151
}
5252

5353
//determine file properties
@@ -137,7 +137,7 @@ namespace bin2cpp
137137
fclose(input);
138138
fclose(cpp);
139139

140-
return bin2cpp::ErrorCodes::Success;
140+
return true;
141141
}
142142

143143
}; //bin2cpp

src/ArrayGenerator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace bin2cpp
1515
ArrayGenerator();
1616
virtual ~ArrayGenerator();
1717
virtual const char * getName() const;
18-
virtual bin2cpp::ErrorCodes createCppSourceFile(const char * iInputFilename, const char * iCppFilePath, const char * iFunctionIdentifier, size_t iChunkSize);
18+
virtual bool createCppSourceFile(const char * iInputFilename, const char * iCppFilePath, const char * iFunctionIdentifier, size_t iChunkSize);
1919
};
2020

2121
}; //bin2cpp

src/BaseGenerator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ namespace bin2cpp
7777
return output;
7878
}
7979

80-
bin2cpp::ErrorCodes BaseGenerator::createCppHeaderFile(const char * iInputFilename, const char * iHeaderFilePath, const char * iFunctionIdentifier)
80+
bool BaseGenerator::createCppHeaderFile(const char * iInputFilename, const char * iHeaderFilePath, const char * iFunctionIdentifier)
8181
{
8282
FILE * header = fopen(iHeaderFilePath, "w");
8383
if (!header)
84-
return bin2cpp::ErrorCodes::UnableToCreateOutputFiles;
84+
return false;
8585

8686
std::string headercomments = getFileHeading(iInputFilename);
8787
fprintf(header, "%s", headercomments.c_str());
@@ -106,7 +106,7 @@ namespace bin2cpp
106106

107107
fclose(header);
108108

109-
return bin2cpp::ErrorCodes::Success;
109+
return true;
110110
}
111111

112112
}; //bin2cpp

src/BaseGenerator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace bin2cpp
1515
virtual ~BaseGenerator();
1616

1717
//same header file for all generators
18-
virtual bin2cpp::ErrorCodes createCppHeaderFile(const char * iInputFilename, const char * iHeaderFilePath, const char * iFunctionIdentifier);
18+
virtual bool createCppHeaderFile(const char * iInputFilename, const char * iHeaderFilePath, const char * iFunctionIdentifier);
1919

2020
protected:
2121
virtual std::string getGetterFunctionName(const char * iFunctionIdentifier);

src/IGenerator.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ namespace bin2cpp
2222
///<param name="iInputFilename">The path of the input file (resource) to embeded as a C++ source code.</param>
2323
///<param name="iHeaderFilePath">The path of the header file (*.h) that is used for getting access to the functions.</param>
2424
///<param name="iFunctionIdentifier">The unique identifier name for each data accessor functions.</param>
25-
///<returns>Returns an enum of type ErrorCodes which defines the results.</returns>
26-
virtual bin2cpp::ErrorCodes createCppHeaderFile(const char * iInputFilename, const char * iHeaderFilePath, const char * iFunctionIdentifier) = 0;
25+
///<returns>Returns true when the file was created. Returns false otherwise.</returns>
26+
virtual bool createCppHeaderFile(const char * iInputFilename, const char * iHeaderFilePath, const char * iFunctionIdentifier) = 0;
2727

2828
///<summary>
2929
///Creates a cpp source file for embedding a given file into C++ source code.
@@ -32,8 +32,8 @@ namespace bin2cpp
3232
///<param name="iCppFilePath">The path of the source file (*.cpp) that is used for getting access to the functions.</param>
3333
///<param name="iFunctionIdentifier">The unique identifier name for each data accessor functions.</param>
3434
///<param name="iChunkSize">The size in bytes of each chunk of data.</param>
35-
///<returns>Returns an enum of type ErrorCodes which defines the results.</returns>
36-
virtual bin2cpp::ErrorCodes createCppSourceFile(const char * iInputFilename, const char * iCppFilePath, const char * iFunctionIdentifier, size_t iChunkSize) = 0;
35+
///<returns>Returns true when the file was created. Returns false otherwise.</returns>
36+
virtual bool createCppSourceFile(const char * iInputFilename, const char * iCppFilePath, const char * iFunctionIdentifier, size_t iChunkSize) = 0;
3737
};
3838

3939
}; //bin2cpp

src/SegmentGenerator.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ namespace bin2cpp
2525
return "segment";
2626
}
2727

28-
bin2cpp::ErrorCodes SegmentGenerator::createCppSourceFile(const char * iInputFilename, const char * iCppFilePath, const char * iFunctionIdentifier, size_t iChunkSize)
28+
bool SegmentGenerator::createCppSourceFile(const char * iInputFilename, const char * iCppFilePath, const char * iFunctionIdentifier, size_t iChunkSize)
2929
{
3030
//check if input file exists
3131
FILE * input = fopen(iInputFilename, "rb");
3232
if (!input)
33-
return bin2cpp::ErrorCodes::InputFileNotFound;
33+
return false;
3434

3535
//Uppercase function identifier
3636
std::string functionIdentifier = iFunctionIdentifier;
@@ -47,7 +47,7 @@ namespace bin2cpp
4747
if (!cpp)
4848
{
4949
fclose(input);
50-
return bin2cpp::ErrorCodes::UnableToCreateOutputFiles;
50+
return false;
5151
}
5252

5353
//determine file properties
@@ -127,7 +127,7 @@ namespace bin2cpp
127127
fclose(input);
128128
fclose(cpp);
129129

130-
return bin2cpp::ErrorCodes::Success;
130+
return true;
131131
}
132132

133133
}; //bin2cpp

src/SegmentGenerator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace bin2cpp
1515
SegmentGenerator();
1616
virtual ~SegmentGenerator();
1717
virtual const char * getName() const;
18-
virtual bin2cpp::ErrorCodes createCppSourceFile(const char * iInputFilename, const char * iCppFilePath, const char * iFunctionIdentifier, size_t iChunkSize);
18+
virtual bool createCppSourceFile(const char * iInputFilename, const char * iCppFilePath, const char * iFunctionIdentifier, size_t iChunkSize);
1919
};
2020

2121
}; //bin2cpp

src/StringGenerator.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ namespace bin2cpp
2525
return "string";
2626
}
2727

28-
bin2cpp::ErrorCodes StringGenerator::createCppSourceFile(const char * iInputFilename, const char * iCppFilePath, const char * iFunctionIdentifier, size_t iChunkSize)
28+
bool StringGenerator::createCppSourceFile(const char * iInputFilename, const char * iCppFilePath, const char * iFunctionIdentifier, size_t iChunkSize)
2929
{
3030
//check if input file exists
3131
FILE * input = fopen(iInputFilename, "rb");
3232
if (!input)
33-
return bin2cpp::ErrorCodes::InputFileNotFound;
33+
return false;
3434

3535
//Uppercase function identifier
3636
std::string functionIdentifier = iFunctionIdentifier;
@@ -47,7 +47,7 @@ namespace bin2cpp
4747
if (!cpp)
4848
{
4949
fclose(input);
50-
return bin2cpp::ErrorCodes::UnableToCreateOutputFiles;
50+
return false;
5151
}
5252

5353
//determine file properties
@@ -136,7 +136,7 @@ namespace bin2cpp
136136
fclose(input);
137137
fclose(cpp);
138138

139-
return bin2cpp::ErrorCodes::Success;
139+
return true;
140140
}
141141

142142
}; //bin2cpp

src/StringGenerator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace bin2cpp
1414
StringGenerator();
1515
virtual ~StringGenerator();
1616
virtual const char * getName() const;
17-
virtual bin2cpp::ErrorCodes createCppSourceFile(const char * iInputFilename, const char * iCppFilePath, const char * iFunctionIdentifier, size_t iChunkSize);
17+
virtual bool createCppSourceFile(const char * iInputFilename, const char * iCppFilePath, const char * iFunctionIdentifier, size_t iChunkSize);
1818
};
1919

2020
}; //bin2cpp

src/errorcodes.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,6 @@ namespace bin2cpp
5858
case bin2cpp::ErrorCodes::UnableToCreateOutputFiles:
5959
return "Unable to create output files";
6060
break;
61-
case bin2cpp::ErrorCodes::OutputFileAlreadyExist:
62-
return "Output file already exist";
63-
break;
64-
case bin2cpp::ErrorCodes::OutputFilesSkipped:
65-
return "No change to input files. Skipping file generation";
66-
break;
6761
};
6862
return "Unknown";
6963
}

0 commit comments

Comments
 (0)