Skip to content

Commit 06af3fb

Browse files
committed
Revert "Renamed interface ITemplateVariableLookup to ITemplateVariableHandler."
This reverts commit d5ad856. Revert "First draft for modifying the TemplateProcessor to support TemplateVariable that are strings or streams." This reverts commit 94102bc.
1 parent d5ad856 commit 06af3fb

17 files changed

+103
-261
lines changed

src/bin2cpp/ArrayGenerator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ namespace bin2cpp
8282
"}; //${bin2cpp_namespace}\n";
8383

8484
TemplateProcessor processor(&text);
85-
processor.setTemplateVariableHandler(this);
85+
processor.setTemplateVariableLookup(this);
8686
bool write_success = processor.writeFile(file_path);
8787

8888
return write_success;
@@ -179,7 +179,7 @@ namespace bin2cpp
179179
"${bin2cpp_c_file_manager_registration_implementation}";
180180

181181
TemplateProcessor processor(&text);
182-
processor.setTemplateVariableHandler(this);
182+
processor.setTemplateVariableLookup(this);
183183
bool write_success = processor.writeFile(file_path);
184184

185185
return write_success;

src/bin2cpp/BaseGenerator.cpp

Lines changed: 43 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,6 @@ namespace bin2cpp
4040
{
4141
BaseGenerator::BaseGenerator()
4242
{
43-
// Load existing variables
44-
registerTemplateVariable("bin2cpp_baseclass");
45-
registerTemplateVariable("bin2cpp_c_file_manager_registration_implementation");
46-
registerTemplateVariable("bin2cpp_c_file_manager_registration_post_init_impl");
47-
registerTemplateVariable("bin2cpp_c_file_manager_registration_predeclaration");
48-
registerTemplateVariable("bin2cpp_classname");
49-
registerTemplateVariable("bin2cpp_cpp_get_file_manager_registration_impl");
50-
registerTemplateVariable("bin2cpp_cpp_get_save_method_impl");
51-
registerTemplateVariable("bin2cpp_file_manager_file_header");
52-
registerTemplateVariable("bin2cpp_file_manager_header_file_name");
53-
registerTemplateVariable("bin2cpp_file_manager_macro_guard_prefix");
54-
registerTemplateVariable("bin2cpp_file_object_file_name_impl");
55-
registerTemplateVariable("bin2cpp_file_object_file_name");
56-
registerTemplateVariable("bin2cpp_file_object_file_path_impl");
57-
registerTemplateVariable("bin2cpp_file_object_file_path");
58-
registerTemplateVariable("bin2cpp_file_object_macro_guard_prefix");
59-
registerTemplateVariable("bin2cpp_function_identifier_lowercase");
60-
registerTemplateVariable("bin2cpp_function_identifier");
61-
registerTemplateVariable("bin2cpp_getter_function_name");
62-
registerTemplateVariable("bin2cpp_header_source_file_include_path");
63-
registerTemplateVariable("bin2cpp_input_file_size");
64-
registerTemplateVariable("bin2cpp_insert_input_file_as_code");
65-
registerTemplateVariable("bin2cpp_namespace");
66-
registerTemplateVariable("bin2cpp_output_file_header");
67-
registerTemplateVariable("bin2cpp_output_file_macro_guard");
6843
}
6944

7045
BaseGenerator::~BaseGenerator()
@@ -81,108 +56,65 @@ namespace bin2cpp
8156
return mContext;
8257
}
8358

