Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 #include <telekyb_base/File/File.hpp>
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 #include <boost/tokenizer.hpp>
00037 
00038 
00039 #include <ros/console.h>
00040 
00041 
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         
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         
00074         std::string line;
00075         while(std::getline(file, line)) {
00076                 
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 } 
00092 
00093