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 // MOOSFileReader.h: interface for the CMOOSFileReader class. 00031 // 00033 #ifdef _WIN32 00034 #pragma warning(disable : 4786) 00035 #pragma warning(disable : 4503) 00036 #endif 00037 00038 #if !defined(AFX_MOOSFILEREADER_H__B355D791_3CC0_4612_B755_020A269204F2__INCLUDED_) 00039 #define AFX_MOOSFILEREADER_H__B355D791_3CC0_4612_B755_020A269204F2__INCLUDED_ 00040 00041 #if _MSC_VER > 1000 00042 #pragma once 00043 #endif // _MSC_VER > 1000 00044 00045 //#include "MOOSLock.h" 00046 #include <fstream> 00047 #include <string> 00048 #include <map> 00049 //using namespace std; 00050 00051 #ifdef _WIN32 00052 typedef std::map<int,std::ifstream*> THREAD2FILE_MAP; 00053 #else 00054 typedef std::map<pthread_t,std::ifstream *> THREAD2FILE_MAP; 00055 #endif 00056 00057 00058 00059 class CMOOSLock; 00060 00062 class CMOOSFileReader 00063 { 00064 public: 00065 CMOOSFileReader(); 00066 virtual ~CMOOSFileReader(); 00067 00068 /* true if file is open */ 00069 bool IsOpen(); 00070 00071 /* Goto a given line*/ 00072 bool GoTo(std::string sLine); 00073 00074 /* returns true if file reader is eof*/ 00075 bool eof(); 00076 00077 /* reset everything */ 00078 bool Reset(); 00079 00081 bool GetValue(std::string sName,std::string & sResult); 00083 bool GetValue(std::string sName,double & dfResult); 00085 bool GetValue(std::string sName,int & nResult); 00087 bool GetValue(std::string sName,float & fResult); 00089 bool GetValue(std::string sName,bool & bResult); 00091 bool GetValue(std::string sName,unsigned int & nResult); 00092 00093 00094 00096 bool SetFile(const std::string & sFile); 00098 static bool GetTokenValPair(std::string sLine, std::string &sTok, std::string & sVal,bool bPreserveWhiteSpace = false); 00099 00101 std::string GetNextValidLine(bool bDoShellSubstitution = true); 00102 00103 00104 bool DoVariableExpansion(std::string & sVal); 00105 bool BuildLocalShellVars(); 00106 bool MakeOverloadedCopy(const std::string & sCopyName,std::map<std::string, std::string> & OverLoads); 00107 void EnableVerbatimQuoting(bool bEnable=true){m_bEnableVerbatimQuoting = bEnable;}; 00108 00109 00110 protected: 00112 void ClearFileMap() 00113 { 00114 for(THREAD2FILE_MAP::iterator iter = m_FileMap.begin(); iter != m_FileMap.end(); iter++) 00115 { 00116 std::ifstream * pFile = iter->second; 00117 if(pFile) 00118 delete pFile; 00119 } 00120 m_FileMap.clear(); 00121 } 00122 00123 00124 std::ifstream * GetFile(); 00125 CMOOSLock *m_pLock; 00126 static bool IsComment(std::string & sLine); 00127 std::string m_sFileName; 00128 std::ifstream m_File; 00129 00130 std::map<std::string,std::string> m_LocalShellVariables; 00132 THREAD2FILE_MAP m_FileMap; 00133 00134 //true if quoted strings are treated as literals - quotes will be removed and comment "//" 00135 //characters not treated as comments 00136 bool m_bEnableVerbatimQuoting; 00137 00138 }; 00139 00140 #endif // !defined(AFX_MOOSFILEREADER_H__B355D791_3CC0_4612_B755_020A269204F2__INCLUDED_)