MOOS 0.2375
|
00001 00002 // 00003 // MOOS - Mission Oriented Operating Suite 00004 // 00005 // A suit of Applications and Libraries for Mobile Robotics Research 00006 // Copyright (C) 2001-2005 Massachusetts Institute of Technology and 00007 // Oxford University. 00008 // 00009 // This software was written by Paul Newman at MIT 2001-2002 and Oxford 00010 // University 2003-2005. email: pnewman@robots.ox.ac.uk. 00011 // 00012 // This file is part of a MOOS Core Component. 00013 // 00014 // This program is free software; you can redistribute it and/or 00015 // modify it under the terms of the GNU General Public License as 00016 // published by the Free Software Foundation; either version 2 of the 00017 // License, or (at your option) any later version. 00018 // 00019 // This program is distributed in the hope that it will be useful, 00020 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00022 // General Public License for more details. 00023 // 00024 // You should have received a copy of the GNU General Public License 00025 // along with this program; if not, write to the Free Software 00026 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00027 // 02111-1307, USA. 00028 // 00030 // MOOSVariable.h: interface for the CMOOSVariable class. 00031 // 00033 00034 #ifndef MOOSVARIABLEH 00035 #define MOOSVARIABLEH 00036 00037 #include "MOOSMsg.h" 00038 #include <iomanip> 00039 #include <ostream> 00040 #define DEFAULT_MOOS_VAR_COMMS_TIME 0.2 00041 00042 class CMOOSVariable 00043 { 00044 public: 00045 00047 CMOOSVariable(); 00048 CMOOSVariable(std::string sName, std::string sSubscribe,std::string sPublish,double dfCommsTime = DEFAULT_MOOS_VAR_COMMS_TIME); 00049 virtual ~CMOOSVariable(); 00050 00052 std::string GetAsString(int nFieldWidth = 12) const; 00053 00055 std::string GetWriter() const; 00056 00058 double GetAge(double dfTimeNow) const; 00059 00061 bool Set(const std::string & sVal,double dfTime); 00062 00064 bool Set(double dfVal,double dfTime); 00065 00067 std::string GetName() const; 00068 00070 std::string GetStringVal() const; 00071 00073 double GetTime() const ; 00074 00076 double GetDoubleVal() const ; 00077 00079 bool IsDouble() const; 00080 00082 std::string GetPublishName() const; 00083 00085 bool IsFresh() const ; 00086 00088 bool SetFresh(bool bFresh); 00089 00091 std::string GetSubscribeName() const; 00092 00094 bool Set(const CMOOSMsg & Msg); 00095 00097 double GetCommsTime() const {return m_dfCommsTime;}; 00098 00099 00100 00101 00102 00103 00104 protected: 00105 double m_dfVal; 00106 std::string m_sVal; 00107 bool m_bDouble; 00108 bool m_bFresh; 00109 double m_dfTimeWritten; 00110 double m_dfCommsTime; //time used when registering (how often should we receive updates? 00111 00112 std::string m_sName; 00113 std::string m_sSrc; 00114 std::string m_sSubscribeName; 00115 std::string m_sPublishName; 00116 }; 00117 00119 00120 00121 template <typename _CharT, typename _Traits> 00122 static std::basic_ostream <_CharT, _Traits>& 00123 operator<< (std::basic_ostream <_CharT, _Traits>& OutputStream, const CMOOSVariable& MOOSVar) 00124 { 00125 OutputStream << "name=" << MOOSVar.GetName (); 00126 OutputStream << ", "; 00127 00128 if (MOOSVar.IsDouble ()) 00129 { 00130 OutputStream << "double=" << MOOSVar.GetDoubleVal (); 00131 } 00132 else 00133 { 00134 OutputStream << "string=" << MOOSVar.GetStringVal (); 00135 } 00136 OutputStream << ", "; 00137 OutputStream << std::fixed << std::setprecision (2) << "time=" << MOOSVar.GetTime (); 00138 return OutputStream; 00139 } 00140 00141 #endif