#include <configuration.h>
Public Types | |
enum | CRITERIUM { DATE, PATH, DOMAIN, NONE } |
Public Methods | |
Configuration () | |
~Configuration () | |
CRITERIUM | format () const |
unsigned int | max_level () const |
const set<unsigned int>& | levels () const |
const Expression* | select () const |
bool | parse (istream &) |
Protected Methods | |
bool | parse_format (istream &) |
bool | parse_select (istream &) |
bool | parse_exclude (istream &) |
Expression* | parse_expression (istream &) |
CRITERIUM | parse_criterium (istream &) |
bool | parse_levels (istream &,set< unsigned int > &levels) |
void | add_expression (Expression *e) |
Private Attributes | |
CRITERIUM | format_ |
set<unsigned int> | levels_ |
unsigned int | max_level_ |
AndExpression* | select_ |
Friends | |
ostream& | operator<< (ostream &,const Configuration &) |
Definition at line 10 of file configuration.h.
|
Definition at line 12 of file configuration.h. 00012 { DATE, PATH, DOMAIN, NONE }; |
|
Definition at line 12 of file configuration.C. 00012 : format_(DATE), max_level_(0), select_(0) { 00013 } |
|
Definition at line 15 of file configuration.C. 00015 { 00016 delete select_; 00017 } |
|
Definition at line 16 of file configuration.h. Referenced by Stats::add(), and operator<<().
00016 { return format_; } |
|
Definition at line 17 of file configuration.h. Referenced by Stats::add().
00017 { return max_level_; } |
|
Definition at line 18 of file configuration.h. Referenced by Stats::add(), and operator<<().
00018 { return levels_; } |
|
Definition at line 19 of file configuration.h. Referenced by main(), and operator<<().
00019 { return select_; } |
|
Definition at line 29 of file configuration.C. Referenced by main().
00029 { 00030 string word; // first word on the line 00031 bool ok(true); 00032 while (is >> word) { // while we can read the first word of a line 00033 if (word.size() && word[0]=='#') { // comment, just skip until the end of the line 00034 string junk; 00035 getline(is,junk); 00036 } 00037 else if (word=="format") 00038 ok = parse_format(is); 00039 else if (word=="select") 00040 ok = parse_select(is); 00041 else if (word=="exclude") 00042 ok = parse_exclude(is); 00043 else 00044 return false; 00045 if (!ok) 00046 return false; 00047 } 00048 return true; 00049 } |
|
Definition at line 52 of file configuration.C. Referenced by parse().
00052 { 00053 format_ = parse_criterium(is); 00054 if (format_ == NONE) 00055 return false; 00056 if (parse_levels(is,levels_)) { 00057 if (levels_.size()==0) { // insert default 00058 levels_.insert(1); 00059 levels_.insert(2); 00060 levels_.insert(3); 00061 } 00062 // compute max_level_ 00063 max_level_ = *(max_element(levels_.begin(),levels_.end())); 00064 } 00065 return true; 00066 } |
|
Definition at line 69 of file configuration.C. Referenced by parse().
00069 { 00070 Expression* e(parse_expression(is)); 00071 if (e) { 00072 add_expression(e); 00073 return true; 00074 } 00075 return false; 00076 } |
|
Definition at line 127 of file configuration.C. Referenced by parse().
00127 { 00128 Expression* e(parse_expression(is)); 00129 if (e) { 00130 add_expression(new NotExpression(e)); 00131 return true; 00132 } 00133 return false; 00134 } |
|
Definition at line 80 of file configuration.C. Referenced by parse_exclude(), and parse_select().
00080 { 00081 CRITERIUM crit = parse_criterium(is); 00082 if (crit == NONE) 00083 return 0; 00084 string pattern; // rest of line 00085 if (!getline(is,pattern)) 00086 return 0; 00087 // remove leading blanks or tabs 00088 if (pattern.size()) { // remove leading and trailing blanks and tabs 00089 string::size_type n0(pattern.find_first_not_of(" \t")); 00090 if (n0) 00091 pattern.erase(0,n0); 00092 if (pattern.size()) { 00093 string::size_type n1(pattern.find_last_not_of(" \t")); 00094 if (n1<(pattern.size()-1)) 00095 pattern.erase(n1+1); 00096 } 00097 } 00098 if (pattern.size()==0) 00099 return 0; 00100 switch (crit) { 00101 case DATE: { 00102 DatePattern dp; 00103 if (!dp.parse(pattern)) 00104 return 0; 00105 return new DateExpression(dp); 00106 } 00107 break; 00108 case DOMAIN: { 00109 Domain d; 00110 if (!d.parse(pattern)) 00111 return 0; 00112 return new DomainExpression(d); 00113 } 00114 break; 00115 case PATH: { 00116 Path p; 00117 if (!p.parse(pattern)) 00118 return 0; 00119 return new PathExpression(p); 00120 } 00121 break; 00122 default: return 0; 00123 } 00124 } |
|
Definition at line 137 of file configuration.C. Referenced by parse_expression(), and parse_format().
00137 { 00138 string word; 00139 if (is >> word) { 00140 if (word=="path") 00141 return PATH; 00142 else if (word=="date") 00143 return DATE; 00144 else if (word=="domain") 00145 return DOMAIN; 00146 else 00147 return NONE; 00148 } 00149 return NONE; 00150 } |
|
Definition at line 153 of file configuration.C. Referenced by parse_format().
00153 { 00154 levels.clear(); 00155 string line; 00156 if (!getline(is,line)) 00157 return false; 00158 const char* cline(line.c_str()); 00159 const char* start(0); 00160 // The const_cast is needed because strtol's 3rd is wrongly types as char**. 00161 char* end(const_cast<char*>(cline)); 00162 00163 while (start!=end) { 00164 start = end; 00165 long l = strtol(start,&end,10); 00166 if (start!=end) { 00167 if (l<0) 00168 return false; 00169 unsigned int u1(static_cast<unsigned int>(l)); 00170 levels.insert(u1); 00171 if (*end=='-') { // a range like 1-4 00172 start = end+1; 00173 if (*start=='\0') // syntax error: something like '1-' 00174 return false; 00175 long l2 = strtol(start,&end,10); 00176 if (start==end) // syntax error: something like '1-asda' 00177 return false; 00178 if (l2<0) 00179 return false; 00180 unsigned int u2(static_cast<unsigned int>(l2)); 00181 for (unsigned int u=u1+1; u<=u2; ++u) 00182 levels.insert(u); 00183 } 00184 } 00185 } 00186 return true; 00187 } |
|
Definition at line 20 of file configuration.C. Referenced by parse_exclude(), and parse_select().
00020 { 00021 if (e) { 00022 if (!select_) 00023 select_ = new AndExpression(); 00024 select_->add(e); 00025 } 00026 } |
|
Definition at line 190 of file configuration.C. |
|
Definition at line 35 of file configuration.h. |
|
Definition at line 36 of file configuration.h. |
|
Definition at line 37 of file configuration.h. |
|
Definition at line 38 of file configuration.h. |