OpenSDN source code
|
Public Member Functions | |
t_cpp_generator (t_program *program, const std::map< std::string, std::string > &parsed_options, const std::string &option_string) | |
void | init_generator () |
void | close_generator () |
void | generate_consts (std::vector< t_const * > consts) |
void | generate_typedef (t_typedef *ttypedef) |
void | generate_enum (t_enum *tenum) |
void | generate_struct (t_struct *tstruct) |
void | generate_xception (t_struct *txception) |
void | generate_cpp_struct (t_struct *tstruct, bool is_exception) |
void | generate_service (t_service *tservice) |
void | print_const_value (std::ofstream &out, std::string name, t_type *type, t_const_value *value) |
std::string | render_const_value (std::ofstream &out, std::string name, t_type *type, t_const_value *value) |
void | generate_struct_definition (std::ofstream &out, t_struct *tstruct, bool is_exception=false, bool pointers=false, bool read=true, bool write=true) |
void | generate_struct_fingerprint (std::ofstream &out, t_struct *tstruct, bool is_definition) |
void | generate_struct_reader (std::ofstream &out, t_struct *tstruct, bool pointers=false) |
void | generate_struct_writer (std::ofstream &out, t_struct *tstruct, bool pointers=false) |
void | generate_struct_result_writer (std::ofstream &out, t_struct *tstruct, bool pointers=false) |
void | generate_service_interface (t_service *tservice, string style) |
void | generate_service_interface_factory (t_service *tservice, string style) |
void | generate_service_null (t_service *tservice, string style) |
void | generate_service_multiface (t_service *tservice) |
void | generate_service_helpers (t_service *tservice) |
void | generate_service_client (t_service *tservice, string style) |
void | generate_service_processor (t_service *tservice, string style) |
void | generate_service_skeleton (t_service *tservice) |
void | generate_process_function (t_service *tservice, t_function *tfunction, string style, bool specialized=false) |
void | generate_function_helpers (t_service *tservice, t_function *tfunction) |
void | generate_service_async_skeleton (t_service *tservice) |
void | generate_deserialize_field (std::ofstream &out, t_field *tfield, std::string prefix="", std::string suffix="") |
void | generate_deserialize_struct (std::ofstream &out, t_struct *tstruct, std::string prefix="") |
void | generate_deserialize_container (std::ofstream &out, t_type *ttype, std::string prefix="") |
void | generate_deserialize_set_element (std::ofstream &out, t_set *tset, std::string prefix="") |
void | generate_deserialize_map_element (std::ofstream &out, t_map *tmap, std::string prefix="") |
void | generate_deserialize_list_element (std::ofstream &out, t_list *tlist, std::string prefix, bool push_back, std::string index) |
void | generate_serialize_field (std::ofstream &out, t_field *tfield, std::string prefix="", std::string suffix="") |
void | generate_serialize_struct (std::ofstream &out, t_struct *tstruct, std::string prefix="") |
void | generate_serialize_container (std::ofstream &out, t_type *ttype, std::string prefix="") |
void | generate_serialize_map_element (std::ofstream &out, t_map *tmap, std::string iter) |
void | generate_serialize_set_element (std::ofstream &out, t_set *tmap, std::string iter) |
void | generate_serialize_list_element (std::ofstream &out, t_list *tlist, std::string iter) |
void | generate_function_call (ostream &out, t_function *tfunction, string target, string iface, string arg_prefix) |
std::string | namespace_prefix (std::string ns) |
std::string | namespace_open (std::string ns) |
std::string | namespace_close (std::string ns) |
std::string | type_name (t_type *ttype, bool in_typedef=false, bool arg=false) |
std::string | base_type_name (t_base_type::t_base tbase) |
std::string | declare_field (t_field *tfield, bool init=false, bool pointer=false, bool constant=false, bool reference=false) |
std::string | function_signature (t_function *tfunction, std::string style, std::string prefix="", bool name_params=true) |
std::string | cob_function_signature (t_function *tfunction, std::string prefix="", bool name_params=true) |
std::string | argument_list (t_struct *tstruct, bool name_params=true, bool start_comma=false) |
std::string | type_to_enum (t_type *ttype) |
std::string | local_reflection_name (const char *, t_type *ttype, bool external=false) |
void | generate_enum_constant_list (std::ofstream &f, const vector< t_enum_value * > &constants, const char *prefix, const char *suffix, bool include_values) |
void | generate_local_reflection (std::ofstream &out, t_type *ttype, bool is_definition) |
void | generate_local_reflection_pointer (std::ofstream &out, t_type *ttype) |
bool | is_complex_type (t_type *ttype) |
void | set_use_include_prefix (bool use_include_prefix) |
![]() | |
t_oop_generator (t_program *program) | |
void | scope_up (std::ostream &out) |
void | scope_down (std::ostream &out) |
std::string | upcase_string (std::string original) |
virtual std::string | autogen_comment () |
![]() | |
t_generator (t_program *program) | |
virtual | ~t_generator () |
virtual void | generate_program () |
const t_program * | get_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) |
Private Member Functions | |
std::string | get_include_prefix (const t_program &program) const |
void | generate_common_struct_reader_body (std::ofstream &out, t_struct_common *tstruct, bool pointers=false) |
void | generate_common_struct_writer_body (std::ofstream &out, t_struct_common *tstruct, bool pointers=false) |
Private Attributes | |
bool | gen_pure_enums_ |
bool | gen_dense_ |
bool | gen_templates_ |
bool | use_include_prefix_ |
bool | gen_cob_style_ |
bool | gen_no_client_completion_ |
std::string | ns_open_ |
std::string | ns_close_ |
std::ofstream | f_types_ |
std::ofstream | f_types_impl_ |
std::ofstream | f_types_tcc_ |
std::ofstream | f_header_ |
std::ofstream | f_service_ |
std::ofstream | f_service_tcc_ |
std::set< std::string > | reflected_fingerprints_ |
Friends | |
class | ProcessorGenerator |
Additional Inherited Members | |
![]() | |
static bool | is_valid_namespace (const std::string &sub_namespace) |
static t_type * | get_true_type (t_type *type) |
![]() | |
virtual void | generate_const (t_const *tconst) |
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) |
![]() | |
t_program * | program_ |
std::string | program_name_ |
std::string | service_name_ |
std::string | out_dir_base_ |
std::map< char, std::string > | escape_ |
C++ code generator. This is legitimacy incarnate.
Definition at line 47 of file t_cpp_generator.cc.
|
inline |
Definition at line 49 of file t_cpp_generator.cc.
string t_cpp_generator::argument_list | ( | t_struct * | tstruct, |
bool | name_params = true , |
||
bool | start_comma = false |
||
) |
Renders a field list
tstruct | The struct definition |
Definition at line 8241 of file t_cpp_generator.cc.
string t_cpp_generator::base_type_name | ( | t_base_type::t_base | tbase | ) |
Returns the C++ type that corresponds to the thrift type.
tbase | The base type |
Definition at line 8027 of file t_cpp_generator.cc.
|
virtual |
Closes the output files.
Reimplemented from t_generator.
Definition at line 658 of file t_cpp_generator.cc.
std::string t_cpp_generator::cob_function_signature | ( | t_function * | tfunction, |
std::string | prefix = "" , |
||
bool | name_params = true |
||
) |
string t_cpp_generator::declare_field | ( | t_field * | tfield, |
bool | init = false , |
||
bool | pointer = false , |
||
bool | constant = false , |
||
bool | reference = false |
||
) |
Declares a field, which may include initialization as necessary.
ttype | The type |
Definition at line 8080 of file t_cpp_generator.cc.
string t_cpp_generator::function_signature | ( | t_function * | tfunction, |
std::string | style, | ||
std::string | prefix = "" , |
||
bool | name_params = true |
||
) |
Renders a function signature of the form 'type name(args)'
tfunction | Function definition |
Definition at line 8159 of file t_cpp_generator.cc.
|
private |
Makes a helper function to gen a generic body of sandesh and struct readers.
Definition at line 8397 of file t_cpp_generator.cc.
|
private |
Makes a helper function to gen a generic body of sandesh and struct writers.
Definition at line 8561 of file t_cpp_generator.cc.
|
virtual |
Generates a class that holds all the constants.
Reimplemented from t_generator.
Definition at line 801 of file t_cpp_generator.cc.
void t_cpp_generator::generate_cpp_struct | ( | t_struct * | tstruct, |
bool | is_exception | ||
) |
Generates a struct definition for a thrift data type. This is a class with data members and a read/write() function, plus a mirroring isset inner class.
tstruct | The struct definition |
Definition at line 1035 of file t_cpp_generator.cc.
void t_cpp_generator::generate_deserialize_container | ( | std::ofstream & | out, |
t_type * | ttype, | ||
std::string | prefix = "" |
||
) |
void t_cpp_generator::generate_deserialize_field | ( | std::ofstream & | out, |
t_field * | tfield, | ||
std::string | prefix = "" , |
||
std::string | suffix = "" |
||
) |
Serialization constructs
Deserializes a field of any type.
Definition at line 7166 of file t_cpp_generator.cc.
void t_cpp_generator::generate_deserialize_list_element | ( | std::ofstream & | out, |
t_list * | tlist, | ||
std::string | prefix, | ||
bool | push_back, | ||
std::string | index | ||
) |
void t_cpp_generator::generate_deserialize_map_element | ( | std::ofstream & | out, |
t_map * | tmap, | ||
std::string | prefix = "" |
||
) |
Generates code to deserialize a map
Definition at line 7432 of file t_cpp_generator.cc.
void t_cpp_generator::generate_deserialize_set_element | ( | std::ofstream & | out, |
t_set * | tset, | ||
std::string | prefix = "" |
||
) |
void t_cpp_generator::generate_deserialize_struct | ( | std::ofstream & | out, |
t_struct * | tstruct, | ||
std::string | prefix = "" |
||
) |
Generates an unserializer for a variable. This makes two key assumptions, first that there is a const char* variable named data that points to the buffer for deserialization, and that there is a variable protocol which is a reference to a TProtocol serialization object.
Definition at line 7275 of file t_cpp_generator.cc.
|
virtual |
Generates code for an enumerated type. In C++, this is essentially the same as the thrift definition itself, using the enum keyword in C++.
tenum | The enumeration |
Generate a character array of enum names for debugging purposes.
Implements t_generator.
Definition at line 745 of file t_cpp_generator.cc.
void t_cpp_generator::generate_enum_constant_list | ( | std::ofstream & | f, |
const vector< t_enum_value * > & | constants, | ||
const char * | prefix, | ||
const char * | suffix, | ||
bool | include_values | ||
) |
void t_cpp_generator::generate_function_call | ( | ostream & | out, |
t_function * | tfunction, | ||
string | target, | ||
string | iface, | ||
string | arg_prefix | ||
) |
void t_cpp_generator::generate_function_helpers | ( | t_service * | tservice, |
t_function * | tfunction | ||
) |
Generates a struct and helpers for a function.
tfunction | The function |
Definition at line 6492 of file t_cpp_generator.cc.
void t_cpp_generator::generate_local_reflection | ( | std::ofstream & | out, |
t_type * | ttype, | ||
bool | is_definition | ||
) |
Writes the local reflection of a type (either declaration or definition).
Definition at line 3262 of file t_cpp_generator.cc.
void t_cpp_generator::generate_local_reflection_pointer | ( | std::ofstream & | out, |
t_type * | ttype | ||
) |
Writes the structure's static pointer to its local reflection typespec into the implementation file.
Definition at line 3379 of file t_cpp_generator.cc.
void t_cpp_generator::generate_process_function | ( | t_service * | tservice, |
t_function * | tfunction, | ||
string | style, | ||
bool | specialized = false |
||
) |
Generates a process function definition.
tfunction | The function to write a dispatcher for |
Definition at line 6531 of file t_cpp_generator.cc.
void t_cpp_generator::generate_serialize_container | ( | std::ofstream & | out, |
t_type * | ttype, | ||
std::string | prefix = "" |
||
) |
void t_cpp_generator::generate_serialize_field | ( | std::ofstream & | out, |
t_field * | tfield, | ||
std::string | prefix = "" , |
||
std::string | suffix = "" |
||
) |
Serializes a field of any type.
tfield | The field to serialize |
prefix | Name to prepend to field name |
Definition at line 7528 of file t_cpp_generator.cc.
void t_cpp_generator::generate_serialize_list_element | ( | std::ofstream & | out, |
t_list * | tlist, | ||
std::string | iter | ||
) |
Serializes the members of a list.
Definition at line 7852 of file t_cpp_generator.cc.
void t_cpp_generator::generate_serialize_map_element | ( | std::ofstream & | out, |
t_map * | tmap, | ||
std::string | iter | ||
) |
Serializes the members of a map.
Definition at line 7792 of file t_cpp_generator.cc.
void t_cpp_generator::generate_serialize_set_element | ( | std::ofstream & | out, |
t_set * | tmap, | ||
std::string | iter | ||
) |
Serializes the members of a set.
Definition at line 7842 of file t_cpp_generator.cc.
void t_cpp_generator::generate_serialize_struct | ( | std::ofstream & | out, |
t_struct * | tstruct, | ||
std::string | prefix = "" |
||
) |
Serializes all the members of a struct.
tstruct | The struct to serialize |
prefix | String prefix to attach to all fields |
Definition at line 7663 of file t_cpp_generator.cc.
|
virtual |
Generates a thrift service. In C++, this comprises an entirely separate header and source file. The header file defines the methods and includes the data types defined in the main header file, and the implementation file contains implementations of the basic printer and default interfaces.
tservice | The service definition |
Implements t_generator.
Definition at line 4965 of file t_cpp_generator.cc.
void t_cpp_generator::generate_service_async_skeleton | ( | t_service * | tservice | ) |
void t_cpp_generator::generate_service_client | ( | t_service * | tservice, |
string | style | ||
) |
Generates a service client definition.
tservice | The service to generate a server for. |
Definition at line 5574 of file t_cpp_generator.cc.
void t_cpp_generator::generate_service_helpers | ( | t_service * | tservice | ) |
Generates helper functions for a service. Basically, this generates types for all the arguments and results to functions.
tservice | The service to generate a header definition for |
Definition at line 5108 of file t_cpp_generator.cc.
void t_cpp_generator::generate_service_interface | ( | t_service * | tservice, |
string | style | ||
) |
Service-level generation functions
Generates a service interface definition.
tservice | The service to generate a header definition for |
Definition at line 5136 of file t_cpp_generator.cc.
void t_cpp_generator::generate_service_interface_factory | ( | t_service * | tservice, |
string | style | ||
) |
Generates a service interface factory.
tservice | The service to generate an interface factory for. |
Definition at line 5199 of file t_cpp_generator.cc.
void t_cpp_generator::generate_service_multiface | ( | t_service * | tservice | ) |
Generates a multiface, which is a single server that just takes a set of objects implementing the interface and calls them all, returning the value of the last one to be called.
tservice | The service to generate a multiserver for. |
Definition at line 5451 of file t_cpp_generator.cc.
void t_cpp_generator::generate_service_null | ( | t_service * | tservice, |
string | style | ||
) |
Generates a null implementation of the service.
tservice | The service to generate a header definition for |
Definition at line 5288 of file t_cpp_generator.cc.
void t_cpp_generator::generate_service_processor | ( | t_service * | tservice, |
string | style | ||
) |
Generates a service processor definition.
tservice | The service to generate a processor for. |
Definition at line 6481 of file t_cpp_generator.cc.
void t_cpp_generator::generate_service_skeleton | ( | t_service * | tservice | ) |
Generates a skeleton file of a server
tservice | The service to generate a server for. |
Definition at line 7080 of file t_cpp_generator.cc.
|
inlinevirtual |
Implements t_generator.
Definition at line 94 of file t_cpp_generator.cc.
void t_cpp_generator::generate_struct_definition | ( | std::ofstream & | out, |
t_struct * | tstruct, | ||
bool | is_exception = false , |
||
bool | pointers = false , |
||
bool | read = true , |
||
bool | write = true |
||
) |
Writes the struct definition into the header file
out | Output stream |
tstruct | The struct |
Definition at line 2647 of file t_cpp_generator.cc.
void t_cpp_generator::generate_struct_fingerprint | ( | std::ofstream & | out, |
t_struct * | tstruct, | ||
bool | is_definition | ||
) |
Writes the fingerprint of a struct to either the header or implementation.
out | Output stream |
tstruct | The struct |
Definition at line 3229 of file t_cpp_generator.cc.
void t_cpp_generator::generate_struct_reader | ( | std::ofstream & | out, |
t_struct * | tstruct, | ||
bool | pointers = false |
||
) |
Makes a helper function to gen a struct reader.
out | Stream to write to |
tstruct | The struct |
Definition at line 3397 of file t_cpp_generator.cc.
void t_cpp_generator::generate_struct_result_writer | ( | std::ofstream & | out, |
t_struct * | tstruct, | ||
bool | pointers = false |
||
) |
Struct writer for result of a function, which can have only one of its fields set and does a conditional if else look up into the __isset field of the struct.
out | Output stream |
tstruct | The result struct |
Definition at line 4882 of file t_cpp_generator.cc.
void t_cpp_generator::generate_struct_writer | ( | std::ofstream & | out, |
t_struct * | tstruct, | ||
bool | pointers = false |
||
) |
Generates the write function.
out | Stream to write to |
tstruct | The struct |
Definition at line 3423 of file t_cpp_generator.cc.
|
virtual |
Program-level generation functions
Generates a typedef. This is just a simple 1-liner in C++
ttypedef | The type definition |
Implements t_generator.
Definition at line 704 of file t_cpp_generator.cc.
|
inlinevirtual |
Reimplemented from t_generator.
Definition at line 97 of file t_cpp_generator.cc.
|
private |
Returns the include prefix to use for a file generated by program, or the empty string if no include prefix should be used.
Definition at line 8381 of file t_cpp_generator.cc.
|
virtual |
Init and close methods
Prepares for file generation by opening up the necessary file output streams.
Reimplemented from t_generator.
Definition at line 479 of file t_cpp_generator.cc.
|
inline |
string t_cpp_generator::local_reflection_name | ( | const char * | prefix, |
t_type * | ttype, | ||
bool | external = false |
||
) |
Returns the symbol name of the local reflection of a type.
Definition at line 8341 of file t_cpp_generator.cc.
string t_cpp_generator::namespace_close | ( | std::string | ns | ) |
Closes namespace.
ns | The namespace, w/ periods in it |
Definition at line 7922 of file t_cpp_generator.cc.
string t_cpp_generator::namespace_open | ( | std::string | ns | ) |
Opens namespace.
ns | The namespace, w/ periods in it |
Definition at line 7895 of file t_cpp_generator.cc.
string t_cpp_generator::namespace_prefix | ( | std::string | ns | ) |
Makes a :: prefix for a namespace
ns | The namespace, w/ periods in it |
Definition at line 7865 of file t_cpp_generator.cc.
void t_cpp_generator::print_const_value | ( | std::ofstream & | out, |
std::string | name, | ||
t_type * | type, | ||
t_const_value * | value | ||
) |
Prints the value of a constant with the given type. Note that type checking is NOT performed in this function as it is always run beforehand using the validate_types method in main.cc
Definition at line 894 of file t_cpp_generator.cc.
string t_cpp_generator::render_const_value | ( | std::ofstream & | out, |
std::string | name, | ||
t_type * | type, | ||
t_const_value * | value | ||
) |
|
inline |
Definition at line 367 of file t_cpp_generator.cc.
string t_cpp_generator::type_name | ( | t_type * | ttype, |
bool | in_typedef = false , |
||
bool | arg = false |
||
) |
Returns a C++ type name
ttype | The type |
Definition at line 7942 of file t_cpp_generator.cc.
string t_cpp_generator::type_to_enum | ( | t_type * | type | ) |
Converts the parse type to a C++ enum string for the given type.
type | Thrift Type |
Definition at line 8265 of file t_cpp_generator.cc.
|
friend |
Definition at line 472 of file t_cpp_generator.cc.
|
private |
Definition at line 440 of file t_cpp_generator.cc.
|
private |
Definition at line 441 of file t_cpp_generator.cc.
|
private |
Definition at line 442 of file t_cpp_generator.cc.
|
private |
File streams, stored here to avoid passing them as parameters to every function.
Definition at line 437 of file t_cpp_generator.cc.
|
private |
Definition at line 438 of file t_cpp_generator.cc.
|
private |
Definition at line 439 of file t_cpp_generator.cc.
|
private |
True if we should generate "Continuation OBject"-style classes as well.
Definition at line 418 of file t_cpp_generator.cc.
|
private |
True if we should generate local reflection metadata for TDenseProtocol.
Definition at line 402 of file t_cpp_generator.cc.
|
private |
True if we should omit calls to completion__() in CobClient class.
Definition at line 423 of file t_cpp_generator.cc.
|
private |
True if we should generate pure enums for Thrift enums, instead of wrapper classes.
Definition at line 397 of file t_cpp_generator.cc.
|
private |
True if we should generate templatized reader/writer methods.
Definition at line 407 of file t_cpp_generator.cc.
|
private |
Definition at line 430 of file t_cpp_generator.cc.
|
private |
Strings for namespace, computed once up front then used directly
Definition at line 429 of file t_cpp_generator.cc.
|
private |
When generating local reflections, make sure we don't generate duplicates.
Definition at line 464 of file t_cpp_generator.cc.
|
private |
True if we should use a path prefix in our #include statements for other thrift-generated header files.
Definition at line 413 of file t_cpp_generator.cc.