Skip to content

Commit 2bb2255

Browse files
committed
Modified ManagerGenerator to use TemplateProcessor.
1 parent ec2880f commit 2bb2255

File tree

6 files changed

+409
-410
lines changed

6 files changed

+409
-410
lines changed

src/bin2cpp/BaseGenerator.cpp

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,22 @@ namespace bin2cpp
5959
std::string BaseGenerator::lookupTemplateVariable(const std::string& name)
6060
{
6161
if ( name == "bin2cpp_output_file_macro_guard" ) return getCppIncludeGuardMacroName(mContext.headerFilename);
62-
if ( name == "bin2cpp_embedded_file_class_macro_guard" ) return getClassMacroGuardPrefix();
62+
if ( name == "bin2cpp_embedded_file_class_macro_guard_prefix" ) return getClassMacroGuardPrefix();
6363
if ( name == "bin2cpp_output_file_header" ) return getHeaderTemplate();
64+
if ( name == "bin2cpp_filemanager_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();
6467
if ( name == "bin2cpp_baseclass" ) return mContext.baseClass;
6568
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);
6676
if ( name == "bin2cpp_function_identifier" ) return mContext.functionIdentifier;
6777
if ( name == "bin2cpp_function_identifier_lowercase" ) return ra::strings::Lowercase(mContext.functionIdentifier);
68-
if ( name == "bin2cpp_classname" ) return getClassName();
69-
if ( name == "bin2cpp_namespace" ) return mContext.codeNamespace;
7078
if ( name == "bin2cpp_cpp_getter_function_name" ) return getGetterFunctionName();
7179
if ( name == "bin2cpp_insert_input_file_as_code" ) return getInputFileDataAsCode();
7280
if ( name == "bin2cpp_cpp_header_include_path" ) return getCppHeaderIncludePath();
@@ -283,6 +291,17 @@ namespace bin2cpp
283291
return macroGuardPrefix;
284292
}
285293

294+
std::string BaseGenerator::getFileManagerMacroGuardPrefix()
295+
{
296+
//define macro guard a macro matching the filename
297+
std::string output;
298+
output += getCppIncludeGuardMacroName(mContext.codeNamespace.c_str()); //prefix the custom namespace for the file manager
299+
if ( !output.empty() )
300+
output += "_";
301+
output += getCppIncludeGuardMacroName(mContext.managerHeaderFilename);
302+
return output;
303+
}
304+
286305
std::string BaseGenerator::getImplOfGetFileName()
287306
{
288307
std::string output;
@@ -456,8 +475,8 @@ namespace bin2cpp
456475
"\n"
457476
"namespace ${bin2cpp_namespace}\n"
458477
"{\n"
459-
" #ifndef ${bin2cpp_embedded_file_class_macro_guard}_EMBEDDEDFILE_CLASS\n"
460-
" #define ${bin2cpp_embedded_file_class_macro_guard}_EMBEDDEDFILE_CLASS\n"
478+
" #ifndef ${bin2cpp_embedded_file_class_macro_guard_prefix}_EMBEDDEDFILE_CLASS\n"
479+
" #define ${bin2cpp_embedded_file_class_macro_guard_prefix}_EMBEDDEDFILE_CLASS\n"
461480
" class ${bin2cpp_baseclass}\n"
462481
" {\n"
463482
" public:\n"
@@ -468,7 +487,7 @@ namespace bin2cpp
468487
" virtual const char * getBuffer() const = 0;\n"
469488
" virtual bool save(const char * filename) const = 0;\n"
470489
" };\n"
471-
" #endif //${bin2cpp_embedded_file_class_macro_guard}_EMBEDDEDFILE_CLASS\n"
490+
" #endif //${bin2cpp_embedded_file_class_macro_guard_prefix}_EMBEDDEDFILE_CLASS\n"
472491
" const ${bin2cpp_baseclass} & ${bin2cpp_cpp_getter_function_name}();\n"
473492
"}; //${bin2cpp_namespace}\n"
474493
"\n"
@@ -544,8 +563,8 @@ namespace bin2cpp
544563
"#include <stddef.h>\n"
545564
"#include <stdbool.h>\n"
546565
"\n"
547-
"#ifndef ${bin2cpp_embedded_file_class_macro_guard}_EMBEDDEDFILE_STRUCT\n"
548-
"#define ${bin2cpp_embedded_file_class_macro_guard}_EMBEDDEDFILE_STRUCT\n"
566+
"#ifndef ${bin2cpp_embedded_file_class_macro_guard_prefix}_EMBEDDEDFILE_STRUCT\n"
567+
"#define ${bin2cpp_embedded_file_class_macro_guard_prefix}_EMBEDDEDFILE_STRUCT\n"
549568
"typedef struct ${bin2cpp_baseclass} ${bin2cpp_baseclass};\n"
550569
"typedef bool(*${bin2cpp_namespace}_load_func)();\n"
551570
"typedef void(*${bin2cpp_namespace}_free_func)();\n"
@@ -561,7 +580,7 @@ namespace bin2cpp
561580
" ${bin2cpp_namespace}_save_func save;\n"
562581
"} ${bin2cpp_baseclass};\n"
563582
"typedef ${bin2cpp_baseclass}* ${bin2cpp_baseclass}Ptr;\n"
564-
"#endif //${bin2cpp_embedded_file_class_macro_guard}_EMBEDDEDFILE_STRUCT\n"
583+
"#endif //${bin2cpp_embedded_file_class_macro_guard_prefix}_EMBEDDEDFILE_STRUCT\n"
565584
"${bin2cpp_baseclass}* ${bin2cpp_cpp_getter_function_name}(void);\n"
566585
"\n"
567586
"#endif //${bin2cpp_output_file_macro_guard}\n"

src/bin2cpp/BaseGenerator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ namespace bin2cpp
6666
virtual std::string getCFileManagerStaticFileRegistrationImplementation();
6767
virtual std::string getClassName();
6868
virtual std::string getClassMacroGuardPrefix();
69+
virtual std::string getFileManagerMacroGuardPrefix();
6970
virtual std::string getImplOfGetFileName();
7071
virtual std::string getImplOfGetFilePath();
7172
virtual std::string getFileClassFileName();

0 commit comments

Comments
 (0)