#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 set<CRITERIUM>& | criteria () const |
const Expression* | select () const |
unsigned int | 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<CRITERIUM> | criteria_ |
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 10 of file configuration.C. 00010 : format_(NONE), max_level_(0), select_(0) { 00011 } |
|
Definition at line 13 of file configuration.C. 00013 { 00014 delete select_; 00015 } |
|
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 LogRecord::parse_line().
00019 { return criteria_; } |
|
Definition at line 20 of file configuration.h. Referenced by main(), and operator<<().
00020 { return select_; } |
|
Definition at line 27 of file configuration.C. Referenced by main().
00027 { 00028 string word; // first word on the line 00029 bool ok(true); 00030 criteria_.clear(); 00031 unsigned int lineno(1); 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 if (format_!=NONE) // a format_ is already there 00039 return lineno; 00040 ok = parse_format(is); 00041 } 00042 else if (word=="select") 00043 ok = parse_select(is); 00044 else if (word=="exclude") 00045 ok = parse_exclude(is); 00046 else 00047 return lineno; 00048 if (!ok) 00049 return lineno; 00050 ++lineno; 00051 } 00052 return 0; 00053 } |
|
Definition at line 56 of file configuration.C. Referenced by parse().
00056 { 00057 format_ = parse_criterium(is); 00058 if (format_ == NONE) 00059 return false; 00060 criteria_.insert(format_); 00061 if (parse_levels(is,levels_)) { 00062 if (levels_.size()==0) { // insert default 00063 levels_.insert(1); 00064 levels_.insert(2); 00065 levels_.insert(3); 00066 } 00067 // compute max_level_ 00068 max_level_ = *(max_element(levels_.begin(),levels_.end())); 00069 } 00070 return true; 00071 } |
|
Definition at line 74 of file configuration.C. Referenced by parse().
00074 { 00075 Expression* e(parse_expression(is)); 00076 if (e) { 00077 add_expression(e); 00078 return true; 00079 } 00080 return false; 00081 } |
|
Definition at line 133 of file configuration.C. Referenced by parse().
00133 { 00134 Expression* e(parse_expression(is)); 00135 if (e) { 00136 add_expression(new NotExpression(e)); 00137 return true; 00138 } 00139 return false; 00140 } |
|
Definition at line 85 of file configuration.C. Referenced by parse_exclude(), and parse_select().
00085 { 00086 CRITERIUM crit = parse_criterium(is); 00087 if (crit == NONE) 00088 return false; 00089 criteria_.insert(crit); 00090 string pattern; // rest of line 00091 if (!getline(is,pattern)) 00092 return false; 00093 // remove leading blanks or tabs 00094 if (pattern.size()) { // remove leading and trailing blanks and tabs 00095 string::size_type n0(pattern.find_first_not_of(" \t")); 00096 if (n0) 00097 pattern.erase(0,n0); 00098 if (pattern.size()) { 00099 string::size_type n1(pattern.find_last_not_of(" \t")); 00100 if (n1<(pattern.size()-1)) 00101 pattern.erase(n1+1); 00102 } 00103 } 00104 if (pattern.size()==0) 00105 return false; 00106 switch (crit) { 00107 case DATE: { 00108 DatePattern dp; 00109 if (!dp.parse(pattern)) 00110 return false; 00111 return new DateExpression(dp); 00112 } 00113 break; 00114 case DOMAIN: { 00115 Domain d; 00116 if (!d.parse(pattern)) 00117 return false; 00118 return new DomainExpression(d); 00119 } 00120 break; 00121 case PATH: { 00122 Path p; 00123 if (!p.parse(pattern)) 00124 return false; 00125 return new PathExpression(p); 00126 } 00127 break; 00128 default: return false; 00129 } 00130 } |
|
Definition at line 143 of file configuration.C. Referenced by parse_expression(), and parse_format().
00143 { 00144 string word; 00145 if (is >> word) { 00146 if (word=="path") 00147 return PATH; 00148 else if (word=="date") 00149 return DATE; 00150 else if (word=="domain") 00151 return DOMAIN; 00152 else 00153 return NONE; 00154 } 00155 return NONE; 00156 } |
|
Definition at line 159 of file configuration.C. Referenced by parse_format().
00159 { 00160 levels.clear(); 00161 string line; 00162 if (!getline(is,line)) 00163 return false; 00164 const char* cline(line.c_str()); 00165 const char* start(0); 00166 // The const_cast is needed because strtol's 3rd is wrongly types as char**. 00167 char* end(const_cast<char*>(cline)); 00168 00169 while (start!=end) { 00170 start = end; 00171 long l = strtol(start,&end,10); 00172 if (start!=end) { 00173 if (l<0) 00174 return false; 00175 unsigned int u1(static_cast<unsigned int>(l)); 00176 levels.insert(u1); 00177 if (*end=='-') { // a range like 1-4 00178 start = end+1; 00179 if (*start=='\0') // syntax error: something like '1-' 00180 return false; 00181 long l2 = strtol(start,&end,10); 00182 if (start==end) // syntax error: something like '1-asda' 00183 return false; 00184 if (l2<0) 00185 return false; 00186 unsigned int u2(static_cast<unsigned int>(l2)); 00187 for (unsigned int u=u1+1; u<=u2; ++u) 00188 levels.insert(u); 00189 } 00190 } 00191 } 00192 return true; 00193 } |
|
Definition at line 18 of file configuration.C. Referenced by parse_exclude(), and parse_select().
00018 { 00019 if (e) { 00020 if (!select_) 00021 select_ = new AndExpression(); 00022 select_->add(e); 00023 } 00024 } |
|
Definition at line 196 of file configuration.C. |
|
Definition at line 37 of file configuration.h. |
|
Definition at line 38 of file configuration.h. |
|
Definition at line 39 of file configuration.h. |
|
Definition at line 40 of file configuration.h. |
|
Definition at line 41 of file configuration.h. |