@@ -316,7 +316,9 @@ class t_yarp_generator : public t_oop_generator
316316 void generate_struct_read_connectionreader (t_struct* tstruct, std::ostringstream& f_h_, std::ostringstream& f_cpp_);
317317 void generate_struct_write_wirereader (t_struct* tstruct, std::ostringstream& f_h_, std::ostringstream& f_cpp_);
318318 void generate_struct_write_connectionreader (t_struct* tstruct, std::ostringstream& f_h_, std::ostringstream& f_cpp_);
319+ void generate_struct_typeconstexpr (t_struct* tstruct, std::ostringstream& f_h_, const std::string& type, const std::string& version);
319320 void generate_struct_tostring (t_struct* tstruct, std::ostringstream& f_h_, std::ostringstream& f_cpp_);
321+ void generate_struct_gettype (t_struct* tstruct, std::ostringstream& f_h_, std::ostringstream& f_cpp_);
320322 void generate_struct_unwrapped_helper (t_struct* tstruct, std::ostringstream& f_h_, std::ostringstream& f_cpp_);
321323 void generate_struct_editor (t_struct* tstruct, std::ostringstream& f_h_, std::ostringstream& f_cpp_);
322324 void generate_struct_editor_default_constructor (t_struct* tstruct, std::ostringstream& f_h_, std::ostringstream& f_cpp_);
@@ -1842,12 +1844,18 @@ void t_yarp_generator::generate_struct(t_struct* tstruct)
18421844
18431845 std::string yarp_type_name{};
18441846 if (annotations.find (" yarp.type.name" ) != annotations.end ()) {
1845- yarp_api_keyword = annotations.at (" yarp.type.name" );
1847+ yarp_type_name = annotations.at (" yarp.type.name" );
1848+ }
1849+ else {
1850+ yarp_type_name = " yarp/" +name;
18461851 }
18471852
18481853 std::string yarp_type_version{};
18491854 if (annotations.find (" yarp.type.version" ) != annotations.end ()) {
1850- yarp_api_keyword = annotations.at (" yarp.type.version" );
1855+ yarp_type_version = annotations.at (" yarp.type.version" );
1856+ }
1857+ else {
1858+ yarp_type_version = " 1.0" ;
18511859 }
18521860
18531861 // Open header file
@@ -1884,6 +1892,7 @@ void t_yarp_generator::generate_struct(t_struct* tstruct)
18841892
18851893 f_h_ << " #include <yarp/os/Wire.h>\n " ;
18861894 f_h_ << " #include <yarp/os/idl/WireTypes.h>\n " ;
1895+ f_h_ << " #include <yarp/os/Type.h>\n " ;
18871896 if (need_common_) {
18881897 f_h_ << ' \n ' ;
18891898 f_h_ << " #include <" << get_include_prefix (program_) << program_->get_name () << " _common.h>" << ' \n ' ;
@@ -1925,7 +1934,9 @@ void t_yarp_generator::generate_struct(t_struct* tstruct)
19251934 generate_struct_read_connectionreader (tstruct, f_h_, f_cpp_);
19261935 generate_struct_write_wirereader (tstruct, f_h_, f_cpp_);
19271936 generate_struct_write_connectionreader (tstruct, f_h_, f_cpp_);
1937+ generate_struct_typeconstexpr (tstruct, f_h_, yarp_type_name, yarp_type_version);
19281938 generate_struct_tostring (tstruct, f_h_, f_cpp_);
1939+ generate_struct_gettype (tstruct, f_h_, f_cpp_);
19291940 generate_struct_unwrapped_helper (tstruct, f_h_, f_cpp_);
19301941
19311942 // Add editor class, if not disabled
@@ -2228,6 +2239,48 @@ void t_yarp_generator::generate_struct_tostring(t_struct* tstruct, std::ostrings
22282239 assert (indent_count_cpp () == 0 );
22292240}
22302241
2242+ void t_yarp_generator::generate_struct_typeconstexpr (t_struct* tstruct, std::ostringstream& f_h_, const std::string& yarp_type_name, const std::string& yarp_type_version)
2243+ {
2244+ THRIFT_DEBUG_COMMENT (f_h_);
2245+
2246+ const auto & name = tstruct->get_name ();
2247+
2248+ f_h_ << indent_h () << " //The name and the version for this message\n " ;
2249+ f_h_ << indent_h () << " static constexpr const char* typeName = \" " << yarp_type_name << " \" ;\n " ;
2250+ f_h_ << indent_h () << " static constexpr const char* typeVersion = \" " << " 1.0" << " \" ;\n " ;
2251+ f_h_ << ' \n ' ;
2252+
2253+ assert (indent_count_h () == 1 );
2254+ }
2255+
2256+ void t_yarp_generator::generate_struct_gettype (t_struct* tstruct, std::ostringstream& f_h_, std::ostringstream& f_cpp_)
2257+ {
2258+ THRIFT_DEBUG_COMMENT (f_h_);
2259+ THRIFT_DEBUG_COMMENT (f_cpp_);
2260+
2261+ const auto & name = tstruct->get_name ();
2262+
2263+ f_h_ << indent_h () << " // Get the message type\n " ;
2264+ f_h_ << indent_h () << " yarp::os::Type getType() const;\n " ;
2265+ f_h_ << ' \n ' ;
2266+
2267+ f_cpp_ << indent_cpp () << " // Convert to a printable string\n " ;
2268+ f_cpp_ << indent_cpp () << " yarp::os::Type " << name << " ::getType() const\n " ;
2269+ f_cpp_ << indent_cpp () << " {\n " ;
2270+ indent_up_cpp ();
2271+ {
2272+ f_cpp_ << indent_cpp () << " yarp::os::Type typ = yarp::os::Type::byNameOnWire(typeName);\n " ;
2273+ f_cpp_ << indent_cpp () << " typ.setVersion(typeVersion);\n " ;
2274+ f_cpp_ << indent_cpp () << " return typ;\n " ;
2275+ }
2276+ indent_down_cpp ();
2277+ f_cpp_ << indent_cpp () << " }\n " ;
2278+ f_cpp_ << ' \n ' ;
2279+
2280+ assert (indent_count_h () == 1 );
2281+ assert (indent_count_cpp () == 0 );
2282+ }
2283+
22312284void t_yarp_generator::generate_struct_unwrapped_helper (t_struct* tstruct, std::ostringstream& f_h_, std::ostringstream& f_cpp_)
22322285{
22332286 THRIFT_DEBUG_COMMENT (f_h_);
0 commit comments