Plugins
|
Generator to produce valid but dummy C++ files from registered classes and functions. More...
#include <cpp_generator.h>
Public Member Functions | |
CppGenerator (const string dir, ClassHierarchyProvider &chp, bool silent=false) | |
Default constructor. More... | |
void | generate_cpp_files () |
Generates C++ files for all registered classes and functions. More... | |
~CppGenerator () | |
Destructor. More... | |
Private Member Functions | |
void | generate_class_group () |
Generates C++ files for all classes in class groups. More... | |
void | generate_global_functions () |
Generates C++ code for all global functions. More... | |
void | generate_class_docu () |
Writes documentation for current class to current file. More... | |
void | generate_class_cpp () |
Writes C++ code for current class to current file. More... | |
void | generate_class_constructors () |
Writes documentation and declarations of constructors of current class. More... | |
void | generate_class_public_methods () |
Generates documentation and declarations for all methods of current class. More... | |
void | generate_class_public_members () |
Generates documentation and C++ signature for all public members of current class. More... | |
template<class TEntity > | |
void | write_brief_detail_docu (const TEntity &entity) |
Writes brief and detailed documentation for an entity. More... | |
template<class TFunction > | |
void | write_parameter_docu (const TFunction &function) |
Writes documentation for input parameters of given function. More... | |
template<class TFunction > | |
void | write_generic_function (const TFunction &function, bool constant=false) |
Writes documentation and declaration of given function. More... | |
void | write_group_definitions () |
Writes some general docu on parent namespace. More... | |
template<class TFunction > | |
string | generate_parameter_list (const TFunction &func) |
Generates parameter list for the given function. More... | |
string | generate_return_value (const bridge::ExportedFunctionBase &method) |
Writes docu on return value and returns return value as string. More... | |
string | name_to_id (const string &str) |
Converts a group or class name to a portable ID. More... | |
string | parameter_to_string (const bridge::ParameterInfo &par, const int i) const |
Converts a value type to a string representation. More... | |
string | sanitize_parameter_name (const string ¶m) const |
Tunes parameter names to be valid C++ variable names. More... | |
string | sanitize_docstring (const string &docstring, bool is_brief=false) |
Detects empty tooltips and help and fills it with dummy content. More... | |
string | sanitize_docu (const string ¶m_docu) const |
Tunes parameter name to be rendered in docu. More... | |
vector< string > | split_group_hieararchy (const string group) |
Tokenizes given group name into its separate parts. More... | |
string | write_group_namespaces (vector< string > group_hierarchy, bool is_global_func=false) |
Converts group hierarchy into namespaces and writes them to file. More... | |
Private Attributes | |
bridge::IExportedClass * | m_curr_class |
Pointer to the currently processed class (if applicable) More... | |
fstream | m_curr_file |
Current file stream to write to. More... | |
bridge::ClassGroupDesc * | m_curr_group |
Pointer to the currently processed group (if applicable) More... | |
string | m_curr_group_name |
Name of current group as in ug4 itself (including namespaces) More... | |
bool | m_is_global |
Whether the currently processed function is global. More... | |
bool | m_is_plugin |
Whether the currently processed class or function is registered by a plugin. More... | |
string | m_output_dir |
bool | m_silent |
map< string, string > | m_written_classes |
Map for keeping track of already processed classes. More... | |
ClassHierarchyProvider & | mr_chp |
Reference to a helper for retrieving the class group of a class. More... | |
bridge::Registry & | mr_reg |
Reference to the registry (to save countless calls to ug::bridge::GetUGRegistry()) More... | |
Generator to produce valid but dummy C++ files from registered classes and functions.
It requires the registry to be accessible by a call to ug::bridge::GetUGRegistry().
ug::DocuGen::CppGenerator::CppGenerator | ( | const string | dir, |
ClassHierarchyProvider & | chp, | ||
bool | silent = false |
||
) |
Default constructor.
dir | name and path of output directory for generated C++ files |
silent | flag for suppressing verbose logging |
ug::DocuGen::CppGenerator::~CppGenerator | ( | ) |
|
private |
Writes documentation and declarations of constructors of current class.
Only public constructors are written. In case there are no public constructors (i.e. the class is not instanciable), no constructors are written.
References ug::DocuGen::Doxygen::BRIEF, generate_parameter_list(), ug::bridge::IExportedClass::get_constructor(), ug::DocuGen::ClassHierarchyProvider::get_group(), ug::bridge::IExportedClass::is_instantiable(), m_curr_class, m_curr_file, mr_chp, ug::bridge::IExportedClass::name(), ug::bridge::IExportedClass::num_constructors(), UG_CATCH_THROW_FUNC, write_brief_detail_docu(), and write_parameter_docu().
Referenced by generate_class_cpp().
|
private |
Writes C++ code for current class to current file.
This includes the C++ code and documentation for all members of the current class.
References ug::bridge::ClassNameNode::base_class(), ug::bridge::IExportedClass::class_name_node(), generate_class_constructors(), generate_class_public_members(), generate_class_public_methods(), ug::DocuGen::ClassHierarchyProvider::get_group(), m_curr_class, m_curr_file, mr_chp, ug::bridge::ClassNameNode::name(), ug::bridge::IExportedClass::name(), ug::bridge::ClassNameNode::num_base_classes(), UG_CATCH_THROW_FUNC, and UG_WARNING.
Referenced by generate_class_group(), and generate_cpp_files().
|
private |
Writes documentation for current class to current file.
References ug::DocuGen::Doxygen::BRIEF, ug::DocuGen::Doxygen::CLASS, ug::DocuGen::ClassHierarchyProvider::get_group(), m_curr_class, m_curr_file, m_is_plugin, mr_chp, ug::bridge::IExportedClass::name(), ug::bridge::IExportedClass::tooltip(), UG_CATCH_THROW_FUNC, UG_WARNING, and ug::DocuGen::Doxygen::WARNING.
Referenced by generate_class_group(), and generate_cpp_files().
|
private |
Generates C++ files for all classes in class groups.
This iterates over all registered class groups and generates one C++ file per group containing all classes in this group.
Usually a class group is a templated ug4 class and the classes in this group are specializations of this template depending on the build parameters of the linked libug4.
References generate_class_cpp(), generate_class_docu(), ug::bridge::ClassGroupDesc::get_default_class(), ug::DocuGen::ClassHierarchyProvider::get_group(), ug::bridge::IExportedClass::group(), m_curr_class, m_curr_file, m_curr_group, m_curr_group_name, m_is_plugin, m_output_dir, m_silent, m_written_classes, mr_chp, ug::bridge::ClassGroupDesc::name(), ug::bridge::IExportedClass::name(), name_to_id(), ug::DocuGen::Doxygen::NOTE, ug::DocuGen::Doxygen::SEE, split_group_hieararchy(), UG_CATCH_THROW_FUNC, UG_LOG, UG_WARNING, and write_group_namespaces().
Referenced by generate_cpp_files().
|
private |
Generates documentation and C++ signature for all public members of current class.
Referenced by generate_class_cpp().
|
private |
Generates documentation and declarations for all methods of current class.
References ug::bridge::IExportedClass::get_const_method(), ug::bridge::IExportedClass::get_method(), m_curr_class, m_curr_file, ug::bridge::IExportedClass::num_const_methods(), ug::bridge::IExportedClass::num_methods(), UG_CATCH_THROW_FUNC, and write_generic_function().
Referenced by generate_class_cpp().
void ug::DocuGen::CppGenerator::generate_cpp_files | ( | ) |
Generates C++ files for all registered classes and functions.
References generate_class_cpp(), generate_class_docu(), generate_class_group(), generate_global_functions(), ug::bridge::Registry::get_class(), ug::bridge::Registry::get_class_group(), ug::DocuGen::ClassHierarchyProvider::get_group(), ug::bridge::IExportedClass::group(), m_curr_class, m_curr_file, m_curr_group, m_curr_group_name, m_output_dir, m_silent, m_written_classes, mr_chp, mr_reg, ug::bridge::IExportedClass::name(), name_to_id(), ug::bridge::Registry::num_class_groups(), ug::bridge::Registry::num_classes(), ug::bridge::Registry::num_functions(), split_group_hieararchy(), UG_CATCH_THROW_FUNC, UG_LOG, write_group_definitions(), and write_group_namespaces().
Referenced by ug::GenerateScriptReferenceDocu().
|
private |
Generates C++ code for all global functions.
This iterates over all global functions and writes their documentation and declaration to the file global_functions.cpp
.
References ug::bridge::Registry::get_function(), ug::bridge::ExportedFunction::group(), m_curr_file, m_is_global, m_is_plugin, m_output_dir, mr_reg, ug::bridge::Registry::num_functions(), split_group_hieararchy(), UG_CATCH_THROW_FUNC, UG_LOG, write_generic_function(), and write_group_namespaces().
Referenced by generate_cpp_files().
|
private |
Generates parameter list for the given function.
Generates the parameter list as in function declerations for the given registered method. The enclosing brakets ('(' and ')') are also written.
TFunction | a function type usually either derived from ug::bridge::ExportedFunctionBase or ug::bridge::ExportedConstructor providing at least the members
|
func | method object to be used |
References parameter_to_string(), sanitize_parameter_name(), and UG_CATCH_THROW_FUNC.
Referenced by generate_class_constructors(), and write_generic_function().
|
private |
Writes docu on return value and returns return value as string.
Documentation on the return value of the given function method
is written to m_curr_file.
A single return value is converted into a valid C++ string by utilizing ug::bridge::ParameterToString(). If func
has no return value, void
is displayed and returned.
method | the method to generated the return value for |
func
as a string References m_curr_file, parameter_to_string(), ug::bridge::ExportedFunctionBase::params_out(), ug::bridge::ExportedFunctionBase::return_info(), ug::DocuGen::Doxygen::RETURNS, sanitize_docu(), ug::bridge::ParameterInfo::size(), UG_CATCH_THROW_FUNC, and UG_WARNING.
Referenced by write_generic_function().
|
inlineprivate |
Converts a group or class name to a portable ID.
It
str | initial name to convert |
Referenced by generate_class_group(), generate_cpp_files(), and split_group_hieararchy().
|
private |
Converts a value type to a string representation.
ug4's internal classes are correctly substituted as well as other registered classes and types.
[in] | par | parameter stack |
[in] | i | index of the parameter from the parameter stack |
References ug::bridge::ParameterInfo::class_name(), ug::DocuGen::ClassHierarchyProvider::get_group(), ug::bridge::ParameterInfo::is_vector(), mr_chp, ug::bridge::ParameterInfo::type(), ug::Variant::VT_BOOL, ug::Variant::VT_CONST_POINTER, ug::Variant::VT_CONST_SMART_POINTER, ug::Variant::VT_CSTRING, ug::Variant::VT_DOUBLE, ug::Variant::VT_FLOAT, ug::Variant::VT_INT, ug::Variant::VT_INVALID, ug::Variant::VT_POINTER, ug::Variant::VT_SIZE_T, ug::Variant::VT_SMART_POINTER, and ug::Variant::VT_STDSTRING.
Referenced by generate_parameter_list(), and generate_return_value().
|
inlineprivate |
Detects empty tooltips and help and fills it with dummy content.
For an empty tooltip (e.g. a brief docu) the string "no brief documentation" is used; for an empty help (e.g. a detailed docu) the string "no documentation" is used
[in] | docstring | either a tooltip or help text |
[in] | is_brief | indicator whether the docstring is a tooltip |
Referenced by write_brief_detail_docu().
|
inlineprivate |
Tunes parameter name to be rendered in docu.
In case the given parameter is empty, it is rendered as undocumented
. Otherwise it is returned as it.
param_docu | parameter to be preprocessed for docstring. |
Referenced by generate_return_value().
|
inlineprivate |
Tunes parameter names to be valid C++ variable names.
In case the given parameter name is empty, it is rendered as unnamed
. Otherwise it trims leading and trailing whitespaces and replaces the remaining whitespaces by underscores.
param | parameter name to be preprocessed |
Referenced by generate_parameter_list(), and write_parameter_docu().
|
private |
Tokenizes given group name into its separate parts.
Splits the given group name at the characters '_' and '/'.
group | group name to be tokenized |
References ug::find(), m_is_plugin, and name_to_id().
Referenced by generate_class_group(), generate_cpp_files(), and generate_global_functions().
|
private |
Writes brief and detailed documentation for an entity.
Writes the brief and detailed documentation for the given entity to the current file.
TEntity | Either a registered class or function, which provides the members
|
entity | Class or function to be documented |
References ug::DocuGen::Doxygen::BRIEF, ug::DocuGen::Doxygen::DETAILS, m_curr_file, and sanitize_docstring().
Referenced by generate_class_constructors(), and write_generic_function().
|
private |
Writes documentation and declaration of given function.
Writes the full documentation and method signature of the given function to the current file.
TFunction | a function type usually derived from ug::bridge::ExportedFunctionBase providing at least the members
|
function | function to be written |
constant | whether the function is const or not |
References generate_parameter_list(), generate_return_value(), m_curr_file, m_curr_group_name, m_is_global, m_is_plugin, UG_CATCH_THROW_FUNC, ug::DocuGen::Doxygen::WARNING, write_brief_detail_docu(), and write_parameter_docu().
Referenced by generate_class_public_methods(), and generate_global_functions().
|
private |
Writes some general docu on parent namespace.
also warning for the plugin namespace
References ug::DocuGen::Doxygen::BRIEF, m_curr_file, m_output_dir, UG_CATCH_THROW_FUNC, and ug::DocuGen::Doxygen::WARNING.
Referenced by generate_cpp_files().
|
private |
Converts group hierarchy into namespaces and writes them to file.
Creates a namespace for each element of the group vector while empty group names are ignored and the group name ug4 is replaced by ug4bridge .
[in] | group_hierarchy | vector of groups as returned by split_group_hieararchy(group) |
References m_curr_file.
Referenced by generate_class_group(), generate_cpp_files(), and generate_global_functions().
|
private |
Writes documentation for input parameters of given function.
For each input parameter of the given function the documentation is written to the current file
TFunction | a function type usually either derived from ug::bridge::ExportedFunctionBase or ug::bridge::ExportedConstructor providing at least the members
|
function | function to be documented |
References m_curr_file, ug::DocuGen::Doxygen::PARAM_IN, and sanitize_parameter_name().
Referenced by generate_class_constructors(), and write_generic_function().
|
private |
Pointer to the currently processed class (if applicable)
Referenced by generate_class_constructors(), generate_class_cpp(), generate_class_docu(), generate_class_group(), generate_class_public_methods(), and generate_cpp_files().
|
private |
Current file stream to write to.
Referenced by generate_class_constructors(), generate_class_cpp(), generate_class_docu(), generate_class_group(), generate_class_public_methods(), generate_cpp_files(), generate_global_functions(), generate_return_value(), write_brief_detail_docu(), write_generic_function(), write_group_definitions(), write_group_namespaces(), write_parameter_docu(), and ~CppGenerator().
|
private |
Pointer to the currently processed group (if applicable)
Referenced by generate_class_group(), and generate_cpp_files().
|
private |
Name of current group as in ug4 itself (including namespaces)
Referenced by generate_class_group(), generate_cpp_files(), and write_generic_function().
|
private |
Whether the currently processed function is global.
Referenced by generate_global_functions(), and write_generic_function().
|
private |
Whether the currently processed class or function is registered by a plugin.
Referenced by generate_class_docu(), generate_class_group(), generate_global_functions(), split_group_hieararchy(), and write_generic_function().
|
private |
Referenced by generate_class_group(), generate_cpp_files(), generate_global_functions(), and write_group_definitions().
|
private |
Referenced by generate_class_group(), and generate_cpp_files().
|
private |
Map for keeping track of already processed classes.
Key is the class name, which maps to the file name this class has been written to.
Referenced by generate_class_group(), and generate_cpp_files().
|
private |
Reference to a helper for retrieving the class group of a class.
Referenced by generate_class_constructors(), generate_class_cpp(), generate_class_docu(), generate_class_group(), generate_cpp_files(), and parameter_to_string().
|
private |
Reference to the registry (to save countless calls to ug::bridge::GetUGRegistry())
Referenced by generate_cpp_files(), and generate_global_functions().