Goby3  3.1.5a
2024.05.23
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"
44 namespace goby
45 {
46 namespace moos
47 {
48 namespace transitional
49 {
50 class DCCLMessageVal;
51 class DCCLMessage;
52 class 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:
170  unsigned array_length_;
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
goby::moos::transitional::DCCLMessageVar::name
std::string name() const
Definition: message_var.h:134
goby::moos::transitional::DCCLMessageVar::is_key_frame_
bool is_key_frame_
Definition: message_var.h:172
goby::moos::transitional::DCCLMessageVar::set_static_val
virtual void set_static_val(const std::string &)
Definition: message_var.h:80
goby::moos::transitional::DCCLMessageVar::DCCLMessageVar
DCCLMessageVar()=default
goby::moos::transitional::DCCLMessageVar::source_var_
std::string source_var_
Definition: message_var.h:173
goby::moos::transitional::DCCLMessageVar::static_val
virtual std::string static_val() const
Definition: message_var.h:118
goby::moos::transitional::DCCLMessageVar::set_num_bytes
virtual void set_num_bytes(const std::string &)
Definition: message_var.h:79
message_val.h
goby
The global namespace for the Goby project.
Definition: acomms_constants.h:33
goby::moos::transitional::DCCLMessageVar::precision
virtual int precision() const
Definition: message_var.h:103
goby::moos::transitional::DCCLMessageVar::initialize_specific
virtual void initialize_specific()=0
goby::moos::transitional::DCCLMessageVar::sequence_number_
int sequence_number_
Definition: message_var.h:175
goby::moos::transitional::DCCLMessageVar::add_enum
virtual void add_enum(std::string)
Definition: message_var.h:84
goby::moos::transitional::DCCLMessageVar::set_name
void set_name(std::string name)
Definition: message_var.h:64
goby::moos::transitional::DCCLMessageVar::array_length_
unsigned array_length_
Definition: message_var.h:170
dccl_constants.h
goby::moos::transitional::DCCLMessageVar::key_val_
DCCLMessageVal key_val_
Definition: message_var.h:171
goby::moos::transitional::DCCLMessageVar::set_max_delta
virtual void set_max_delta(const std::string &)
Definition: message_var.h:85
goby::moos::transitional::DCCLMessageVar::set_defaults
void set_defaults(std::map< std::string, std::vector< DCCLMessageVal > > &vals, unsigned modem_id, unsigned id)
Definition: message_var.h:145
goby::moos::transitional::DCCLMessageVar::min
virtual double min() const
Definition: message_var.h:98
goby::moos::transitional::DCCLType
DCCLType
Enumeration of DCCL types used for sending messages. dccl_enum and dccl_string primarily map to cpp_s...
Definition: dccl_constants.h:48
dccl.h
goby::moos::transitional::DCCLMessageVar::set_precision
virtual void set_precision(const std::string &)
Definition: message_var.h:77
goby::moos::transitional::DCCLMessageVar::set_array_length
void set_array_length(unsigned u)
Definition: message_var.h:87
goby::moos::transitional::DCCLMessageVar::write_schema_to_dccl2
virtual void write_schema_to_dccl2(std::ofstream *proto_file, int sequence_number)
Definition: message_var.h:59
goby::moos::transitional::DCCLMessageVar::max_length
virtual unsigned max_length() const
Definition: message_var.h:108
goby::moos::transitional::DCCLMessageVar::array_length
unsigned array_length() const
Definition: message_var.h:129
goby::moos::transitional::DCCLMessageVar::type
virtual DCCLType type() const =0
goby::moos::transitional::DCCLMessageVal
defines a DCCL value
Definition: message_val.h:41
goby::moos::transitional::DCCLMessageVar::set_algorithms
void set_algorithms(const std::vector< std::string > &algorithm)
Definition: message_var.h:72
goby::msg
extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, ::google::protobuf::internal::MessageTypeTraits< ::goby::GobyMessageOptions >, 11, false > msg
Definition: option_extensions.pb.h:1327
goby::moos::transitional::DCCLMessageVar::sequence_number
int sequence_number() const
Definition: message_var.h:137
goby::moos::transitional::DCCLMessageVar::algorithms
const std::vector< std::string > & algorithms() const
Definition: message_var.h:138
goby::moos::transitional::DCCLMessageVar::set_max
virtual void set_max(const std::string &)
Definition: message_var.h:75
goby::moos::transitional::DCCLMessageVar::initialize
void initialize(const DCCLMessage &msg)
Definition: message_var.h:141
goby::moos::transitional::DCCLMessageVar
Definition: message_var.h:55
goby::moos::transitional::DCCLMessageVar::enums
virtual std::vector< std::string > * enums()
Definition: message_var.h:123
goby::moos::transitional::DCCLMessageVar::set_array_length
void set_array_length(const std::string &s)
Definition: message_var.h:88
goby::moos::transitional::DCCLMessageVar::num_bytes
virtual unsigned num_bytes() const
Definition: message_var.h:113
goby::moos::transitional::type_to_string
std::string type_to_string(DCCLType type)
Definition: dccl_constants.h:84
goby::moos::transitional::DCCLMessageVar::set_source_var
void set_source_var(std::string source_var)
Definition: message_var.h:65
goby::moos::transitional::DCCLMessage
Definition: message.h:61
goby::moos::transitional::DCCLMessageVar::set_max_length
virtual void set_max_length(const std::string &)
Definition: message_var.h:78
goby::moos::transitional::DCCLMessageVar::max
virtual double max() const
Definition: message_var.h:93
goby::moos::transitional::DCCLMessageVar::set_source_set
void set_source_set(bool source_set)
Definition: message_var.h:71
goby::moos::transitional::DCCLMessageVar::set_source_key
void set_source_key(std::string source_key)
Definition: message_var.h:70
goby::moos::transitional::DCCLMessageVar::name_
std::string name_
Definition: message_var.h:174
goby::moos::transitional::DCCLMessageVar::set_defaults_specific
virtual void set_defaults_specific(DCCLMessageVal &, unsigned, unsigned)
Definition: message_var.h:155
goby::acomms::DCCLException
dccl::Exception DCCLException
Definition: dccl.h:69
goby::moos::transitional::DCCLMessageVar::set_min
virtual void set_min(const std::string &)
Definition: message_var.h:76
goby::moos::transitional::DCCLMessageVar::source_var
std::string source_var() const
Definition: message_var.h:135
goby::moos::transitional::DCCLMessageVar::additional_option_extensions
virtual std::string additional_option_extensions()
Definition: message_var.h:153