#include <keys_generator.h>
Inheritance diagram for keys_generator:
Public Member Functions | |
bool | gen_struct (AST_Structure *node, UTL_ScopedName *name, const std::vector< AST_Field * > &fields, AST_Type::SIZE_TYPE size, const char *repoid) |
bool | gen_typedef (AST_Typedef *, UTL_ScopedName *, AST_Type *, const char *) |
bool | gen_union (AST_Union *, UTL_ScopedName *, const std::vector< AST_UnionBranch * > &, AST_Type *, const char *) |
Definition at line 13 of file keys_generator.h.
bool keys_generator::gen_struct | ( | AST_Structure * | node, | |
UTL_ScopedName * | name, | |||
const std::vector< AST_Field * > & | fields, | |||
AST_Type::SIZE_TYPE | size, | |||
const char * | repoid | |||
) | [virtual] |
Implements dds_generator.
Definition at line 16 of file keys_generator.cpp.
References Function::addArg(), be_global, Function::endArgs(), BE_GlobalData::export_macro(), BE_GlobalData::header_, BE_GlobalData::impl_, scoped(), and dds_generator::scoped_helper().
00018 { 00019 string cxx = scoped(name), under = scoped_helper(name, "_"); 00020 IDL_GlobalData::DCPS_Data_Type_Info* info = idl_global->is_dcps_type(name); 00021 if (!info) { 00022 return true; 00023 } 00024 00025 const bool empty = info->key_list_.is_empty(); 00026 { 00027 NamespaceGuard ng; 00028 Function has_key("gen_has_key", "bool"); 00029 has_key.addArg("", "const " + cxx + "&"); 00030 has_key.endArgs(); 00031 be_global->impl_ << " return " << (empty ? "false" : "true") << ";\n"; 00032 } 00033 00034 struct Namespaces { 00035 size_t n_; 00036 Namespaces(UTL_ScopedName* name) 00037 : n_(0) 00038 { 00039 for (UTL_ScopedName* sn = name; sn && sn->tail(); 00040 sn = static_cast<UTL_ScopedName*>(sn->tail())) { 00041 string str = sn->head()->get_string(); 00042 if (str.size()) { 00043 be_global->header_ << "namespace " << str << " {\n"; 00044 ++n_; 00045 } 00046 } 00047 } 00048 ~Namespaces() 00049 { 00050 for (size_t i = 0; i < n_; ++i) be_global->header_ << "}\n"; 00051 } 00052 } ns(name); 00053 00054 be_global->header_ << 00055 "namespace OpenDDSGenerated {\n" 00056 "// This structure supports use of std::map with a key\n" 00057 "// defined by one or more #pragma DCPS_DATA_KEY lines.\n" 00058 "struct " << be_global->export_macro() << ' ' << 00059 name->last_component()->get_string() << "_KeyLessThan {\n" 00060 " bool operator()(const " << cxx << "& v1, const " << cxx 00061 << "& v2) const\n" 00062 " {\n" 00063 " using ::operator<; // TAO::String_Manager's operator< is " 00064 "in global NS\n"; 00065 00066 if (empty) { 00067 be_global->header_ << 00068 " ACE_UNUSED_ARG(v1);\n" 00069 " ACE_UNUSED_ARG(v2);\n" 00070 " // with no DCPS_DATA_KEYs, return false\n" 00071 " // to allow use of map with just one entry\n" 00072 " return false;\n" 00073 " }\n" 00074 "};\n" 00075 "}\n"; 00076 return true; 00077 } 00078 00079 IDL_GlobalData::DCPS_Data_Type_Info_Iter iter(info->key_list_); 00080 00081 for (ACE_TString* kp = 0; iter.next(kp) != 0; iter.advance()) { 00082 string fname = ACE_TEXT_ALWAYS_CHAR(kp->c_str()); 00083 be_global->header_ << 00084 " if (v1." << fname << " < v2." << fname << ") return true;\n" 00085 " if (v2." << fname << " < v1." << fname << ") return false;\n"; 00086 } 00087 be_global->header_ << 00088 " return false;\n" 00089 " }\n};\n}\n"; 00090 return true; 00091 }
bool keys_generator::gen_typedef | ( | AST_Typedef * | , | |
UTL_ScopedName * | , | |||
AST_Type * | , | |||
const char * | ||||
) | [inline, virtual] |
bool keys_generator::gen_union | ( | AST_Union * | , | |
UTL_ScopedName * | , | |||
const std::vector< AST_UnionBranch * > & | , | |||
AST_Type * | , | |||
const char * | ||||
) | [inline, virtual] |