GeneratorBase::GenerateGettersAndSetters Struct Reference

List of all members.

Public Member Functions

 GenerateGettersAndSetters (AST_Union *u, AST_Type *d)
void operator() (AST_UnionBranch *branch)

Public Attributes

AST_Union * the_union
AST_Type * discriminator

Detailed Description

Definition at line 202 of file langmap_generator.cpp.


Constructor & Destructor Documentation

GeneratorBase::GenerateGettersAndSetters::GenerateGettersAndSetters ( AST_Union *  u,
AST_Type *  d 
) [inline]

Definition at line 207 of file langmap_generator.cpp.

00208       : the_union(u)
00209       , discriminator(d)
00210     { }


Member Function Documentation

void GeneratorBase::GenerateGettersAndSetters::operator() ( AST_UnionBranch *  branch  )  [inline]

Definition at line 212 of file langmap_generator.cpp.

References be_global, AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_ENUM, AstTypeClassification::CL_FIXED, AstTypeClassification::CL_PRIMITIVE, AstTypeClassification::CL_SEQUENCE, AstTypeClassification::CL_STRING, AstTypeClassification::CL_STRUCTURE, AstTypeClassification::CL_UNION, AstTypeClassification::CL_WIDE, AstTypeClassification::classify(), discriminator, GeneratorBase::generateDefaultValue(), getEnumLabel(), helpers_, HLP_STR_VAR, HLP_WSTR_VAR, BE_GlobalData::lang_header_, map_type(), primtype_, AstTypeClassification::resolveActualType(), and the_union.

00213     {
00214       const char* field_name = branch->local_name()->get_string();
00215       std::stringstream first_label;
00216       {
00217         AST_UnionLabel* label = branch->label(0);
00218         if (label->label_kind() == AST_UnionLabel::UL_default) {
00219           first_label << generateDefaultValue(the_union, discriminator);
00220         } else if (discriminator->node_type() == AST_Decl::NT_enum) {
00221           first_label << getEnumLabel(label->label_val(), discriminator);
00222         } else {
00223           first_label << *label->label_val()->ev();
00224         }
00225       }
00226 
00227       AST_Type* field_type = branch->field_type();
00228       const std::string field_type_string = map_type(field_type);
00229       AST_Type* actual_field_type = resolveActualType(field_type);
00230       const Classification cls = classify(actual_field_type);
00231       if (cls & (CL_PRIMITIVE | CL_ENUM)) {
00232         be_global->lang_header_ <<
00233           "  void " << field_name << " (" << field_type_string << " x) {\n"
00234           "    _reset();\n"
00235           "    this->_u." << field_name << " = x;\n"
00236           "    _discriminator = " << first_label.str() << ";\n"
00237           "  }\n"
00238           "  " << field_type_string << ' ' << field_name << " () const {\n"
00239           "    return this->_u." << field_name << ";\n"
00240           "  }\n";
00241       } else if (cls & CL_STRING) {
00242         const std::string& primtype = (cls & CL_WIDE) ? primtype_[AST_PredefinedType::PT_wchar] : primtype_[AST_PredefinedType::PT_char];
00243         const std::string& helper = (cls & CL_WIDE) ? helpers_[HLP_WSTR_VAR] : helpers_[HLP_STR_VAR];
00244         be_global->lang_header_ <<
00245           "  void " << field_name << " (" << primtype << "* x) {\n"
00246           "    _reset();\n" <<
00247           "    this->_u." << field_name << " = x;\n"
00248           "    _discriminator = " << first_label.str() << ";\n"
00249           "  }\n"
00250           "  void " << field_name << " (const " << primtype << "* x) {\n"
00251           "    _reset();\n"
00252           "    this->_u." << field_name << " = ::CORBA::string_dup(x);\n"
00253           "    _discriminator = " << first_label.str() << ";\n"
00254           "  }\n"
00255           "  void " << field_name << " (const " << helper << "& x) {\n"
00256           "    _reset();\n" <<
00257           "    this->_u." << field_name << " = ::CORBA::string_dup(x.in());\n"
00258           "    _discriminator = " << first_label.str() << ";\n"
00259           "  }\n"
00260           "  const " << primtype << "* " << field_name << " () const {\n"
00261           "    return this->_u." << field_name << ";\n"
00262           "  }\n";
00263       } else if (cls & CL_ARRAY) {
00264         be_global->lang_header_ <<
00265           "  void " << field_name << " (" << field_type_string << " x) {\n"
00266           "    _reset();\n" <<
00267           "    this->_u." << field_name << " = " << field_type_string << "_dup(x);\n"
00268           "    _discriminator = " << first_label.str() << ";\n"
00269           "  }\n"
00270           "  " << field_type_string << "_slice* " << field_name << " () const {\n"
00271           "    return this->_u." << field_name << ";\n"
00272           "  }\n";
00273       } else if (cls & (CL_STRUCTURE | CL_UNION | CL_SEQUENCE | CL_FIXED)) {
00274         be_global->lang_header_ <<
00275           "  void " << field_name << " (const " << field_type_string << "& x) {\n"
00276           "    _reset();\n"
00277           "    this->_u." << field_name << " = new " << field_type_string << "(x);\n"
00278           "    _discriminator = " << first_label.str() << ";\n"
00279           "  }\n"
00280           "  const " << field_type_string << "& " << field_name << " () const {\n"
00281           "    return *this->_u." << field_name << ";\n"
00282           "  }\n"
00283           "  " << field_type_string << "& " << field_name << " () {\n"
00284           "    return *this->_u." << field_name << ";\n"
00285           "  }\n";
00286       } else {
00287         std::cerr << "Unsupported type for union element\n";
00288       }
00289     }


Member Data Documentation

AST_Type* GeneratorBase::GenerateGettersAndSetters::discriminator

Definition at line 205 of file langmap_generator.cpp.

Referenced by operator()().

AST_Union* GeneratorBase::GenerateGettersAndSetters::the_union

Definition at line 204 of file langmap_generator.cpp.

Referenced by operator()().


The documentation for this struct was generated from the following file:
Generated on Fri Feb 12 20:05:56 2016 for OpenDDS by  doxygen 1.4.7