Skip to content

Commit 305c953

Browse files
committed
Compile code in Windows
Signed-off-by: Yangbo Long <[email protected]>
1 parent 0e89724 commit 305c953

File tree

4 files changed

+761
-867
lines changed

4 files changed

+761
-867
lines changed

examples/cpp/dds/IdlParserExample/IdlParser_main.cpp

Lines changed: 100 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -34,164 +34,120 @@ int main(
3434
Log::SetVerbosity(Log::Kind::Info);
3535
Log::SetCategoryFilter(std::regex("IDLPARSER"));
3636

37-
std::cout << "Processing forward declarations:" << std::endl;
38-
std::string test00 =
39-
R"(
40-
struct StructDcl;
41-
union UnionDcl;
42-
)";
43-
DynamicType::_ref_type fwd_dcl_type = DynamicTypeBuilderFactory::get_instance()->create_type_w_idl(test00)->build();
44-
if (nullptr != fwd_dcl_type)
45-
{
46-
EPROSIMA_LOG_INFO(IDLPARSER, "Succeeded to create DynamicType from IDL: " << test00);
47-
}
48-
else
49-
{
50-
EPROSIMA_LOG_ERROR(IDLPARSER, "Failed to create DynamicType from IDL: " << test00);
51-
}
52-
53-
std::cout << "Processing literals, expressions, and consts:" << std::endl;
54-
std::string test01 =
55-
R"(
56-
// boolean literals in IDL are case sensitive and should be exactly TRUE or FALSE
57-
const boolean C_BOOL = TRUE;
58-
const string<100> C_STR = "hello";
59-
const int32 C_LITERALS1 = (0x5 | (4 + 3)) + (4 << 1) * 2; // 23
60-
const int32 C_LITERALS2 = (02 + 0x1) * 2; // 6
61-
const int32 C_LITERALS3 = 4 / ( 07 & 0x2 ); // 2
62-
const int32 C_LITERALS4 = -(5 * ( 03 + 0xF )); // -90
63-
const int32 C_LITERALS5 = 0xf0 & ~(4 * ( 0x7 - 02 )); // 224
64-
const int32 C_LITERALS6 = (0x7 | 0x9) & ~(6 * ( 024 - 5 )); // 5
65-
const float C_LITERALS7 = (2 + 4) / 3.0d; /* 2.0 */
66-
const float C_LITERALS8 = (2e0 + 4) / 3.0d; /* 2.0 */
67-
)";
68-
DynamicTypeBuilder::_ref_type literal_type = DynamicTypeBuilderFactory::get_instance()->create_type_w_idl(test01);
69-
70-
// std::cout << "Processing IDL string:" << std::endl;
71-
// std::string test02 =
72-
// R"(
73-
// struct InnerType
74-
// {
75-
// uint32 im1;
76-
// float im2;
77-
// };
78-
// )";
79-
// idl::Context context02 = idl::parse(test02);
80-
81-
// std::cout << "Processing IDL file:" << std::endl;
82-
// idl::Context context03 = idl::parse_file("idl/test02.idl");
83-
84-
// std::string test04 =
85-
// R"(
86-
// enum e_test { a, b, c };
87-
// )";
88-
// idl::Context context04 = idl::parse(test04);
89-
90-
// std::string test05 =
91-
// R"(
92-
// struct Test05
93-
// {
94-
// long my_long;
95-
// short my_short;
96-
// long long my_llong;
97-
// int32 my_int;
98-
// unsigned short my_ushort;
99-
// unsigned long my_ulong;
100-
// long double my_ldouble;
101-
// float my_float;
102-
// double my_double;
103-
// };
104-
// )";
105-
// idl::Context context05 = idl::parse(test05);
106-
107-
// std::string test06 =
108-
// R"(
109-
// struct Point {
110-
// float x;
111-
// float y;
112-
// float z;
113-
// };
114-
// typedef Point PointAlias;
115-
// typedef Point PointArrayOf10[ 10 /**/];
116-
// typedef PointAlias TwoDimPointArray[5][3];
117-
// )";
118-
// idl::Context context06 = idl::parse(test06);
37+
std::cout << "Processing forward declarations:" << std::endl;
38+
std::string test00 =
39+
R"(
40+
struct StructDcl;
41+
union UnionDcl;
42+
)";
43+
DynamicType::_ref_type fwd_dcl_type = DynamicTypeBuilderFactory::get_instance()->create_type_w_idl(test00)->build();
44+
if (nullptr != fwd_dcl_type)
45+
{
46+
EPROSIMA_LOG_INFO(IDLPARSER, "Succeeded to create DynamicType from IDL: " << test00);
47+
}
48+
else
49+
{
50+
EPROSIMA_LOG_ERROR(IDLPARSER, "Failed to create DynamicType from IDL: " << test00);
51+
}
11952

