libcluon  0.0.148
ToODVDVisitor.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_TOODVDVISITOR_HPP
10 #define CLUON_TOODVDVISITOR_HPP
11 
12 #include "cluon/cluon.hpp"
13 
14 #include <cstdint>
15 #include <regex>
16 #include <sstream>
17 #include <string>
18 #include <vector>
19 
20 namespace cluon {
41  private:
42  ToODVDVisitor(const ToODVDVisitor &) = delete;
43  ToODVDVisitor(ToODVDVisitor &&) = delete;
44  ToODVDVisitor &operator=(const ToODVDVisitor &) = delete;
45  ToODVDVisitor &operator=(ToODVDVisitor &&) = delete;
46 
47  public:
48  ToODVDVisitor() = default;
49 
53  std::string messageSpecification() const noexcept;
54 
55  public:
56  // The following methods are provided to allow an instance of this class to
57  // be used as visitor for an instance with the method signature void accept<T>(T&);
58 
59  void preVisit(int32_t id, const std::string &shortName, const std::string &longName) noexcept;
60  void postVisit() noexcept;
61 
62  void visit(uint32_t id, std::string &&typeName, std::string &&name, bool &v) noexcept;
63  void visit(uint32_t id, std::string &&typeName, std::string &&name, char &v) noexcept;
64  void visit(uint32_t id, std::string &&typeName, std::string &&name, int8_t &v) noexcept;
65  void visit(uint32_t id, std::string &&typeName, std::string &&name, uint8_t &v) noexcept;
66  void visit(uint32_t id, std::string &&typeName, std::string &&name, int16_t &v) noexcept;
67  void visit(uint32_t id, std::string &&typeName, std::string &&name, uint16_t &v) noexcept;
68  void visit(uint32_t id, std::string &&typeName, std::string &&name, int32_t &v) noexcept;
69  void visit(uint32_t id, std::string &&typeName, std::string &&name, uint32_t &v) noexcept;
70  void visit(uint32_t id, std::string &&typeName, std::string &&name, int64_t &v) noexcept;
71  void visit(uint32_t id, std::string &&typeName, std::string &&name, uint64_t &v) noexcept;
72  void visit(uint32_t id, std::string &&typeName, std::string &&name, float &v) noexcept;
73  void visit(uint32_t id, std::string &&typeName, std::string &&name, double &v) noexcept;
74  void visit(uint32_t id, std::string &&typeName, std::string &&name, std::string &v) noexcept;
75 
76  template <typename T>
77  void visit(uint32_t &id, std::string &&typeName, std::string &&name, T &value) noexcept {
78  try {
79  std::string tmp{std::regex_replace(typeName, std::regex("::"), ".")}; // NOLINT
80 
81  ToODVDVisitor odvdVisitor;
82  value.accept(odvdVisitor);
83  m_forwardDeclarations.emplace(m_forwardDeclarations.begin(), odvdVisitor.messageSpecification());
84 
85  m_buffer << " " << tmp << ' ' << name << " [ id = " << id << " ];" << '\n';
86  } catch (std::regex_error &) { // LCOV_EXCL_LINE
87  }
88  }
89 
90  private:
91  std::vector<std::string> m_forwardDeclarations{};
92  std::stringstream m_buffer{};
93 };
94 
95 } // namespace cluon
96 #endif
Definition: cluon.hpp:65
std::string messageSpecification() const noexcept
Definition: ToODVDVisitor.cpp:15
#define LIBCLUON_API
Definition: cluon.hpp:56
Definition: ToODVDVisitor.hpp:40
void visit(uint32_t &id, std::string &&typeName, std::string &&name, T &value) noexcept
Definition: ToODVDVisitor.hpp:77