5 #ifndef LODESTAR_PROTOMESSAGEBUILDER_HPP
6 #define LODESTAR_PROTOMESSAGEBUILDER_HPP
8 #include <Lodestar/blocks/Signal.hpp>
9 #include <Lodestar/aux/AlwaysFalse.hpp>
10 #include <Lodestar/io/proto/ProtoMessageType.hpp>
13 #include <ersatz/Codegen.hpp>
14 #include <Eigen/Dense>
20 ProtoMessageType type;
23 template<
typename TType>
28 template<
typename TType>
37 return {ProtoMessageType::bool_t};
40 static void defineMessage(::std::stringstream &ss)
42 ss << fmt::format(
"message {} {{\n",
"bool_m");
43 ss <<
" required bool value = 1;\n";
47 static void defineOptions(::std::stringstream &ss)
50 static void defineHeader(::std::stringstream &ss)
52 ss <<
"syntax = \"proto2\";\n\n";
53 ss <<
"package ls.proto;\n\n";
57 template<
typename TScalar,
int NRows,
int NCols>
60 static_assert((NRows >= 0) && (NCols >= 0),
"Matrix may not be dynamically sized.");
64 return {ProtoMessageType::bool_t};
67 inline static ::std::string getFileName()
69 return fmt::format(
"ls.proto.{}", getName());
72 inline static ::std::string getProtoFileName()
74 return fmt::format(
"{}.proto", getFileName());
77 inline static ::std::string getOptionsFileName()
79 return fmt::format(
"{}.options", getFileName());
82 static ::std::string getScalarName()
84 if (::std::is_same<TScalar, double>::value)
86 if (::std::is_same<TScalar, float>::value)
88 if (::std::is_same<TScalar, int32_t>::value)
90 if (::std::is_same<TScalar, uint32_t>::value)
94 static ::std::string getShortScalarName()
96 if (::std::is_same<TScalar, double>::value)
98 if (::std::is_same<TScalar, float>::value)
100 if (::std::is_same<TScalar, int32_t>::value)
102 if (::std::is_same<TScalar, uint32_t>::value)
106 inline static ::std::string getName()
108 return fmt::format(
"Matrix{}{}x{}", getShortScalarName(), NRows, NCols);
111 inline static ::std::string getMessageName()
113 return fmt::format(
"{}_m", getName());
116 inline static ::std::string getMessageTypeName()
118 return fmt::format(
"{}_t", getName());
121 static void defineMessage(::std::stringstream &ss)
123 ss << fmt::format(
"message {} {{\n", getMessageName());
124 ss << fmt::format(
" repeated {} coeff = 1;\n", getScalarName());
128 static void defineOptions(::std::stringstream &ss)
130 ss << fmt::format(
"{}.coeff max_size:{}", getMessageName(), NRows*NCols);
133 static void defineHeader(::std::stringstream &ss)
135 ss <<
"syntax = \"proto2\";\n\n";
136 ss <<
"package ls.proto;\n\n";
144 #endif //LODESTAR_PROTOMESSAGEBUILDER_HPP