OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
t_generator Class Referenceabstract

#include <t_generator.h>

Inheritance diagram for t_generator:
Collaboration diagram for t_generator:

Public Member Functions

 t_generator (t_program *program)
 
virtual ~t_generator ()
 
virtual void generate_program ()
 
const t_programget_program () const
 
void generate_docstring_comment (std::ofstream &out, const std::string &comment_start, const std::string &line_prefix, const std::string &contents, const std::string &comment_end)
 
virtual std::string escape_string (const std::string &in) const
 
std::string get_escaped_string (t_const_value *constval)
 

Static Public Member Functions

static bool is_valid_namespace (const std::string &sub_namespace)
 
static t_typeget_true_type (t_type *type)
 

Protected Member Functions

virtual void init_generator ()
 
virtual void close_generator ()
 
virtual void generate_consts (std::vector< t_const * > consts)
 
virtual void generate_typedef (t_typedef *ttypedef)=0
 
virtual void generate_enum (t_enum *tenum)=0
 
virtual void generate_const (t_const *tconst)
 
virtual void generate_struct (t_struct *tstruct)=0
 
virtual void generate_service (t_service *tservice)=0
 
virtual void generate_xception (t_struct *txception)
 
virtual std::string get_program_name (t_program *tprogram)
 
virtual std::string get_service_name (t_service *tservice)
 
virtual std::string get_out_dir () const
 
std::string tmp (std::string name)
 
void indent_up ()
 
void indent_down ()
 
std::string indent ()
 
std::ostream & indent (std::ostream &os)
 
std::string capitalize (std::string in)
 
std::string decapitalize (std::string in)
 
std::string lowercase (std::string in)
 
std::string uppercase (std::string in)
 
std::string underscore (std::string in)
 
std::string camelcase (std::string in)
 

Protected Attributes

t_programprogram_
 
std::string program_name_
 
std::string service_name_
 
std::string out_dir_base_
 
std::map< char, std::string > escape_
 

Private Attributes

int indent_
 
int tmp_
 

Detailed Description

Base class for a thrift code generator. This class defines the basic routines for code generation and contains the top level method that dispatches code generation across various components.

Definition at line 37 of file t_generator.h.

Constructor & Destructor Documentation

t_generator::t_generator ( t_program program)
inline

Definition at line 39 of file t_generator.h.

Here is the call graph for this function:

virtual t_generator::~t_generator ( )
inlinevirtual

Definition at line 51 of file t_generator.h.

Member Function Documentation

std::string t_generator::camelcase ( std::string  in)
inlineprotected

Transforms a string with words separated by underscores to a camel case equivalent e.g. a_multi_word -> aMultiWord some_name -> someName name -> name

Definition at line 244 of file t_generator.h.

Here is the call graph for this function:

std::string t_generator::capitalize ( std::string  in)
inlineprotected

Capitalization helpers

Definition at line 200 of file t_generator.h.

virtual void t_generator::close_generator ( )
inlineprotectedvirtual

Reimplemented in t_py_generator, t_c_generator, t_cpp_generator, and t_xsd_generator.

Definition at line 98 of file t_generator.h.

std::string t_generator::decapitalize ( std::string  in)
inlineprotected

Definition at line 204 of file t_generator.h.

string t_generator::escape_string ( const std::string &  in) const
virtual

Escape string to use one in generated sources.

Definition at line 87 of file t_generator.cc.

virtual void t_generator::generate_const ( t_const tconst)
inlineprotectedvirtual

Reimplemented in t_doc_generator, t_py_generator, and t_html_generator.

Definition at line 108 of file t_generator.h.

void t_generator::generate_consts ( std::vector< t_const * >  consts)
protectedvirtual

Reimplemented in t_cpp_generator.

Definition at line 100 of file t_generator.cc.

void t_generator::generate_docstring_comment ( std::ofstream &  out,
const std::string &  comment_start,
const std::string &  line_prefix,
const std::string &  contents,
const std::string &  comment_end 
)

Definition at line 107 of file t_generator.cc.

virtual void t_generator::generate_enum ( t_enum tenum)
protectedpure virtual
void t_generator::generate_program ( )
virtual

Framework generator method that iterates over all the parts of a program and performs general actions. This is implemented by the base class and should not normally be overwritten in the subclasses.

Top level program generation function. Calls the generator subclass methods for preparing file streams etc. then iterates over all the parts of the program to perform the correct actions.

Parameters
programThe thrift program to compile into C++ source

Reimplemented in t_doc_generator, and t_html_generator.

Definition at line 30 of file t_generator.cc.

