Falcon
Loading...
Searching...
No Matches
eventdata.hpp
1// ---------------------------------------------------------------------
2// This file is part of falcon-core.
3//
4// Copyright (C) 2015, 2016, 2017 Neuro-Electronics Research Flanders
5//
6// Falcon-server is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// Falcon-server is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with falcon-core. If not, see <http://www.gnu.org/licenses/>.
18// ---------------------------------------------------------------------
19
20#pragma once
21
22#include <string>
23#include <string_view>
24
25#include "idata.hpp"
26#include "yaml-cpp/yaml.h"
27
28const std::string DEFAULT_EVENT = "none";
29// to be used for port names using event data
30const std::string EVENTDATA = "events";
31
32namespace nsEventType {
33
34using ParentType = AnyType;
35
36struct Parameters {
37 Parameters(const std::string& event = DEFAULT_EVENT) : default_event(event) {}
38
39 std::string default_event;
40};
41
42class Data : public IData<Data, ParentType> {
43 public:
44 using BaseClass = IData<Data, ParentType>;
45
46 Data(const std::string& event = DEFAULT_EVENT);
47 Data(const Parameters& parameters) : Data(parameters.default_event) {}
48
49 static const std::string static_datatype() { return "event"; }
50 static const std::string static_dataname() { return "events"; }
51
52 Parameters parameters() const { return Parameters(default_event_); }
53
54 void ClearData() override;
55 std::string event() const;
56 size_t hash() const;
57 size_t size() const;
58 void set_event(const std::string& event);
59 void set_event(const Data& source);
60
61 friend bool operator==(const Data& e1, const Data& e2);
62 friend bool operator!=(const Data& e1, const Data& e2);
63
64 void SerializeBinary(std::ostream& stream,
65 Serialization::Format format = Serialization::Format::FULL) const override;
66
67 std::string_view serialized_type_name() const override { return "EventType"; }
68
69 void SerializeYAML(YAML::Node& node,
70 Serialization::Format format = Serialization::Format::FULL) const override;
71
72 void SerializeFlatBuffer(flexbuffers::Builder& fbb) override;
73
74 void YAMLDescription(YAML::Node& node,
75 Serialization::Format format = Serialization::Format::FULL) const override;
76
77 protected:
78 std::string default_event_;
79 std::string event_;
80 size_t hash_;
81
82 static const unsigned int EVENT_STRING_LENGTH = 128;
83};
84
85using Capabilities = ParentType::Capabilities;
86
87} // namespace nsEventType
88
89using EventType = DefineType<nsEventType::Data, AnyType, true, nsEventType::Capabilities,
91
92namespace YAML {
93template <>
94struct convert<EventType::Data> {
95 static Node encode(const EventType::Data& rhs) {
96 Node node;
97 node = rhs.event();
98 return node;
99 }
100
101 static bool decode(const Node& node, EventType::Data& rhs) {
102 rhs.set_event(node.as<std::string>());
103 return true;
104 }
105};
106} // namespace YAML
Convenient template class to define data types.
Definition idata.hpp:75
Base class of all data object classes.
Definition idata.hpp:95
Definition eventdata.hpp:42
Definition eventdata.hpp:36