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