File.cpp
Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 //
00003 // $Id$
00004 //
00005 // Copyright 2008, 2009, 2010, 2011  Antonio Franchi and Paolo Stegagno    
00006 //
00007 // This file is part of MIP.
00008 //
00009 // MIP is free software: you can redistribute it and/or modify
00010 // it under the terms of the GNU General Public License as published by
00011 // the Free Software Foundation, either version 3 of the License, or
00012 // (at your option) any later version.
00013 //
00014 // MIP is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with MIP. If not, see <http://www.gnu.org/licenses/>.
00021 //
00022 // Contact info: antonio.franchi@tuebingen.mpg.de stegagno@dis.uniroma1.it
00023 //
00024 // ----------------------------------------------------------------------------
00025 
00026 
00027 #include <telekyb_base/File/File.hpp>
00028 
00029 
00030 //#include <Tools/TokenReader.h>
00031 // stl
00032 //#include <iostream>
00033 
00034 
00035 // boost
00036 #include <boost/tokenizer.hpp>
00037 
00038 // ros
00039 #include <ros/console.h>
00040 
00041 // defines
00042 #define FILE_COMMENT_CHAR '#'
00043 
00044 namespace TELEKYB_NAMESPACE
00045 {
00046 
00047 typedef boost::tokenizer< boost::escaped_list_separator<char> > Tokenizer;
00048 
00049 File::File(const std::string& fileName_, std::ifstream::openmode mode)
00050 {
00051         fileName = fileName_;
00052         file.open(fileName.c_str(), mode);
00053 
00054         if (!file.is_open())
00055         {
00056                 ROS_WARN_STREAM(fileName << " does not exist!");
00057         }
00058 }
00059 
00060 File::~File()
00061 {
00062         file.close();
00063 }
00064 
00065 bool File::getWords(std::vector<std::string>& wordVector)
00066 {
00067         // exit conditions
00068         if (!file.is_open()) {
00069                 ROS_WARN_STREAM("Cound not get Words from File! " << fileName << " does not exist!");
00070                 return false;
00071         }
00072 
00073         // a line is always a word sparator
00074         std::string line;
00075         while(std::getline(file, line)) {
00076                 // check if line has #. ignore rest
00077                 size_t cPos = line.find( FILE_COMMENT_CHAR );
00078                 line = line.substr(0,cPos);
00079 
00080                 boost::escaped_list_separator<char> sep('\\',' ','\"');
00081                 Tokenizer tokenizer(line,sep);
00082 
00083                 for(Tokenizer::iterator it = tokenizer.begin(); it != tokenizer.end(); it++) {
00084                         wordVector.push_back(*it);
00085                 }
00086         }
00087 
00088         return true;
00089 }
00090 
00091 } // namespace
00092 
00093 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines


telekyb_base
Author(s): Dr. Antonio Franchi and Martin Riedel
autogenerated on Mon Nov 11 2013 11:12:34