Goby3 3.2.3
2025.05.13
Loading...
Searching...
No Matches
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
34namespace goby
35{
36namespace moos
37{
38namespace transitional
39{
42{
43 public:
44 enum
45 {
47 };
48
50
51
53
55 DCCLMessageVal(const std::string& s);
56
58 DCCLMessageVal(const char* s);
59
62
65
68
71
74
76 DCCLMessageVal(const std::vector<DCCLMessageVal>& vm);
77
79
81
82
83 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
100 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
180std::ostream& operator<<(std::ostream& os, const DCCLMessageVal& mv);
181std::ostream& operator<<(std::ostream& os, const std::vector<DCCLMessageVal>& vm);
182} // namespace transitional
183} // namespace moos
184} // namespace goby
185
186#endif
DCCLMessageVal(int i)
construct with int value
bool get(long &t) const
extract as long (all reasonable casts are done)
DCCLMessageVal(long l)
construct with long value
void set(double dval, int precision=MAX_DBL_PRECISION)
set the value with a double (overwrites previous value regardless of type)
DCCLMessageVal(const std::vector< DCCLMessageVal > &vm)
construct with vector
DCCLMessageVal(const std::string &s)
construct with string value
bool get(bool &b) const
extract as bool (all reasonable casts are done)
DCCLMessageVal(bool b)
construct with bool value
void set(bool bval)
set the value with a bool (overwrites previous value regardless of type)
bool get(std::string &s) const
extract as std::string (all reasonable casts are done)
bool get(double &d) const
extract as double (all reasonable casts are done)
DCCLMessageVal(double d, int p=MAX_DBL_PRECISION)
construct with double value, optionally givig the precision of the double (number of decimal places) ...
bool operator==(const std::string &s) const
bool empty() const
was this just constructed with DCCLMessageVal() ?
void set(long lval)
set the value with a long (overwrites previous value regardless of type)
bool operator==(const DCCLMessageVal &mv) const
void set(std::string sval)
set the value with a string (overwrites previous value regardless of type)
friend std::ostream & operator<<(std::ostream &os, const DCCLMessageVal &mv)
DCCLMessageVal(float f)
construct with float value
DCCLMessageVal(const char *s)
construct with char* value
DCCLCppType type() const
what type is the original type of this DCCLMessageVal?
DCCLCppType
Enumeration of C++ types used in DCCL.
The global namespace for the Goby project.