Goby3 3.2.3
2025.05.13
Loading...
Searching...
No Matches
message_var.h
Go to the documentation of this file.
1// Copyright 2009-2021:
2// GobySoft, LLC (2013-)
3// Massachusetts Institute of Technology (2007-2014)
4// Community contributors (see AUTHORS file)
5// File authors:
6// Toby Schneider <toby@gobysoft.org>
7//
8//
9// This file is part of the Goby Underwater Autonomy Project Libraries
10// ("The Goby Libraries").
11//
12// The Goby Libraries are free software: you can redistribute them and/or modify
13// them under the terms of the GNU Lesser General Public License as published by
14// the Free Software Foundation, either version 2.1 of the License, or
15// (at your option) any later version.
16//
17// The Goby Libraries are distributed in the hope that they will be useful,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20// GNU Lesser General Public License for more details.
21//
22// You should have received a copy of the GNU Lesser General Public License
23// along with Goby. If not, see <http://www.gnu.org/licenses/>.
24
25#ifndef GOBY_MOOS_TRANSITIONAL_MESSAGE_VAR_H
26#define GOBY_MOOS_TRANSITIONAL_MESSAGE_VAR_H
27
28#include <bitset>
29#include <cmath>
30#include <limits>
31#include <map>
32#include <ostream>
33#include <stdexcept>
34#include <string>
35#include <utility>
36
37#include <vector>
38
39#include <boost/lexical_cast.hpp>
40
41#include "dccl_constants.h"
42#include "goby/acomms/dccl.h"
43#include "message_val.h"
44namespace goby
45{
46namespace moos
47{
48namespace transitional
49{
50class DCCLMessageVal;
51class DCCLMessage;
52class DCCLAlgorithmPerformer;
53
54// defines a piece of a DCCLMessage (an <int>, a <bool>, etc)
56{
57 public:
58 // Added in Goby2 for transition to new Protobuf structure
59 virtual void write_schema_to_dccl2(std::ofstream* proto_file, int sequence_number) {}
60
61 DCCLMessageVar() = default;
62
63 // set
64 void set_name(std::string name) { name_ = std::move(name); }
65 void set_source_var(std::string source_var)
66 {
67 source_var_ = std::move(source_var);
68 source_set_ = true;
69 }
70 void set_source_key(std::string source_key) { source_key_ = std::move(source_key); }
71 void set_source_set(bool source_set) { source_set_ = source_set; }
72 void set_algorithms(const std::vector<std::string>& algorithm) { algorithms_ = algorithm; }
73
74 // should be overloaded by derived types if supported
75 virtual void set_max(const std::string& /*s*/) { bad_overload("set_max()"); }
76 virtual void set_min(const std::string& /*s*/) { bad_overload("set_min()"); }
77 virtual void set_precision(const std::string& /*s*/) { bad_overload("set_precision()"); }
78 virtual void set_max_length(const std::string& /*s*/) { bad_overload("set_max_length()"); }
79 virtual void set_num_bytes(const std::string& /*s*/) { bad_overload("set_num_bytes()"); }
80 virtual void set_static_val(const std::string& /*static_val*/)
81 {
82 bad_overload("set_static_val()");
83 }
84 virtual void add_enum(std::string /*senum*/) { bad_overload("add_enum()"); }
85 virtual void set_max_delta(const std::string& /*s*/) { bad_overload("set_max_delta()"); }
86
87 void set_array_length(unsigned u) { array_length_ = u; }
88 void set_array_length(const std::string& s)
89 {
90 set_array_length(boost::lexical_cast<unsigned>(s));
91 }
92
93 virtual double max() const
94 {
95 bad_overload("max()");
96 return 0;
97 }
98 virtual double min() const
99 {
100 bad_overload("min()");
101 return 0;
102 }
103 virtual int precision() const
104 {
105 bad_overload("precision()");
106 return 0;
107 }
108 virtual unsigned max_length() const
109 {
110 bad_overload("max_length()");
111 return 0;
112 }
113 virtual unsigned num_bytes() const
114 {
115 bad_overload("num_bytes()");
116 return 0;
117 }
118 virtual std::string static_val() const
119 {
120 bad_overload("static_val()");
121 return "";
122 }
123 virtual std::vector<std::string>* enums()
124 {
125 bad_overload("enums()");
126 return nullptr;
127 }
128
129 unsigned array_length() const { return array_length_; }
130
131 // get
132 virtual DCCLType type() const = 0;
133
134 std::string name() const { return name_; }
135 std::string source_var() const { return source_var_; }
136
137 int sequence_number() const { return sequence_number_; }
138 const std::vector<std::string>& algorithms() const { return algorithms_; }
139
140 // other
141 void initialize(const DCCLMessage& msg) {}
142
143 // std::string get_display() const;
144
145 void set_defaults(std::map<std::string, std::vector<DCCLMessageVal> >& vals, unsigned modem_id,
146 unsigned id)
147 {
148 }
149
150 protected:
151 virtual void initialize_specific() = 0;
152
153 virtual std::string additional_option_extensions() { return ""; }
154
155 virtual void set_defaults_specific(DCCLMessageVal& /*v*/, unsigned /*modem_id*/,
156 unsigned /*id*/)
157 {
158 bad_overload("set_defaults_specific()");
159 }
160
161 private:
162 void bad_overload(const std::string& s) const
163 {
165 std::string(s + " not supported by this DCCLMessageVar: " + name() + " (" +
166 type_to_string(type()) + ")")));
167 }
168
169 protected:
173 std::string source_var_;
174 std::string name_;
176
177 private:
178 bool source_set_;
179 std::string source_key_;
180 std::vector<std::string> algorithms_;
181};
182
183} // namespace transitional
184} // namespace moos
185} // namespace goby
186#endif
void set_source_key(std::string source_key)
Definition message_var.h:70
virtual std::string static_val() const
virtual void set_num_bytes(const std::string &)
Definition message_var.h:79
void set_defaults(std::map< std::string, std::vector< DCCLMessageVal > > &vals, unsigned modem_id, unsigned id)
virtual void set_static_val(const std::string &)
Definition message_var.h:80
void set_source_var(std::string source_var)
Definition message_var.h:65
const std::vector< std::string > & algorithms() const
virtual void set_defaults_specific(DCCLMessageVal &, unsigned, unsigned)
virtual void set_max_delta(const std::string &)
Definition message_var.h:85
void set_array_length(const std::string &s)
Definition message_var.h:88
virtual std::string additional_option_extensions()
void initialize(const DCCLMessage &msg)
virtual void add_enum(std::string)
Definition message_var.h:84
virtual unsigned max_length() const
virtual void set_max_length(const std::string &)
Definition message_var.h:78
void set_algorithms(const std::vector< std::string > &algorithm)
Definition message_var.h:72
virtual void set_precision(const std::string &)
Definition message_var.h:77
virtual void write_schema_to_dccl2(std::ofstream *proto_file, int sequence_number)
Definition message_var.h:59
virtual DCCLType type() const =0
virtual std::vector< std::string > * enums()
virtual void set_min(const std::string &)
Definition message_var.h:76
virtual void set_max(const std::string &)
Definition message_var.h:75
dccl::Exception DCCLException
Definition dccl.h:69
std::string type_to_string(DCCLType type)
DCCLType
Enumeration of DCCL types used for sending messages. dccl_enum and dccl_string primarily map to cpp_s...
The global namespace for the Goby project.
extern ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< ::PROTOBUF_NAMESPACE_ID::MessageOptions, ::PROTOBUF_NAMESPACE_ID::internal::MessageTypeTraits< ::goby::GobyMessageOptions >, 11, false > msg