Goby3  3.1.5
2024.05.14
message_val.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_VAL_H
26 #define GOBY_MOOS_TRANSITIONAL_MESSAGE_VAL_H
27 
28 #include <iostream> // for ostream
29 #include <string> // for string, basic_string
30 #include <vector> // for vector
31 
32 #include "dccl_constants.h" // for DCCLCppType, cpp_notype
33 
34 namespace goby
35 {
36 namespace moos
37 {
38 namespace transitional
39 {
42 {
43  public:
44  enum
45  {
47  };
48 
50 
53 
55  DCCLMessageVal(const std::string& s);
56 
58  DCCLMessageVal(const char* s);
59 
61  DCCLMessageVal(double d, int p = MAX_DBL_PRECISION);
62 
64  DCCLMessageVal(long l);
65 
67  DCCLMessageVal(int i);
68 
70  DCCLMessageVal(float f);
71 
73  DCCLMessageVal(bool b);
74 
76  DCCLMessageVal(const std::vector<DCCLMessageVal>& vm);
77 
79 
81 
82  void set(std::string sval);
87  void set(double dval, int precision = MAX_DBL_PRECISION);
89  void set(long lval);
91  void set(bool bval);
92 
94 
96 
97  bool get(std::string& s) const;
104  bool get(bool& b) const;
108  bool get(long& t) const;
112  bool get(double& d) const;
113 
116  operator double() const;
117 
120  operator bool() const;
121 
124  operator std::string() const;
125 
128  operator long() const;
129 
132  operator int() const;
133 
136  operator unsigned() const;
137 
140  operator float() const;
141 
142  operator std::vector<DCCLMessageVal>() const;
143 
145  DCCLCppType type() const { return type_; }
146 
148  bool empty() const { return type_ == cpp_notype; }
149 
150  unsigned precision() const { return precision_; }
151 
153 
155 
156  bool operator==(const DCCLMessageVal& mv) const;
157  bool operator==(const std::string& s) const;
158  bool operator==(double d) const;
159  bool operator==(long l) const;
160  bool operator==(bool b) const;
161 
162  // @}
163 
164  private:
165  void init();
166 
167  friend std::ostream& operator<<(std::ostream& os, const DCCLMessageVal& mv);
168 
169  private:
170  std::string sval_;
171  double dval_;
172  long lval_;
173  bool bval_;
174 
175  unsigned precision_;
176 
177  DCCLCppType type_;
178 };
179 
180 std::ostream& operator<<(std::ostream& os, const DCCLMessageVal& mv);
181 std::ostream& operator<<(std::ostream& os, const std::vector<DCCLMessageVal>& vm);
182 } // namespace transitional
183 } // namespace moos
184 } // namespace goby
185 
186 #endif
goby
The global namespace for the Goby project.
Definition: acomms_constants.h:33
goby::moos::transitional::DCCLMessageVal::empty
bool empty() const
was this just constructed with DCCLMessageVal() ?
Definition: message_val.h:148
goby::moos::transitional::DCCLMessageVal::type
DCCLCppType type() const
what type is the original type of this DCCLMessageVal?
Definition: message_val.h:145
goby::moos::transitional::DCCLMessageVal::operator==
bool operator==(const DCCLMessageVal &mv) const
dccl_constants.h
goby::moos::transitional::DCCLMessageVal::MAX_DBL_PRECISION
@ MAX_DBL_PRECISION
Definition: message_val.h:46
goby::moos::transitional::DCCLMessageVal::precision
unsigned precision() const
Definition: message_val.h:150
goby::moos::transitional::DCCLMessageVal::DCCLMessageVal
DCCLMessageVal()
empty
bool
goby::moos::transitional::DCCLMessageVal::set
void set(std::string sval)
set the value with a string (overwrites previous value regardless of type)
double
goby::moos::transitional::DCCLMessageVal
defines a DCCL value
Definition: message_val.h:41
goby::moos::transitional::operator<<
std::ostream & operator<<(std::ostream &os, const DCCLMessageVal &mv)
goby::moos::transitional::DCCLMessageVal::operator<<
friend std::ostream & operator<<(std::ostream &os, const DCCLMessageVal &mv)
goby::moos::transitional::DCCLCppType
DCCLCppType
Enumeration of C++ types used in DCCL.
Definition: dccl_constants.h:59
goby::moos::transitional::DCCLMessageVal::get
bool get(std::string &s) const
extract as std::string (all reasonable casts are done)
goby::moos::transitional::cpp_notype
@ cpp_notype
Definition: dccl_constants.h:61
int