DCCL v4
Loading...
Searching...
No Matches
field_codec_data.h
1// Copyright 2023:
2// GobySoft, LLC (2013-)
3// Community contributors (see AUTHORS file)
4// File authors:
5// Toby Schneider <toby@gobysoft.org>
6//
7//
8// This file is part of the Dynamic Compact Control Language Library
9// ("DCCL").
10//
11// DCCL is free software: you can redistribute it and/or modify
12// it under the terms of the GNU Lesser General Public License as published by
13// the Free Software Foundation, either version 2.1 of the License, or
14// (at your option) any later version.
15//
16// DCCL is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU Lesser General Public License for more details.
20//
21// You should have received a copy of the GNU Lesser General Public License
22// along with DCCL. If not, see <http://www.gnu.org/licenses/>.
23#ifndef DCCLFIELDCODECDATAH
24#define DCCLFIELDCODECDATAH
25
26#include "../dynamic_conditions.h"
27
28#include "field_codec_message_stack.h"
29
30#include <typeindex>
31
32namespace google
33{
34namespace protobuf
35{
36class Message;
37class Descriptor;
38} // namespace protobuf
39} // namespace google
40
41namespace dccl
42{
43namespace internal
44{
45// Data shared amongst all the FieldCodecs for a single message
47{
48 MessagePart part_{dccl::UNKNOWN};
49 bool strict_{false};
50 const google::protobuf::Message* root_message_{nullptr};
51 const google::protobuf::Descriptor* root_descriptor_{nullptr};
52 MessageStackData message_data_;
53 DynamicConditions dynamic_conditions_;
54
55 template <typename FieldCodecType>
56 void set_codec_specific_data(std::shared_ptr<dccl::any> data)
57 {
58 codec_specific_[std::type_index(typeid(FieldCodecType))] = data;
59 }
60
61 template <typename FieldCodecType> std::shared_ptr<dccl::any> codec_specific_data()
62 {
63 return codec_specific_.at(std::type_index(typeid(FieldCodecType)));
64 }
65
66 template <typename FieldCodecType> bool has_codec_specific_data()
67 {
68 return codec_specific_.count(std::type_index(typeid(FieldCodecType)));
69 }
70
71 private:
72 std::map<std::type_index, std::shared_ptr<dccl::any>> codec_specific_;
73};
74} // namespace internal
75} // namespace dccl
76
77#endif
Dynamic Compact Control Language namespace.
Definition any.h:47