Goby v2
message_val.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_VAL20091211H
24 #define MESSAGE_VAL20091211H
25 
26 #include <iostream>
27 
28 #include "dccl_constants.h"
29 
30 namespace goby
31 {
32 namespace transitional
33 {
36 {
37  public:
38  enum
39  {
40  MAX_DBL_PRECISION = 15
41  };
42 
44 
47 
49  DCCLMessageVal(const std::string& s);
50 
52  DCCLMessageVal(const char* s);
53 
55  DCCLMessageVal(double d, int p = MAX_DBL_PRECISION);
56 
58  DCCLMessageVal(long l);
59 
61  DCCLMessageVal(int i);
62 
64  DCCLMessageVal(float f);
65 
67  DCCLMessageVal(bool b);
68 
70  DCCLMessageVal(const std::vector<DCCLMessageVal>& vm);
71 
73 
75 
76  void set(std::string sval);
81  void set(double dval, int precision = MAX_DBL_PRECISION);
83  void set(long lval);
85  void set(bool bval);
86 
88 
90 
91  bool get(std::string& s) const;
98  bool get(bool& b) const;
102  bool get(long& t) const;
106  bool get(double& d) const;
107 
110  operator double() const;
111 
114  operator bool() const;
115 
118  operator std::string() const;
119 
122  operator long() const;
123 
126  operator int() const;
127 
130  operator unsigned() const;
131 
134  operator float() const;
135 
136  operator std::vector<DCCLMessageVal>() const;
137 
139  DCCLCppType type() const { return type_; }
140 
142  bool empty() const { return type_ == cpp_notype; }
143 
144  unsigned precision() const { return precision_; }
145 
147 
149 
150  bool operator==(const DCCLMessageVal& mv) const;
151  bool operator==(const std::string& s) const;
152  bool operator==(double d) const;
153  bool operator==(long l) const;
154  bool operator==(bool b) const;
155 
156  // @}
157 
158  private:
159  void init();
160 
161  friend std::ostream& operator<<(std::ostream& os, const DCCLMessageVal& mv);
162 
163  private:
164  std::string sval_;
165  double dval_;
166  long lval_;
167  bool bval_;
168 
169  unsigned precision_;
170 
171  DCCLCppType type_;
172 };
173 
174 std::ostream& operator<<(std::ostream& os, const DCCLMessageVal& mv);
175 std::ostream& operator<<(std::ostream& os, const std::vector<DCCLMessageVal>& vm);
176 } // namespace transitional
177 
178 } // namespace goby
179 
180 #endif
DCCLCppType type() const
what type is the original type of this DCCLMessageVal?
Definition: message_val.h:139
bool empty() const
was this just constructed with DCCLMessageVal() ?
Definition: message_val.h:142
DCCLCppType
Enumeration of C++ types used in DCCL.
The global namespace for the Goby project.