SimpleAI
 All Classes Namespaces Files Functions Variables Typedefs Macros Groups Pages
AINamesMessage.h
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #include "IProtocolMessage.h"
7 
8 namespace ai {
9 
16 private:
17  std::vector<std::string> _names;
18  const std::vector<std::string>* _namesPtr;
19 
20 public:
21  explicit AINamesMessage(const std::vector<std::string>& names) :
22  IProtocolMessage(PROTO_NAMES), _namesPtr(&names) {
23  }
24 
25  explicit AINamesMessage(streamContainer& in) :
26  IProtocolMessage(PROTO_NAMES), _namesPtr(nullptr) {
27  const int size = readInt(in);
28  for (int i = 0; i < size; ++i) {
29  _names.push_back(readString(in));
30  }
31  }
32 
33  void serialize(streamContainer& out) const override {
34  addByte(out, _id);
35  const std::size_t size = _namesPtr->size();
36  addInt(out, static_cast<int>(size));
37  for (std::size_t i = 0U; i < size; ++i) {
38  addString(out, (*_namesPtr)[i]);
39  }
40  }
41 
42  inline const std::vector<std::string>& getNames() const {
43  if (_namesPtr)
44  return *_namesPtr;
45  return _names;
46  }
47 };
48 
49 }
Message for the remote debugging interface.
Definition: AINamesMessage.h:15
A protocol message is used for the serialization of the ai states for remote debugging.
Definition: IProtocolMessage.h:60