120-
// std::string test07 =
121-
// R"(
122-
// union MyUnion switch (int32) {
123-
// case 0:
124-
// case 1:
125-
// long myLong;
126-
// case 2:
127-
// double myDouble;
128-
// default:
129-
// char myChar;
130-
// };
131-
// )";
132-
// idl::Context context07 = idl::parse(test07);
53+
std::cout << "Processing literals, expressions, and consts:" << std::endl;
54+
std::string test01 =
55+
R"(
56+
// boolean literals in IDL are case sensitive and should be exactly TRUE or FALSE
57+
const boolean C_BOOL = TRUE;
58+
const string<100> C_STR = "hello";
59+
const int32 C_LITERALS1 = (0x5 | (4 + 3)) + (4 << 1) * 2; // 23
60+
const int32 C_LITERALS2 = (02 + 0x1) * 2; // 6
61+
const int32 C_LITERALS3 = 4 / ( 07 & 0x2 ); // 2
62+
const int32 C_LITERALS4 = -(5 * ( 03 + 0xF )); // -90
63+
const int32 C_LITERALS5 = 0xf0 & ~(4 * ( 0x7 - 02 )); // 224
64+
const int32 C_LITERALS6 = (0x7 | 0x9) & ~(6 * ( 024 - 5 )); // 5
65+
const float C_LITERALS7 = (2 + 4) / 3.0d; /* 2.0 */
66+
const float C_LITERALS8 = (2e0 + 4) / 3.0d; /* 2.0 */
67+
)";
68+
DynamicTypeBuilder::_ref_type null_builder = DynamicTypeBuilderFactory::get_instance()->create_type_w_idl(test01);
13369

134-
std::string idl_spec =
70+
std::string test02 =
13571
R"(
136-
struct InnerType
72+
struct Test02
13773
{
138-
uint32 im1;
139-
float im2;
74+
long my_long;
75+
short my_short;
76+
long long my_llong;
77+
int32 my_int;
78+
unsigned short my_ushort;
79+
unsigned long my_ulong;
80+
long double my_ldouble;
81+
float my_float;
82+
double my_double;
14083
};
14184
)";
142-
143-
DynamicType::_ref_type inner_type = DynamicTypeBuilderFactory::get_instance()->create_type_w_idl(idl_spec)->build();
144-
if (nullptr != inner_type)
85+
DynamicType::_ref_type struct_type = DynamicTypeBuilderFactory::get_instance()->create_type_w_idl(test02)->build();
86+
if (nullptr != struct_type)
14587
{
146-
EPROSIMA_LOG_INFO(IDLPARSER, "Succeeded to create DynamicType from IDL: " << idl_spec);
88+
EPROSIMA_LOG_INFO(IDLPARSER, "Succeeded to create DynamicType from IDL: " << test02);
14789
}
14890
else
14991
{
150-
EPROSIMA_LOG_ERROR(IDLPARSER, "Failed to create DynamicType from IDL: " << idl_spec);
92+
EPROSIMA_LOG_ERROR(IDLPARSER, "Failed to create DynamicType from IDL: " << test02);
15193
}
15294

