00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifdef HAVE_CONFIG_H
00022 #include <config.h>
00023 #endif
00024 #include "read.h"
00025 #include <iostream>
00026 #include <string>
00027 #include "cfg.h"
00028
00029 using namespace std;
00030
00031 const string Reader::_s_notfound = "key not found";
00032
00033 int Reader::parse(const Reader::AttributeSet& attr, istream &is)
00034 {
00035 while(!is.eof()) {
00036 string line;
00037 getline(is,line);
00038 if(line.length() > 0) {
00039 if( g_getCfg().isVerbose() )
00040 _input += line + " ";
00041 string::size_type eqpos = line.find('=');
00042 if(eqpos != string::npos) {
00043 const string key = line.substr(0,eqpos);
00044 Reader::AttributeSet::const_iterator itr = attr.find(key);
00045 if( itr != attr.end() ) {
00046 const string val = line.substr(eqpos+1,string::npos);
00047 _map.insert(AttributeMap::value_type(key,val));
00048
00049 }
00050 }
00051 } else {
00052 return _map.size();
00053 }
00054 }
00055 return -1;
00056 }
00057 bool Reader::haveAllRequired(const Reader::AttributeSet& attr) const
00058 {
00059 AttributeSet::const_iterator itr;
00060 for(itr=attr.begin(); itr != attr.end(); ++itr) {
00061 if( ! itr->second)
00062 continue;
00063 if( _map.find(itr->first) == _map.end() )
00064 return false;
00065 }
00066 return true;
00067 }
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081