Goby v2
message_var_float.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_VAR_FLOAT20100317H
24 #define MESSAGE_VAR_FLOAT20100317H
25 
26 #include "goby/util/as.h"
27 
28 #include "message_var.h"
29 
30 #include <boost/math/special_functions/fpclassify.hpp>
31 
32 namespace goby
33 {
34 namespace transitional
35 {
37 {
38  public:
39  DCCLMessageVarFloat(double max = std::numeric_limits<double>::max(), double min = 0,
40  double precision = 0);
41 
42  void set_max(double max) { max_ = max; }
43  void set_max(const std::string& s) { set_max(util::as<double>(s)); }
44 
45  void set_min(double min) { min_ = min; }
46  void set_min(const std::string& s) { set_min(util::as<double>(s)); }
47 
48  void set_precision(int precision) { precision_ = precision; }
49  void set_precision(const std::string& s) { set_precision(util::as<int>(s)); }
50 
51  int precision() const { return precision_; }
52 
53  double min() const { return min_; }
54  double max() const { return max_; }
55 
56  void set_max_delta(double max_delta) { max_delta_ = max_delta; }
57  void set_max_delta(const std::string& s) { set_max_delta(util::as<double>(s)); }
58 
59  virtual DCCLType type() const { return dccl_float; }
60 
61  protected:
62  virtual DCCLMessageVal cast(double d, int precision) { return DCCLMessageVal(d, precision); }
63  virtual void initialize_specific();
64 
65  virtual void pre_encode(DCCLMessageVal& v);
66 
67  private:
68  bool is_delta() const { return using_delta_differencing() && !is_key_frame_; }
69 
70  bool using_delta_differencing() const { return !(boost::math::isnan)(max_delta_); }
71 
72  private:
73  double max_;
74  double min_;
75  int precision_;
76 
77  double max_delta_;
78 };
79 
80 } // namespace transitional
81 } // namespace goby
82 #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.