153-
// idl::Context context = idl::parse(idl_spec);
154-
// v1_3::DynamicType inner = context.module().structure("InnerType");
155-
156-
// v1_3::DynamicTypeBuilderFactory& factory = v1_3::DynamicTypeBuilderFactory::get_instance();
157-
// v1_3::DynamicTypeBuilder_ptr builder = factory.create_struct_type();
158-
// builder->set_name("OuterType");
159-
// builder->add_member(0, "om1", factory.get_string_type());
160-
// auto outer = builder->build();
161-
162-
// idl::Module root;
163-
// idl::Module& submod_a = root.create_submodule("a");
164-
// idl::Module& submod_b = root.create_submodule("b");
165-
// idl::Module& submod_aa = submod_a.create_submodule("a");
166-
// submod_aa.structure(std::move(const_cast<v1_3::DynamicType&>(*outer)));
167-
// submod_b.structure(inner);
168-
// /*
169-
// root
170-
// \_a
171-
// | \_ a _ OuterType
172-
// |
173-
// \_ b _ InnerType
174-
// */
175-
// std::cout << std::boolalpha;
176-
// std::cout << "Does a::a::OuterType exists?: " << root.has_structure("a::a::OuterType") << std::endl;
177-
// std::cout << "Does ::InnerType exists?: " << root.has_structure("::InnerType") << std::endl;
178-
// std::cout << "Does InnerType exists?: " << root.has_structure("InnerType") << std::endl;
179-
// std::cout << "Does OuterType exists?: " << root.has_structure("OuterType") << std::endl;
180-
// std::cout << "Does ::b::InnerType exists?: " << root.has_structure("::b::InnerType") << std::endl;
181-
// std::cout << "Does b::InnerType exists?: " << root.has_structure("b::InnerType") << std::endl;
95+
std::string test03 =
96+
R"(
97+
enum e_test { a, b, c };
98+
)";
99+
DynamicType::_ref_type enum_type = DynamicTypeBuilderFactory::get_instance()->create_type_w_idl(test03)->build();
100+
if (nullptr != enum_type)
101+
{
102+
EPROSIMA_LOG_INFO(IDLPARSER, "Succeeded to create DynamicType from IDL: " << test03);
103+
}
104+
else
105+
{
106+
EPROSIMA_LOG_ERROR(IDLPARSER, "Failed to create DynamicType from IDL: " << test03);
107+
}
182108

183-
// v1_3::DynamicData* outer_data = v1_3::DynamicDataFactory::get_instance()->create_data(
184-
// std::make_shared<v1_3::DynamicType>(root["a"]["a"].structure("OuterType"))
185-
// ); // ::a::a::OuterType
186-
// v1_3::MemberId member_id = outer_data->get_member_id_by_name("om1");
187-
// outer_data->set_string_value("This is a string.", member_id);
109+
std::string test04 =
110+
R"(
111+
struct Point {
112+
float x;
113+
float y;
114+
float z;
115+
};
116+
typedef Point PointAlias;
117+
typedef Point PointArrayOf10[ 10 /**/];
118+
typedef PointAlias TwoDimPointArray[5][3];
119+
)";
120+
DynamicType::_ref_type alias_type = DynamicTypeBuilderFactory::get_instance()->create_type_w_idl(test04)->build();
121+
if (nullptr != alias_type)
122+
{
123+
EPROSIMA_LOG_INFO(IDLPARSER, "Succeeded to create DynamicType from IDL: " << test04);
124+
}
125+
else
126+
{
127+
EPROSIMA_LOG_ERROR(IDLPARSER, "Failed to create DynamicType from IDL: " << test04);
128+
}
188129

189-
// std::string scope_inner_type = inner.get_name(); // b::InnerType
190-
// v1_3::DynamicData* inner_data = v1_3::DynamicDataFactory::get_instance()->create_data(
191-
// std::make_shared<v1_3::DynamicType>(root.structure(scope_inner_type))
192-
// );
193-
// inner_data->set_uint32_value(32u, inner_data->get_member_id_by_name("im1"));
194-
// inner_data->set_float32_value(3.14159265f, inner_data->get_member_id_by_name("im2"));
130+
std::string test05 =
131+
R"(
132+
union MyUnion switch (int32) {
133+
case 0:
134+
case 1:
135+
long myLong;
136+
case 2:
137+
double myDouble;
138+
default:
139+
char myChar;
140+
};
141+
)";
142+
DynamicType::_ref_type union_type = DynamicTypeBuilderFactory::get_instance()->create_type_w_idl(test05)->build();
143+
if (nullptr != union_type)
144+
{
145+
EPROSIMA_LOG_INFO(IDLPARSER, "Succeeded to create DynamicType from IDL: " << test05);
146+
}
147+
else
148+
{
149+
EPROSIMA_LOG_ERROR(IDLPARSER, "Failed to create DynamicType from IDL: " << test05);
150+
}
195151

196152
Log::Flush();
197153
Log::Reset();

0 commit comments

Comments
 (0)