Code to generate C + + language code
This feature is implemented by the T_cpp_generator class (defined and implemented in file t_cpp_generator.cc), directly inheriting to the T_oop_generator class (this class is the direct base class for all object-oriented language generator classes, encapsulating the object-oriented language builder for a total Some features and behavior), and T_oop_generator inherits from T_generator (described above), the following detailed analysis of how this class is generated in C + + language code files. This also starts with the Generate_program function described above, because this function is the total hub that controls the entire code generation.
The first execution is the constructor, which does some of the most basic initialization, one that passes the T_program object of the symbolic resource that owns the generated code to the parent class, and the second function initializes some bool variables based on the optional arguments so that they can be processed later according to the bool variables. The code is simply not listed, and the following table describes the function (or function) of each bool variable.
Gen_pure_enums_
Whether to generate pure enumeration types, rather than in the form of class wrappers
Gen_dense_
Whether the metadata should be reflected for tdenseprotocol cost.
Gen_templates_
Whether to generate a templated read/write method
Use_include_prefix_
Whether the prefix path should be used in #include for other header files generated by thrift
Gen_cob_style_
Whether the inheritance extension function class should be generated (primarily asynchronous)
Gen_no_client_completion_
Should the client class call COMPLETION__ () should be omitted
Constructors just do the most basic initialization, and more detailed initialization is the code generator initialization function described above, so let's take a look at how the C + + code generator is initialized in detail, what kind of work it does, and what it does to achieve something init_generator. Let's introduce this function in a step-by-step approach:
Step one: Make the output directory of the code file: MKDIR (Get_out_dir (). C_STR ()); mkdir is a macro function that invokes the mkdir to create a directory;
Part II: Create a Dock file and implementation file, if you need to generate a templated read and write method will also create a separate file implementation, the code is as follows:
String f_types_name = Get_out_dir () +program_name_+ "_types.h";
F_types_.open (F_types_name.c_str ());
String f_types_impl_name = Get_out_dir () +program_name_+ "_types.cpp";
F_types_impl_.open (F_types_impl_name.c_str ());
if (Gen_templates_) {
string f_types_tcc_name = Get_out_dir () +program_name_+ "_TYPES.TCC";
F_types_tcc_.open (F_types_tcc_name.c_str ());
}