libcluon  0.0.148
FromLCMVisitor.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_FROMLCMVISITOR_HPP
10 #define CLUON_FROMLCMVISITOR_HPP
11 
12 #include "cluon/cluon.hpp"
13 
14 #include <cstdint>
15 #include <istream>
16 #include <sstream>
17 #include <string>
18 #include <vector>
19 
20 namespace cluon {
25  private:
26  FromLCMVisitor(std::stringstream &in) noexcept;
27  FromLCMVisitor(const FromLCMVisitor &) = delete;
28  FromLCMVisitor(FromLCMVisitor &&) = delete;
29  FromLCMVisitor &operator=(const FromLCMVisitor &) = delete;
30  FromLCMVisitor &operator=(FromLCMVisitor &&) = delete;
31 
32  public:
33  FromLCMVisitor() noexcept;
34  ~FromLCMVisitor() = default;
35 
36  public:
42  void decodeFrom(std::istream &in) noexcept;
43 
44  public:
45  // The following methods are provided to allow an instance of this class to
46  // be used as visitor for an instance with the method signature void accept<T>(T&);
47 
48  void preVisit(int32_t id, const std::string &shortName, const std::string &longName) noexcept;
49  void postVisit() noexcept;
50 
51  void visit(uint32_t id, std::string &&typeName, std::string &&name, bool &v) noexcept;
52  void visit(uint32_t id, std::string &&typeName, std::string &&name, char &v) noexcept;
53  void visit(uint32_t id, std::string &&typeName, std::string &&name, int8_t &v) noexcept;
54  void visit(uint32_t id, std::string &&typeName, std::string &&name, uint8_t &v) noexcept;
55  void visit(uint32_t id, std::string &&typeName, std::string &&name, int16_t &v) noexcept;
56  void visit(uint32_t id, std::string &&typeName, std::string &&name, uint16_t &v) noexcept;
57  void visit(uint32_t id, std::string &&typeName, std::string &&name, int32_t &v) noexcept;
58  void visit(uint32_t id, std::string &&typeName, std::string &&name, uint32_t &v) noexcept;
59  void visit(uint32_t id, std::string &&typeName, std::string &&name, int64_t &v) noexcept;
60  void visit(uint32_t id, std::string &&typeName, std::string &&name, uint64_t &v) noexcept;
61  void visit(uint32_t id, std::string &&typeName, std::string &&name, float &v) noexcept;
62  void visit(uint32_t id, std::string &&typeName, std::string &&name, double &v) noexcept;
63  void visit(uint32_t id, std::string &&typeName, std::string &&name, std::string &v) noexcept;
64 
65  template <typename T>
66  void visit(uint32_t &id, std::string &&typeName, std::string &&name, T &value) noexcept {
67  (void)id;
68  (void)typeName;
69  // No hash for the type but for name and dimension.
70  calculateHash(name);
71  calculateHash(0);
72 
73  cluon::FromLCMVisitor nestedLCMDecoder(m_buffer);
74  value.accept(nestedLCMDecoder);
75 
76  m_hashes.push_back(nestedLCMDecoder.hash());
77  }
78 
79  private:
80  int64_t hash() const noexcept;
81  void calculateHash(char c) noexcept;
82  void calculateHash(const std::string &s) noexcept;
83 
84  private:
85  int64_t m_calculatedHash{0x12345678};
86  int64_t m_expectedHash{0};
87  std::stringstream m_internalBuffer{""};
88  std::stringstream &m_buffer;
89  std::vector<int64_t> m_hashes{};
90 };
91 } // namespace cluon
92 
93 #endif
Definition: cluon.hpp:65
#define LIBCLUON_API
Definition: cluon.hpp:56
void visit(uint32_t &id, std::string &&typeName, std::string &&name, T &value) noexcept
Definition: FromLCMVisitor.hpp:66
Definition: FromLCMVisitor.hpp:24