virtual void t_generator::generate_service ( t_service tservice)
protectedpure virtual
virtual void t_generator::generate_struct ( t_struct tstruct)
protectedpure virtual
virtual void t_generator::generate_typedef ( t_typedef ttypedef)
protectedpure virtual

Pure virtual methods implemented by the generator subclasses.

Implemented in t_doc_generator, t_py_generator, t_c_generator, t_cpp_generator, t_html_generator, and t_xsd_generator.

virtual void t_generator::generate_xception ( t_struct txception)
inlineprotectedvirtual

Reimplemented in t_py_generator, t_c_generator, and t_cpp_generator.

Definition at line 113 of file t_generator.h.

Here is the call graph for this function:

std::string t_generator::get_escaped_string ( t_const_value constval)
inline

Definition at line 86 of file t_generator.h.

Here is the call graph for this function:

virtual std::string t_generator::get_out_dir ( ) const
inlineprotectedvirtual

Get the current output directory

Definition at line 148 of file t_generator.h.

Here is the call graph for this function:

const t_program* t_generator::get_program ( ) const
inline

Definition at line 60 of file t_generator.h.

virtual std::string t_generator::get_program_name ( t_program tprogram)
inlineprotectedvirtual

Method to get the program name, may be overridden

Definition at line 125 of file t_generator.h.

Here is the call graph for this function:

virtual std::string t_generator::get_service_name ( t_service tservice)
inlineprotectedvirtual

Method to get the service name, may be overridden

Definition at line 132 of file t_generator.h.

Here is the call graph for this function:

static t_type* t_generator::get_true_type ( t_type type)
inlinestatic

Get the true type behind a series of typedefs.

Definition at line 268 of file t_generator.h.

Here is the call graph for this function:

std::string t_generator::indent ( )
inlineprotected

Indentation print function

Definition at line 181 of file t_generator.h.

std::ostream& t_generator::indent ( std::ostream &  os)
inlineprotected

Indentation utility wrapper

Definition at line 193 of file t_generator.h.

Here is the call graph for this function:

void t_generator::indent_down ( )
inlineprotected

Definition at line 174 of file t_generator.h.

void t_generator::indent_up ( )
inlineprotected

Indentation level modifiers

Definition at line 170 of file t_generator.h.

virtual void t_generator::init_generator ( )
inlineprotectedvirtual

Optional methods that may be imlemented by subclasses to take necessary steps at the beginning or end of code generation.

Reimplemented in t_py_generator, t_c_generator, t_cpp_generator, and t_xsd_generator.

Definition at line 97 of file t_generator.h.

static bool t_generator::is_valid_namespace ( const std::string &  sub_namespace)
inlinestatic

check whether sub-namespace declaraction is used by generator. e.g. allow namespace py.twisted bar to specify namespace to use when -gen py:twisted is specified. Will be called with subnamespace, i.e. is_valid_namespace("twisted") will be called for the above example.

Definition at line 76 of file t_generator.h.

std::string t_generator::lowercase ( std::string  in)
inlineprotected

Definition at line 208 of file t_generator.h.

std::string t_generator::tmp ( std::string  name)
inlineprotected

Creates a unique temporary variable name, which is just "name" with a number appended to it (i.e. name35)

Definition at line 160 of file t_generator.h.

std::string t_generator::underscore ( std::string  in)
inlineprotected

Transforms a camel case string to an equivalent one separated by underscores e.g. aMultiWord -> a_multi_word someName -> some_name CamelCase -> camel_case name -> name Name -> name

Definition at line 228 of file t_generator.h.

std::string t_generator::uppercase ( std::string  in)
inlineprotected

Definition at line 214 of file t_generator.h.

Member Data Documentation

std::map<char, std::string> t_generator::escape_
protected

Map of characters to escape in string literals.

Definition at line 306 of file t_generator.h.

int t_generator::indent_
private

Current code indentation level

Definition at line 312 of file t_generator.h.

std::string t_generator::out_dir_base_
protected

Output type-specifc directory name ("gen-*")

Definition at line 301 of file t_generator.h.

t_program* t_generator::program_
protected

The program being generated

Definition at line 276 of file t_generator.h.

std::string t_generator::program_name_
protected

Quick accessor for formatted program name that is currently being generated.

Definition at line 282 of file t_generator.h.

std::string t_generator::service_name_
protected

Quick accessor for formatted service name that is currently being generated.

Definition at line 288 of file t_generator.h.

int t_generator::tmp_
private

Temporary variable counter, for making unique variable names

Definition at line 317 of file t_generator.h.


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