|
1025 | 1025 | /// }; |
1026 | 1026 | /// @endcode |
1027 | 1027 | /// |
| 1028 | +/// @section page_define_prot_field_aliases Aliases to Field Names |
| 1029 | +/// When the communication protocol evolves and new versions of it are being released, |
| 1030 | +/// it may happen that some fields get renamed to give them a different or refined |
| 1031 | +/// meaning. Simple change of the name may result in old client code not being |
| 1032 | +/// able to compile with new versions of the protocol definition library. To |
| 1033 | +/// help with such case the @b COMMS library provides several macros that can generate |
| 1034 | +/// alias names for renamed fields. |
| 1035 | +/// |
| 1036 | +/// @subsection page_define_prot_field_aliases_messages Aliases to Field Names Inside Message Definition |
| 1037 | +/// The @b COMMS library provides @ref COMMS_MSG_FIELD_ALIAS() |
| 1038 | +/// macro, which is expected to be used after @ref COMMS_MSG_FIELDS_ACCESS() one when new |
| 1039 | +/// message class is being defined. |
| 1040 | +/// As an example let's change the @b value3 from the example in the |
| 1041 | +/// @ref page_define_prot_message_base_field_names section to be @b newValue3. |
| 1042 | +/// @code |
| 1043 | +/// template <typename TMessage> |
| 1044 | +/// class Message1 : public comms::MessageBase<...> |
| 1045 | +/// { |
| 1046 | +/// public: |
| 1047 | +/// // Provide names for the fields |
| 1048 | +/// COMMS_MSG_FIELDS_ACCESS(value1, value2, newValue3); |
| 1049 | +/// COMMS_MSG_FIELD_ALIAS(value3, newValue3); |
| 1050 | +/// }; |
| 1051 | +/// @endcode |
| 1052 | +/// The usage of @ref COMMS_MSG_FIELD_ALIAS() above generates the following convenience access functions: |
| 1053 | +/// @code |
| 1054 | +/// template <typename TMessage> |
| 1055 | +/// class Message1 : public comms::MessageBase<...> |
| 1056 | +/// { |
| 1057 | +/// public: |
| 1058 | +/// // Provide names for the fields |
| 1059 | +/// COMMS_MSG_FIELDS_ACCESS(value1, value2, newValue3); |
| 1060 | +/// |
| 1061 | +/// // Access to "newValue3" via "value3" name |
| 1062 | +/// auto field_value3() -> decltype(field_newValue3()) |
| 1063 | +/// { |
| 1064 | +/// return field_newValue3(); |
| 1065 | +/// } |
| 1066 | +/// |
| 1067 | +/// // Const access to "newValue3" via "value3" name |
| 1068 | +/// auto field_value3() const -> decltype(field_newValue3()) |
| 1069 | +/// { |
| 1070 | +/// return field_newValue3(); |
| 1071 | +/// } |
| 1072 | +/// }; |
| 1073 | +/// @endcode |
| 1074 | +/// In this case the old client code that tries to access appropriate field |
| 1075 | +/// using @b field_value3() access function will still work after renaming |
| 1076 | +/// takes place. |
| 1077 | +/// |
| 1078 | +/// Another common case is when some field (usually @ref comms::field::IntValue |
| 1079 | +/// or @ref comms::field::EnumValue) has a limited range of possible values |
| 1080 | +/// and in order to save on some I/O traffic, the developer decides to split |
| 1081 | +/// the value storage into multiple small parts and make it a |
| 1082 | +/// @ref comms::field::Bitfield instead. In order to keep old client code compiling |
| 1083 | +/// and working the @ref COMMS_MSG_FIELD_ALIAS() may be used: |
| 1084 | +/// @code |
| 1085 | +/// template <typename TMessage> |
| 1086 | +/// class Message1 : public comms::MessageBase<...> |
| 1087 | +/// { |
| 1088 | +/// public: |
| 1089 | +/// // Provide names for the fields |
| 1090 | +/// COMMS_MSG_FIELDS_ACCESS(value1, value2, newValue3); |
| 1091 | +/// COMMS_MSG_FIELD_ALIAS(value3, newValue3, member1); |
| 1092 | +/// }; |
| 1093 | +/// @endcode |
| 1094 | +/// The usage of @ref COMMS_MSG_FIELD_ALIAS() above generates the following convenience access functions: |
| 1095 | +/// @code |
| 1096 | +/// template <typename TMessage> |
| 1097 | +/// class Message1 : public comms::MessageBase<...> |
| 1098 | +/// { |
| 1099 | +/// public: |
| 1100 | +/// // Provide names for the fields |
| 1101 | +/// COMMS_MSG_FIELDS_ACCESS(value1, value2, newValue3); |
| 1102 | +/// |
| 1103 | +/// // Access to "newValue3.member1" via "value3" name |
| 1104 | +/// auto field_value3() -> decltype(field_newValue3().field_member1()) |
| 1105 | +/// { |
| 1106 | +/// return field_newValue3().field_member1(); |
| 1107 | +/// } |
| 1108 | +/// |
| 1109 | +/// // Const access to "newValue3.member1" via "value3" name |
| 1110 | +/// auto field_value3() const -> decltype(field_newValue3().field_member1()) |
| 1111 | +/// { |
| 1112 | +/// return field_newValue3().field_member1(); |
| 1113 | +/// } |
| 1114 | +/// }; |
| 1115 | +/// @endcode |
| 1116 | +/// |
| 1117 | +/// @subsection page_define_prot_field_aliases_bundles Aliases to Field Names Inside Bundle Fields |
| 1118 | +/// Similar to defining aliases to message fields, @b COMMS library provides an ability to define |
| 1119 | +/// aliases within @ref comms::field::Bundle "bundle" field definition using |
| 1120 | +/// @ref COMMS_FIELD_ALIAS() macro. |
| 1121 | +/// @code |
| 1122 | +/// class MyBundle : public comms::field::Bundle<...> |
| 1123 | +/// { |
| 1124 | +/// public: |
| 1125 | +/// COMMS_FIELD_MEMBERS_ACCESS(member1, member2, member3); |
| 1126 | +/// COMMS_FIELD_ALIAS(otherMem1Name, member1); |
| 1127 | +/// COMMS_FIELD_ALIAS(otherMem2Name, member2); |
| 1128 | +/// }; |
| 1129 | +/// @endcode |
| 1130 | +/// |
| 1131 | +/// @subsection page_define_prot_field_aliases_interfaces Aliases to Extra Transport Field Names Inside Interface |
| 1132 | +/// The @ref page_define_prot_interface class definition may have |
| 1133 | +/// @ref page_define_prot_interface_extra_transport. Aliasing between the |
| 1134 | +/// extra transport fields can be defined using @ref COMMS_MSG_TRANSPORT_FIELD_ALIAS() |
| 1135 | +/// macro. |
| 1136 | +/// @code |
| 1137 | +/// template <typename... TOptions> |
| 1138 | +/// class Message : public |
| 1139 | +/// comms::Message< |
| 1140 | +/// comms::option::def::BigEndian, |
| 1141 | +/// comms::option::def::MsgIdType<MsgId>, |
| 1142 | +/// comms::option::def::ExtraTransportFields<MyExtraTransportFields>, |
| 1143 | +/// TOptions... |
| 1144 | +/// > |
| 1145 | +/// { |
| 1146 | +/// public: |
| 1147 | +/// COMMS_MSG_TRANSPORT_FIELDS_ACCESS(version, flags); |
| 1148 | +/// COMMS_MSG_TRANSPORT_FIELD_ALIAS(otherFlagsName, flags); |
| 1149 | +/// }; |
| 1150 | +/// @endcode |
| 1151 | +/// |
1028 | 1152 | /// @section page_define_prot_lenth_verification Extra Compile Time Checks |
1029 | 1153 | /// Quite often it is obvious from the protocol specification what minimal length |
1030 | 1154 | /// of the serialised message contents is expected to be, and if there are not |
|
0 commit comments