MOOS 0.2375
/home/toby/moos-ivp/MOOS-2375-Oct0611/Tools/Graphical/uMS/DBImage.h
Go to the documentation of this file.
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 Utility 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 // DBImage.h: interface for the CDBImage class.
00031 
00032 //
00033 
00035 
00036 #ifdef _WIN32
00037     #pragma warning(disable : 4786)
00038 #endif
00039 
00040 
00041 #if !defined(AFX_DBIMAGE_H__E4F9EC4D_7049_4EC8_86BA_0AF21BBCA23C__INCLUDED_)
00042 
00043 #define AFX_DBIMAGE_H__E4F9EC4D_7049_4EC8_86BA_0AF21BBCA23C__INCLUDED_
00044 
00045 #if _MSC_VER > 1000
00046 #pragma once
00047 #endif // _MSC_VER > 1000
00048 
00049 #include <MOOSLIB/MOOSLib.h>
00050 #include <string>
00051 #include <map>
00052 #include <vector>
00053 
00054 
00055 class CDBImage
00056 {
00057 public:
00058     bool Clear();
00059 
00060     CDBImage()
00061     {
00062         m_bShowPending = false;
00063     }
00064 
00065     struct ProcInfo
00066     {
00067         std::string m_sName;
00068         STRING_LIST m_Published;
00069         STRING_LIST m_Subscribed;
00070     };
00071 
00072     typedef std::map<std::string,ProcInfo> PROC_INFO_MAP;
00073 
00074     class CVar
00075 
00076     {
00077     public:
00078         CVar()
00079         {
00080             m_dfTime = -1;
00081         }
00082 
00083         CVar(CMOOSMsg & rMsg)
00084         {
00085             m_dfTime = rMsg.m_dfTime;
00086             switch(rMsg.m_cDataType)
00087             {
00088             case MOOS_STRING:
00089                 m_eType = STR;
00090                 break;
00091             case MOOS_DOUBLE:
00092                 m_eType = DBL;
00093                 break;
00094             case MOOS_BINARY_STRING:
00095                 m_eType = BIN;
00096                 break;
00097             default:
00098                 m_eType = UNKNOWN;
00099             }
00100             m_sStr = rMsg.GetAsString();
00101             m_sCommunity = rMsg.m_sOriginatingCommunity;
00102             m_sName = rMsg.m_sKey;
00103             m_sFreq = MOOSFormat("%.1f",rMsg.m_dfVal2);
00104             m_sSource = rMsg.m_sSrc;
00105             m_bChanged = false;
00106         }
00107 
00108         std::string GetTime(){return MOOSFormat("%.3f",m_dfTime);};
00109         double GetTimeVal(){return m_dfTime;};
00110         std::string GetValue(){return m_eType==UNKNOWN?"":m_sStr;};
00111         std::string GetCommunity(){return m_sCommunity;};
00112         std::string GetName(){return m_sName;};
00113         std::string GetFrequency(){return m_sFreq;};
00114         std::string GetSource(){return m_sSource;};
00115         bool IsChanged(){return m_bChanged;};
00116         void Changed(bool b){m_bChanged = b;};
00117         std::string GetType()
00118         {
00119             switch(m_eType)
00120             {
00121             case STR:
00122                 return "$";
00123             case DBL:
00124                 return "D";
00125             case BIN:
00126                 return "B";
00127             default:
00128                 return "?";
00129             }
00130         }
00131 
00132 
00133     protected:
00134         double m_dfTime;
00135         std::string m_sStr;
00136         enum Type{ STR,DBL,BIN,UNKNOWN};
00137         Type m_eType;
00138         std::string m_sCommunity;
00139         std::string m_sSrc;
00140         std::string m_sName;
00141         std::string m_sFreq;
00142         std::string m_sSource;
00143         bool m_bChanged;
00144     };
00145 
00146     bool Set(MOOSMSG_LIST & InMail);
00147     bool Get(CVar & rVar, int n);
00148     bool HasChanged(int n);
00149     bool SetProcInfo(MOOSMSG_LIST & InMail) ;
00150     bool GetProcesses(STRING_LIST & sProcs);
00151     int GetNumVariables(){return m_DBData.size();}
00152     bool GetProcInfo(const std::string & sWhat,STRING_LIST & sSubs,STRING_LIST & sPubs);
00153     bool SetMask(std::set<std::string> Mask);
00154     bool ShowPending(bool b){m_bShowPending = b;return true;};
00155 protected:
00156     int GetIndex(const std::string & sName);
00157     std::vector<CVar> m_DBData;
00158     std::map<std::string,int> m_IndexMap;
00159     std::set<std::string> m_Mask;
00160 
00161     bool m_bShowPending ;
00162     int m_nClients;
00163     int m_nVariables;
00164     PROC_INFO_MAP m_Processes;
00165     CMOOSLock m_Lock;
00166 };
00167 
00168 
00169 #endif // !defined(AFX_DBIMAGE_H__E4F9EC4D_7049_4EC8_86BA_0AF21BBCA23C__INCLUDED_)
00170 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines