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/dccl_constants.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 DCCLConstants20091211H
00021 #define DCCLConstants20091211H
00022 
00023 #include <string>
00024 #include <bitset>
00025 #include <limits>
00026 #include <vector>
00027 
00028 #include "goby/acomms/acomms_constants.h"
00029 
00030 namespace goby
00031 {
00032 
00033     namespace acomms
00034     {
00035 
00037         enum DCCLType { dccl_static, 
00038                         dccl_bool, 
00039                         dccl_int, 
00040                         dccl_float, 
00041                         dccl_enum, 
00042                         dccl_string, 
00043                         dccl_hex  
00044         };
00046         enum DCCLCppType { cpp_notype,
00047                            cpp_bool,
00048                            cpp_string,
00049                            cpp_long,
00050                            cpp_double
00051         };
00052 
00053 
00054         // 2^3 = 8
00055         enum { POWER2_BITS_IN_BYTE = 3 };
00056         inline unsigned bits2bytes(unsigned bits) { return bits >> POWER2_BITS_IN_BYTE; }
00057         inline unsigned bytes2bits(unsigned bytes) { return bytes << POWER2_BITS_IN_BYTE; }
00058     
00059         // 2^1 = 2
00060         enum { POWER2_NIBS_IN_BYTE = 1 };
00061         inline unsigned bytes2nibs(unsigned bytes) { return bytes << POWER2_NIBS_IN_BYTE; }
00062         inline unsigned nibs2bytes(unsigned nibs) { return nibs >> POWER2_NIBS_IN_BYTE; }
00063 
00064 
00065         inline std::string type_to_string(DCCLType type)
00066         {
00067             switch(type)
00068             {
00069                 case dccl_int:    return "int";
00070                 case dccl_hex:    return "hex";
00071                 case dccl_bool:   return "bool";
00072                 case dccl_string: return "string";
00073                 case dccl_float:  return "float";
00074                 case dccl_static: return "static";
00075                 case dccl_enum:   return "enum";
00076             }
00077             return "notype";
00078         }
00079 
00080         inline std::string type_to_string(DCCLCppType type)
00081         {
00082             switch(type)
00083             {
00084                 case cpp_long:   return "long";
00085                 case cpp_double: return "double";
00086                 case cpp_string: return "string";
00087                 case cpp_bool:   return "bool";
00088                 case cpp_notype: return "no_type";
00089             }
00090             return "notype";
00091         }
00092     }
00093 }
00094 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends