Note: Goby version 1 (shown here) is now considered obsolete. Please use version 2 for new projects, and consider upgrading old projects.

Goby Underwater Autonomy Project  Series: 1.1, revision: 163, released on 2013-02-06 14:23:27 -0500
acomms/libdccl/message_val.h
00001 // copyright 2008, 2009 t. schneider tes@mit.edu
00002 // 
00003 // this file is part of the Dynamic Compact Control Language (DCCL),
00004 // the goby-acomms codec. goby-acomms is a collection of libraries 
00005 // for acoustic underwater networking
00006 //
00007 // This program is free software: you can redistribute it and/or modify
00008 // it under the terms of the GNU General Public License as published by
00009 // the Free Software Foundation, either version 3 of the License, or
00010 // (at your option) any later version.
00011 //
00012 // This software is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with this software.  If not, see <http://www.gnu.org/licenses/>.
00019 
00020 #ifndef MESSAGE_VAL20091211H
00021 #define MESSAGE_VAL20091211H
00022 
00023 #include <iostream>
00024 
00025 #include "dccl_constants.h"
00026 
00027 namespace goby
00028 {
00029     namespace acomms
00030     {
00031     
00033         class DCCLMessageVal
00034         {
00035           public:
00036             enum { MAX_DBL_PRECISION = 15 };
00037         
00039 
00040 
00041             DCCLMessageVal();
00042         
00044             DCCLMessageVal(const std::string& s);
00045         
00047             DCCLMessageVal(const char* s);
00048         
00050             DCCLMessageVal(double d, int p = MAX_DBL_PRECISION);
00051         
00053             DCCLMessageVal(long l);
00054         
00056             DCCLMessageVal(int i);
00057         
00059             DCCLMessageVal(float f);
00060         
00062             DCCLMessageVal(bool b);
00063 
00065             DCCLMessageVal(const std::vector<DCCLMessageVal>& vm);
00066 
00067         
00068         
00070 
00072 
00073 
00074             void set(std::string sval);
00078             void set(double dval, int precision = MAX_DBL_PRECISION);
00080             void set(long lval);
00082             void set(bool bval);
00083 
00085         
00087 
00088 
00089 
00090 
00091             bool get(std::string& s) const;
00095             bool get(bool& b) const;
00099             bool get(long& t) const;        
00103             bool get(double& d) const;
00104 
00107             operator double() const;
00108 
00111             operator bool() const;
00112 
00115             operator std::string() const;
00116 
00119             operator long() const;
00120 
00123             operator int() const;
00124 
00127             operator unsigned() const;
00128 
00131             operator float() const;
00132 
00133             operator std::vector<DCCLMessageVal>() const;
00134         
00135 
00137             DCCLCppType type() const { return type_; }
00138         
00140             bool empty() const { return type_ == cpp_notype; }        
00141 
00142             unsigned precision() const { return precision_; }
00143         
00145 
00146 
00148 
00149             bool operator==(const DCCLMessageVal& mv) const;
00150             bool operator==(const std::string& s) const;  
00151             bool operator==(double d) const;
00152             bool operator==(long l) const;
00153             bool operator==(bool b) const;
00154         
00155             // @}
00156         
00157           private:
00158             void init();
00159         
00160             friend std::ostream& operator<<(std::ostream& os, const DCCLMessageVal& mv);
00161         
00162           private:
00163             std::string sval_;
00164             double dval_;
00165             long lval_;
00166             bool bval_;
00167 
00168             unsigned precision_;
00169 
00170             DCCLCppType type_;
00171         };
00172 
00173         std::ostream& operator<<(std::ostream& os, const acomms::DCCLMessageVal& mv);
00174         std::ostream& operator<<(std::ostream& os, const std::vector<acomms::DCCLMessageVal>& vm);
00175     }
00176 
00177 }
00178 
00179 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends