Graphite  Version 3
An experimental 3D geometry processing program
OGF::GomCodeGenerator Class Reference

Generates C++ code to create the GOM meta information. More...

#include <OGF/gom/codegen/codegen.h>

Public Member Functions

 GomCodeGenerator ()
 GomCodeGenerator constructor.
 
void generate (std::ostream &out, std::vector< MetaClass * > classes, const std::string &package_name)
 Generates C++ code to create the Meta information and adapters. More...
 

Protected Member Functions

void generate (MetaClass *type)
 Generates C++ code that creates the meta information associated with a class. More...
 
void generate_builtin (MetaBuiltinType *mbuiltin)
 Generates C++ code that creates the meta information associated with a builtin type. More...
 
void generate_enum (MetaEnum *menum)
 Generates C++ code that creates the meta information associated with an enum. More...
 
void generate_class (MetaClass *mclass)
 Generates C++ code that creates the meta information associated with a class. More...
 
void generate_method_adapter (MetaMethod *method)
 Generates a method adapter. More...
 
void generate_method_adapter_arglist (MetaMethod *method)
 Generates a method adapter. More...
 
void generate_signal_adapter (MetaSignal *signal)
 Generates a signal adapter. More...
 
void generate_factory (MetaConstructor *constructor)
 Generates a factory from a MetaConstructor. More...
 
void generate_attributes (const CustomAttributes *info, const std::string &variable_name, bool is_pointer=true)
 Generates C++ code that creates the CustomAttributes associated with a language construct. More...
 
std::string stringify (const std::string &s)
 Adds double quotes to a string. More...
 
std::string stringify_default_value (const MetaArg *marg)
 Generates the code that computes an object that represents a default value. More...
 
std::string colons_to_underscores (const std::string &s)
 Replaces all colons (":") with underscores ("_") in a string. More...
 
std::string method_adapter_name (MetaMethod *method)
 Generates a C++ name for a method adapter from a MetaMethod. More...
 
std::string factory_name (MetaConstructor *constructor)
 Generates a C++ name for a factory from a MetaMethod. More...
 
std::ostream & out ()
 Gets a reference to the output stream, where the generated C++ code is sent. More...
 
bool pass_by_value (const std::string &type_name)
 Tests whether objects of a given type should be passed by value or by reference. More...
 

Detailed Description

Generates C++ code to create the GOM meta information.

The GOM parser populates the Meta reflection API with description of C++ types (MetaClass, MetaEnum ...). GomCodeGenerator generates code to recreate this description, so that Graphite does not need to parse header files at startup. In addition, GomCodeGenerator generates method adapters and factories to invoke methods and create objects from Python scripts.

Definition at line 76 of file codegen.h.

Member Function Documentation

◆ colons_to_underscores()

std::string OGF::GomCodeGenerator::colons_to_underscores ( const std::string &  s)
protected

Replaces all colons (":") with underscores ("_") in a string.

Parameters
[in]sa const reference to the input string
Returns
s with all colons replaced with underscores

◆ factory_name()

std::string OGF::GomCodeGenerator::factory_name ( MetaConstructor constructor)
protected

Generates a C++ name for a factory from a MetaMethod.

Parameters
[in]constructora pointer to the MetaConstructor
Returns
a valid and unique C++ name for a factory

◆ generate() [1/2]

void OGF::GomCodeGenerator::generate ( MetaClass type)
protected

Generates C++ code that creates the meta information associated with a class.

C++ code is generated in the stream returned by out(). The function also generates dependencies (superclasses).

Parameters
[in]typepointer to the MetaClass
See also
out() generate_class()

◆ generate() [2/2]

void OGF::GomCodeGenerator::generate ( std::ostream &  out,
std::vector< MetaClass * >  classes,
const std::string &  package_name 
)

Generates C++ code to create the Meta information and adapters.

Dependencies (e.g., superclasses) are also generated, provided that they belong to package package_name.

Parameters
[out]outa reference to the stream that will receive the generated C++ code
[in]classesthe list of classes to generate, specified as a vector of pointers to MetaClass objects.
[in]package_namethe name of the package

◆ generate_attributes()

void OGF::GomCodeGenerator::generate_attributes ( const CustomAttributes info,
const std::string &  variable_name,
bool  is_pointer = true 
)
protected