84-
TemplateVariableFlags BaseGenerator::getTemplateVariableFlags(const std::string& name)
85-
{
86-
if ( !isRegistedTemplateVariable(name) )
87-
return TEMPLATE_VARIABLE_FLAG_NONE;
88-
89-
// Handle streamable-only variables
90-
if ( name == "bin2cpp_insert_input_file_as_code" ) return TEMPLATE_VARIABLE_FLAG_STREAMABLE;
91-
92-
// All other variables are stringable or streamable
93-
return (TemplateVariableFlags)(TEMPLATE_VARIABLE_FLAG_STRINGNABLE | TEMPLATE_VARIABLE_FLAG_STREAMABLE);
94-
}
95-
96-
void BaseGenerator::writeTemplateVariable(const std::string& name, std::ostream& output)
97-
{
98-
TemplateVariableFlags flags = getTemplateVariableFlags(name);
99-
if ( (flags & TEMPLATE_VARIABLE_FLAG_STREAMABLE) != TEMPLATE_VARIABLE_FLAG_STREAMABLE )
100-
return; // Not streamable
101-
102-
if ( name == "bin2cpp_insert_input_file_as_code" ) output << getInputFileDataAsCode(); return;
103-
104-
// Other variables are assumed "stringable"
105-
std::string tmp;
106-
writeTemplateVariable(name, tmp);
107-
if ( !tmp.empty() )
108-
{
109-
output << tmp;
110-
return;
111-
}
112-
}
113-
114-
void BaseGenerator::writeTemplateVariable(const std::string& name, std::string& output)
115-
{
116-
output.clear();
117-
TemplateVariableFlags flags = getTemplateVariableFlags(name);
118-
if ( (flags & TEMPLATE_VARIABLE_FLAG_STRINGNABLE) != TEMPLATE_VARIABLE_FLAG_STRINGNABLE )
119-
return; // not stringable
120-
121-
if ( name == "bin2cpp_output_file_macro_guard" ) { output = getCppIncludeGuardMacroName(mContext.headerFilename); return; }
122-
if ( name == "bin2cpp_output_file_header" ) { output = getHeaderTemplate(); return; }
123-
if ( name == "bin2cpp_file_object_macro_guard_prefix" ) { output = getClassMacroGuardPrefix(); return; }
124-
if ( name == "bin2cpp_file_manager_file_header" ) { output = getHeaderTemplate(false); return; }
125-
if ( name == "bin2cpp_file_manager_header_file_name" ) { output = mContext.managerHeaderFilename; return; }
126-
if ( name == "bin2cpp_file_manager_macro_guard_prefix" ) { output = getFileManagerMacroGuardPrefix(); return; }
127-
if ( name == "bin2cpp_baseclass" ) { output = mContext.baseClass; return; }
128-
if ( name == "bin2cpp_classname" ) { output = getClassName(); return; }
129-
if ( name == "bin2cpp_namespace" ) { output = mContext.codeNamespace; return; }
130-
//if ( name == "bin2cpp_baseclass_uppercase" ) { output = ra::strings::Uppercase(mContext.baseClass); return; }
131-
//if ( name == "bin2cpp_classname_uppercase" ) { output = ra::strings::Uppercase(getClassName()); return; }
132-
//if ( name == "bin2cpp_namespace_uppercase" ) { output = ra::strings::Lowercase(mContext.codeNamespace); return; }
133-
//if ( name == "bin2cpp_baseclass_lowercase" ) { output = ra::strings::Lowercase(mContext.baseClass); return; }
134-
//if ( name == "bin2cpp_classname_lowercase" ) { output = ra::strings::Lowercase(getClassName()); return; }
135-
//if ( name == "bin2cpp_namespace_lowercase" ) { output = ra::strings::Lowercase(mContext.codeNamespace); return; }
136-
if ( name == "bin2cpp_function_identifier" ) { output = mContext.functionIdentifier; return; }
137-
if ( name == "bin2cpp_function_identifier_lowercase" ) { output = ra::strings::Lowercase(mContext.functionIdentifier); return; }
138-
if ( name == "bin2cpp_getter_function_name" ) { output = getGetterFunctionName(); return; }
139-
if ( name == "bin2cpp_header_source_file_include_path" ) { output = getCppHeaderIncludePath(); return; }
140-
if ( name == "bin2cpp_file_object_file_name_impl" ) { output = getFileClassGetFileNameImplementation(); return; }
141-
if ( name == "bin2cpp_file_object_file_path_impl" ) { output = getFileClassGetFilePathImplementation(); return; }
142-
if ( name == "bin2cpp_file_object_file_name" ) { output = getFileClassFileName(); return; }
143-
if ( name == "bin2cpp_file_object_file_path" ) { output = getFileClassFilePath(); return; }
144-
if ( name == "bin2cpp_cpp_get_save_method_impl" ) { output = getCppSaveMethodTemplate(); return; }
145-
if ( name == "bin2cpp_cpp_get_file_manager_registration_impl" && mContext.registerFiles ) { output = getCppFileManagerRegistrationImplementationTemplate(); return; }
146-
if ( name == "bin2cpp_c_file_manager_registration_predeclaration" && mContext.registerFiles ) { output = getCFileManagerRegistrationPredeclarationImplementation(); return; }
147-
if ( name == "bin2cpp_c_file_manager_registration_implementation" && mContext.registerFiles ) { output = getCFileManagerStaticFileRegistrationImplementation(); return; }
148-
59+
std::string BaseGenerator::lookupTemplateVariable(const std::string& name)
60+
{
61+
if ( name == "bin2cpp_output_file_macro_guard" ) return getCppIncludeGuardMacroName(mContext.headerFilename);
62+
if ( name == "bin2cpp_output_file_header" ) return getHeaderTemplate();
63+
if ( name == "bin2cpp_file_object_macro_guard_prefix" ) return getClassMacroGuardPrefix();
64+
if ( name == "bin2cpp_file_manager_file_header" ) return getHeaderTemplate(false);
65+
if ( name == "bin2cpp_file_manager_header_file_name" ) return mContext.managerHeaderFilename;
66+
if ( name == "bin2cpp_file_manager_macro_guard_prefix" ) return getFileManagerMacroGuardPrefix();
67+
if ( name == "bin2cpp_baseclass" ) return mContext.baseClass;
68+
if ( name == "bin2cpp_classname" ) return getClassName();
69+
if ( name == "bin2cpp_namespace" ) return mContext.codeNamespace;
70+
//if ( name == "bin2cpp_baseclass_uppercase" ) return ra::strings::Uppercase(mContext.baseClass);
71+
//if ( name == "bin2cpp_classname_uppercase" ) return ra::strings::Uppercase(getClassName());
72+
//if ( name == "bin2cpp_namespace_uppercase" ) return ra::strings::Lowercase(mContext.codeNamespace);
73+
//if ( name == "bin2cpp_baseclass_lowercase" ) return ra::strings::Lowercase(mContext.baseClass);
74+
//if ( name == "bin2cpp_classname_lowercase" ) return ra::strings::Lowercase(getClassName());
75+
//if ( name == "bin2cpp_namespace_lowercase" ) return ra::strings::Lowercase(mContext.codeNamespace);
76+
if ( name == "bin2cpp_function_identifier" ) return mContext.functionIdentifier;
77+
if ( name == "bin2cpp_function_identifier_lowercase" ) return ra::strings::Lowercase(mContext.functionIdentifier);
78+
if ( name == "bin2cpp_getter_function_name" ) return getGetterFunctionName();
79+
if ( name == "bin2cpp_insert_input_file_as_code" ) return getInputFileDataAsCode();
80+
if ( name == "bin2cpp_header_source_file_include_path" ) return getCppHeaderIncludePath();
81+
if ( name == "bin2cpp_file_object_file_name_impl" ) return getFileClassGetFileNameImplementation();
82+
if ( name == "bin2cpp_file_object_file_path_impl" ) return getFileClassGetFilePathImplementation();
83+
if ( name == "bin2cpp_file_object_file_name" ) return getFileClassFileName();
84+
if ( name == "bin2cpp_file_object_file_path" ) return getFileClassFilePath();
85+
if ( name == "bin2cpp_cpp_get_save_method_impl" ) return getCppSaveMethodTemplate();
86+
if ( name == "bin2cpp_cpp_get_file_manager_registration_impl" && mContext.registerFiles ) return getCppFileManagerRegistrationImplementationTemplate();
87+
if ( name == "bin2cpp_c_file_manager_registration_predeclaration" && mContext.registerFiles ) return getCFileManagerRegistrationPredeclarationImplementation();
88+
if ( name == "bin2cpp_c_file_manager_registration_implementation" && mContext.registerFiles ) return getCFileManagerStaticFileRegistrationImplementation();
89+
14990
if ( name == "bin2cpp_c_file_manager_registration_post_init_impl" && mContext.registerFiles )
15091
{
151-
std::string tmp;
152-
tmp += " \n";
153-
tmp += " // register when loaded if static initialisation does not work\n";
154-
tmp += " ${bin2cpp_namespace}_filemanager_register_file(file);\n";
155-
output = tmp;
156-
return;
92+
std::string output;
93+
output += " \n";
94+
output += " // register when loaded if static initialisation does not work\n";
95+
output += " ${bin2cpp_namespace}_filemanager_register_file(file);\n";
96+
return output;
15797
}
15898

15999
if ( name == "bin2cpp_input_file_size" )
160100
{
161101
//determine file properties
162102
uint32_t file_size = ra::filesystem::GetFileSize(mContext.inputFilePath.c_str());
163103
std::string file_size_str = ra::strings::ToString(file_size);
164-
output = file_size_str;
165-
return;
104+
return file_size_str;
166105
}
106+
107+
// Unknown name
108+
return "";
167109
}
168110

169111
//-------------------------------
170112
//protected methods
171113
//-------------------------------
172114

173-
void BaseGenerator::registerTemplateVariable(const char* name)
174-
{
175-
mTemplateVariableNames.insert(name);
176-
}
177-
178-
bool BaseGenerator::isRegistedTemplateVariable(const std::string& name)
179-
{
180-
bool found = std::find(mTemplateVariableNames.begin(), mTemplateVariableNames.end(), name) != mTemplateVariableNames.end();
181-
return found;
182-
}
183-
184115
std::string BaseGenerator::getGetterFunctionName()
185116
{
117+
186118
std::string getter;
187119
switch ( mContext.code )
188120
{
@@ -568,7 +500,7 @@ namespace bin2cpp
568500
;
569501

570502
TemplateProcessor processor(&text);
571-
processor.setTemplateVariableHandler(this);
503+
processor.setTemplateVariableLookup(this);
572504
bool write_success = processor.writeFile(header_file_path);
573505

574506
return write_success;
@@ -660,7 +592,7 @@ namespace bin2cpp
660592
;
661593

662594
TemplateProcessor processor(&text);
663-
processor.setTemplateVariableHandler(this);
595+
processor.setTemplateVariableLookup(this);
664596
bool write_success = processor.writeFile(file_path);
665597

666598
return write_success;

src/bin2cpp/BaseGenerator.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#define BASEGENERATOR_H
2727

2828
#include "IGenerator.h"
29-
#include "types.h"
3029
#include <map>
3130

3231
namespace bin2cpp
@@ -45,10 +44,8 @@ namespace bin2cpp
4544
virtual void setContext(const Context& c);
4645
virtual const Context & getContext() const;
4746

48-
//ITemplateVariableHandler methods
49-
virtual TemplateVariableFlags getTemplateVariableFlags(const std::string& name);
50-
virtual void writeTemplateVariable(const std::string& name, std::ostream& output);
51-
virtual void writeTemplateVariable(const std::string& name, std::string& output);
47+
//ITemplateVariableLookup methods
48+
virtual std::string lookupTemplateVariable(const std::string& name);
5249

5350
//same header file for all generators
5451
virtual bool createCppHeaderFile(const char * header_file_path);
@@ -57,8 +54,7 @@ namespace bin2cpp
5754
virtual bool createCSourceFile(const char* file_path);
5855

5956
protected:
60-
virtual void registerTemplateVariable(const char* name);
61-
virtual bool isRegistedTemplateVariable(const std::string& name);
57+
6258
virtual std::string getGetterFunctionName();
6359
virtual std::string getHeaderFilePath(const char * cpp_file_path);
6460
virtual std::string getCppFilePath(const char * header_file_path);
@@ -81,9 +77,6 @@ namespace bin2cpp
8177

8278
//attributes
8379
Context mContext;
84-
85-
private:
86-
Dictionary mTemplateVariableNames;
8780
};
8881

8982
}; //bin2cpp

src/bin2cpp/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ add_executable(bin2cpp
2222
enums.h
2323
IGenerator.h
2424
INameProvider.h
25-
ITemplateVariableHandler.h
25+
ITemplateVariableLookup.h
2626
LegacyNameProvider.cpp
2727
LegacyNameProvider.h
2828
main.cpp

src/bin2cpp/IGenerator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727

2828
#include <string>
2929
#include "Context.h"
30-
#include "ITemplateVariableHandler.h"
30+
#include "ITemplateVariableLookup.h"
3131

3232
namespace bin2cpp
3333
{
3434

35-
class IGenerator : public virtual ITemplateVariableHandler
35+
class IGenerator : public virtual ITemplateVariableLookup
3636
{
3737
public:
3838

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,45 +22,29 @@
2222
* SOFTWARE.
2323
*********************************************************************************/
2424

25-
#ifndef ITEMPLATE_VARIABLE_HANDLER_H
26-
#define ITEMPLATE_VARIABLE_HANDLER_H
25+
#ifndef ITEMPLATE_VARIABLE_LOOKUP_H
26+
#define ITEMPLATE_VARIABLE_LOOKUP_H
2727

28-
#include "enums.h"
2928
#include <string>
30-
#include <ostream>
31-
29+
3230
namespace bin2cpp
3331
{
3432

35-
class ITemplateVariableHandler
33+
class ITemplateVariableLookup
3634
{
3735
public:
38-
virtual ~ITemplateVariableHandler()
36+
virtual ~ITemplateVariableLookup()
3937
{}
4038

4139
///<summary>
42-
///Get the associated flags for the given template variable name.
43-
///</summary>
44-
///<param name="name">The name of the template variable.</param>
45-
///<return>Returns the flags for template variable of the given name.<return>
46-
virtual TemplateVariableFlags getTemplateVariableFlags(const std::string& name) = 0;
47-
48-
///<summary>
49-
///Write the value of the given template variable name to the output stream.
50-
///</summary>
51-
///<param name="name">The name of the template variable.</param>
52-
///<param name="output">The variable where to output the template variable's value.</param>
53-
virtual void writeTemplateVariable(const std::string& name, std::ostream& output) = 0;
54-
55-
///<summary>
56-
///Write the value of the given template variable name to the output string.
40+
///Look up the value for a given template variable name.
5741
///</summary>
5842
///<param name="name">The name of the template variable.</param>
59-
///<param name="output">The variable where to output the template variable's value.</param>
60-
virtual void writeTemplateVariable(const std::string& name, std::string& output) = 0;
43+
///<return>Returns the value of the template variable. Returns an empty string if unknown.<return>
44+
virtual std::string lookupTemplateVariable(const std::string& name) = 0;
6145

6246
};
6347

6448
}; //bin2cpp
6549

66-
#endif //ITEMPLATE_VARIABLE_HANDLER_H
50+
#endif //ITEMPLATE_VARIABLE_LOOKUP_H

src/bin2cpp/ManagerGenerator.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ namespace bin2cpp
9898
;
9999

100100
TemplateProcessor processor(&text);
101-
processor.setTemplateVariableHandler(this);
101+
processor.setTemplateVariableLookup(this);
102102
bool write_success = processor.writeFile(file_path);
103103

104104
return write_success;
@@ -218,7 +218,7 @@ namespace bin2cpp
218218
;
219219

220220
TemplateProcessor processor(&text);
221-
processor.setTemplateVariableHandler(this);
221+
processor.setTemplateVariableLookup(this);
222222
bool write_success = processor.writeFile(file_path);
223223

224224
return write_success;
@@ -262,7 +262,7 @@ namespace bin2cpp
262262
;
263263

264264
TemplateProcessor processor(&text);
265-
processor.setTemplateVariableHandler(this);
265+
processor.setTemplateVariableLookup(this);
266266
bool write_success = processor.writeFile(file_path);
267267

268268
return write_success;
@@ -429,7 +429,7 @@ namespace bin2cpp
429429
;
430430

431431
TemplateProcessor processor(&text);
432-
processor.setTemplateVariableHandler(this);
432+
processor.setTemplateVariableLookup(this);
433433
bool write_success = processor.writeFile(file_path);
434434

435435
return write_success;

src/bin2cpp/SegmentGenerator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ namespace bin2cpp
8888
"}; //${bin2cpp_namespace}\n";
8989

9090
TemplateProcessor processor(&text);
91-
processor.setTemplateVariableHandler(this);
91+
processor.setTemplateVariableLookup(this);
9292
bool write_success = processor.writeFile(file_path);
9393

9494
return write_success;
@@ -179,7 +179,7 @@ namespace bin2cpp
179179
"${bin2cpp_c_file_manager_registration_implementation}";
180180

181181
TemplateProcessor processor(&text);
182-
processor.setTemplateVariableHandler(this);
182+
processor.setTemplateVariableLookup(this);
183183
bool write_success = processor.writeFile(file_path);
184184

185185
return write_success;

0 commit comments

Comments
 (0)