libcluon  0.0.148
MetaMessage.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017-2018 Christian Berger
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8 
9 #ifndef CLUON_METAMESSAGE_HPP
10 #define CLUON_METAMESSAGE_HPP
11 
12 #include "cluon/cluon.hpp"
13 
14 #include <cstdint>
15 #include <functional>
16 #include <string>
17 #include <vector>
18 
19 namespace cluon {
26  public:
31  class MetaField {
32  public:
33  enum MetaFieldDataTypes : uint16_t {
34  BOOL_T = 0,
35  UINT8_T = 2,
36  INT8_T = 3,
37  UINT16_T = 4,
38  INT16_T = 5,
39  UINT32_T = 6,
40  INT32_T = 7,
41  UINT64_T = 8,
42  INT64_T = 9,
43  CHAR_T = 11,
44  FLOAT_T = 13,
45  DOUBLE_T = 14,
46  BYTES_T = 49,
47  STRING_T = 51,
48  MESSAGE_T = 53,
49  UNDEFINED_T = 0xFFFF,
50  };
51 
52  private:
53  MetaField &operator=(MetaField &&) = delete;
54 
55  public:
56  MetaField() = default;
57  MetaField(const MetaField &) = default;
58  MetaField(MetaField &&) = default;
59  MetaField &operator=(const MetaField &) = default;
60 
61  public:
65  MetaFieldDataTypes fieldDataType() const noexcept;
72  MetaField &fieldDataType(const MetaFieldDataTypes &v) noexcept;
73 
77  std::string fieldDataTypeName() const noexcept;
84  MetaField &fieldDataTypeName(const std::string &v) noexcept;
85 
89  std::string fieldName() const noexcept;
96  MetaField &fieldName(const std::string &v) noexcept;
97 
101  uint32_t fieldIdentifier() const noexcept;
108  MetaField &fieldIdentifier(uint32_t v) noexcept;
109 
113  std::string defaultInitializationValue() const noexcept;
120  MetaField &defaultInitializationValue(const std::string &v) noexcept;
121 
122  private:
123  MetaFieldDataTypes m_fieldDataType{UNDEFINED_T};
124  std::string m_fieldDataTypeName{""};
125  std::string m_fieldName{""};
126  uint32_t m_fieldIdentifier{0};
127  std::string m_defaultInitializationValue{""};
128  };
129 
130  public:
131  MetaMessage() noexcept;
132  MetaMessage(const MetaMessage &) = default;
133  MetaMessage(MetaMessage &&) = default;
134  MetaMessage &operator=(const MetaMessage &) = default;
135  MetaMessage &operator=(MetaMessage &&) = default;
136 
143  MetaMessage &add(MetaField &&mf) noexcept;
144 
150  const std::vector<MetaField> &listOfMetaFields() const noexcept;
151 
158  void accept(const std::function<void(const MetaMessage &)> &visit);
159 
163  std::string packageName() const noexcept;
170  MetaMessage &packageName(const std::string &v) noexcept;
171 
175  std::string messageName() const noexcept;
182  MetaMessage &messageName(const std::string &v) noexcept;
183 
187  int32_t messageIdentifier() const noexcept;
194  MetaMessage &messageIdentifier(int32_t v) noexcept;
195 
196  private:
197  std::string m_packageName{""};
198  std::string m_messageName{""};
199  int32_t m_messageIdentifier{0};
200  std::vector<MetaField> m_listOfMetaFields{};
201 };
202 } // namespace cluon
203 
204 #endif
Definition: cluon.hpp:65
mf fieldDataTypeName(::stringtoolbox::trim(_fieldDataType))
mf fieldIdentifier((!_fieldIdentifier.empty() ? static_cast< uint32_t >(std::stoi(::stringtoolbox::trim(_fieldIdentifier))) :fieldIdentifierCounter))
STL namespace.
#define LIBCLUON_API
Definition: cluon.hpp:56
Definition: MetaMessage.hpp:31
mm add(std::move(mf))
mf defaultInitializationValue(_fieldDefaultInitializerValue)
Definition: MetaMessage.hpp:25
MetaFieldDataTypes
Definition: MetaMessage.hpp:33
mf fieldName(::stringtoolbox::trim(_fieldName))
MetaMessage::MetaField mf
Definition: MessageParser.cpp:243