Generates C++ code that creates the CustomAttributes associated with a language construct.

Parameters
[in]infopointer to an object that inherits CustomAttributes
[in]variable_namethe name of the C++ variable in the generated code where custom attributes should be copied
[in]is_pointertrue if variable_name is a pointer (to a class that inherits CustomAttributes), false if variable_name is a reference.

◆ generate_builtin()

void OGF::GomCodeGenerator::generate_builtin ( MetaBuiltinType mbuiltin)
protected

Generates C++ code that creates the meta information associated with a builtin type.

C++ code is generated in the stream returned by out().

Parameters
[in]mbuiltinpointer to the MetaBuiltinType
See also
out()

◆ generate_class()

void OGF::GomCodeGenerator::generate_class ( MetaClass mclass)
protected

Generates C++ code that creates the meta information associated with a class.

C++ code is generated in the stream returned by out(). The function only generates this MetaClass (and does not take care of dependencies).

Parameters
[in]mclasspointer to the MetaClass
See also
out() generate(MetaClass*)

◆ generate_enum()

void OGF::GomCodeGenerator::generate_enum ( MetaEnum menum)
protected

Generates C++ code that creates the meta information associated with an enum.

C++ code is generated in the stream returned by out().

Parameters
[in]menumpointer to the MetaEnum
See also
out()

◆ generate_factory()

void OGF::GomCodeGenerator::generate_factory ( MetaConstructor constructor)
protected

Generates a factory from a MetaConstructor.

C++ code is generated in the stream returned by out().

Parameters
[in]constructora pointer to the MetaConstructor
See also
generate_method_adapter()

◆ generate_method_adapter()

void OGF::GomCodeGenerator::generate_method_adapter ( MetaMethod method)
protected

Generates a method adapter.

C++ code is generated in the stream returned by out().

Parameters
[in]methoda pointer to the MetaMethod

◆ generate_method_adapter_arglist()

void OGF::GomCodeGenerator::generate_method_adapter_arglist ( MetaMethod method)
protected

Generates a method adapter.

This version is used for the special case where the method takes a ArgList as an argument. C++ code is generated in the stream returned by out().

Parameters
[in]methoda pointer to the MetaMethod
See also
generate_method_adapter()

◆ generate_signal_adapter()

void OGF::GomCodeGenerator::generate_signal_adapter ( MetaSignal signal)
protected

Generates a signal adapter.

C++ code is generated in the stream returned by out().

Parameters
[in]signala pointer to the MetaSignal
See also
generate_method_adapter()

◆ method_adapter_name()

std::string OGF::GomCodeGenerator::method_adapter_name ( MetaMethod method)
protected

Generates a C++ name for a method adapter from a MetaMethod.

Parameters
[in]methoda pointer to the MetaMethod
Returns
a valid and unique C++ name for a method adapter

◆ out()

std::ostream& OGF::GomCodeGenerator::out ( )
inlineprotected

Gets a reference to the output stream, where the generated C++ code is sent.

Returns
a reference to the output stream

Definition at line 244 of file codegen.h.

◆ pass_by_value()

bool OGF::GomCodeGenerator::pass_by_value ( const std::string &  type_name)
protected

Tests whether objects of a given type should be passed by value or by reference.

Parameters
[in]type_nameC++ type name, as a string
Return values
trueif objects of type type_name should be passed by value \retvavl false if objects of type type_name should be passed by reference

◆ stringify()

std::string OGF::GomCodeGenerator::stringify ( const std::string &  s)
protected

Adds double quotes to a string.

Parameters
[in]sa const reference to the input string
Returns
the string s with double quotes

◆ stringify_default_value()

std::string OGF::GomCodeGenerator::stringify_default_value ( const MetaArg marg)
protected

Generates the code that computes an object that represents a default value.

The default value can be either an immediate value or a constructed object, and the behavior is different in both cases.

Parameters
[in]marga const reference to the input MetaArg
Return values
thestring s with double quotes if default value is a string literal. It is the case if MetaArg is of type std::string or derived from a Name class. Since we cannot test for the latter, we guess it is the case if typename constains "Name" as a substring.
theconstant that corresponds to the default value otherwise

The documentation for this class was generated from the following file: