Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

Configuration Class Reference

A Configuration object represents the httpstats configuration. More...

#include <configuration.h>

List of all members.

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 Expressionselect () const
unsigned int parse (istream &)

Protected Methods

bool parse_format (istream &)
bool parse_select (istream &)
bool parse_exclude (istream &)
Expressionparse_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_
AndExpressionselect_

Friends

ostream& operator<< (ostream &,const Configuration &)


Detailed Description

A Configuration object represents the httpstats configuration.

Definition at line 10 of file configuration.h.


Member Enumeration Documentation

enum Configuration::CRITERIUM
 

Enumeration values:
DATE  
PATH  
DOMAIN  
NONE  

Definition at line 12 of file configuration.h.

00012 { DATE, PATH, DOMAIN, NONE };


Constructor & Destructor Documentation

Configuration::Configuration ( )
 

Definition at line 10 of file configuration.C.

00010                             : format_(NONE), max_level_(0), select_(0) {
00011 }

Configuration::~Configuration ( )
 

Definition at line 13 of file configuration.C.

00013                               {
00014 delete select_;
00015 }


Member Function Documentation

CRITERIUM Configuration::format ( ) const [inline]
 

Definition at line 16 of file configuration.h.

Referenced by Stats::add(), and operator<<().

00016 { return format_; }

unsigned int Configuration::max_level ( ) const [inline]
 

Definition at line 17 of file configuration.h.

Referenced by Stats::add().

00017 { return max_level_; }

const set< unsigned int > & Configuration::levels<unsigned int> ( ) const [inline]
 

Definition at line 18 of file configuration.h.

Referenced by Stats::add(), and operator<<().

00018 { return levels_; }

const Expression * Configuration::select ( ) const [inline]
 

Definition at line 19 of file configuration.h.

Referenced by main(), and operator<<().

00019 { return select_; }

unsigned int Configuration::parse ( istream & is )
 

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 unsigned int lineno(1);
00031 while (is >> word) { // while we can read the first word of a line
00032   if (word.size() && word[0]=='#') { // comment, just skip until the end of the line
00033     string junk;
00034     getline(is,junk);
00035     }
00036   else if (word=="format") {
00037     if (format_!=NONE) // a format_ is already there
00038       return lineno;
00039     ok = parse_format(is);
00040     }
00041   else if (word=="select")
00042     ok = parse_select(is);
00043   else if (word=="exclude")
00044     ok = parse_exclude(is);
00045   else
00046     return lineno;
00047   if (!ok)
00048     return lineno;
00049   ++lineno;
00050   }
00051 return 0;
00052 }

bool Configuration::parse_format ( istream & is ) [protected]
 

Definition at line 55 of file configuration.C.

Referenced by parse().

00055                                        {
00056 format_ = parse_criterium(is);
00057 if (format_ == NONE)
00058   return false;
00059 if (parse_levels(is,levels_))  {
00060   if (levels_.size()==0) { // insert default
00061     levels_.insert(1);
00062     levels_.insert(2);
00063     levels_.insert(3);
00064     }
00065   // compute max_level_
00066   max_level_ = *(max_element(levels_.begin(),levels_.end()));
00067   }
00068 return true;
00069 }

bool Configuration::parse_select ( istream & is ) [protected]
 

Definition at line 72 of file configuration.C.

Referenced by parse().

00072                                        {
00073 Expression* e(parse_expression(is));
00074 if (e) {
00075   add_expression(e);
00076   return true;
00077   }
00078 return false;
00079 }

bool Configuration::parse_exclude ( istream & is ) [protected]
 

Definition at line 130 of file configuration.C.

Referenced by parse().

00130                                         {
00131 Expression* e(parse_expression(is));
00132 if (e) {
00133   add_expression(new NotExpression(e));
00134   return true;
00135   }
00136 return false;
00137 }

Expression * Configuration::parse_expression ( istream & is ) [protected]
 

Definition at line 83 of file configuration.C.

Referenced by parse_exclude(), and parse_select().

00083                                            {
00084 CRITERIUM crit = parse_criterium(is);
00085 if (crit == NONE)
00086   return 0;
00087 string pattern; // rest of line
00088 if (!getline(is,pattern))
00089   return 0;
00090 // remove leading blanks or tabs
00091 if (pattern.size()) { // remove leading and trailing blanks and tabs
00092   string::size_type n0(pattern.find_first_not_of(" \t"));
00093   if (n0)
00094     pattern.erase(0,n0);
00095   if (pattern.size()) {
00096     string::size_type n1(pattern.find_last_not_of(" \t"));
00097     if (n1<(pattern.size()-1)) 
00098       pattern.erase(n1+1);
00099     }
00100   }
00101 if (pattern.size()==0)
00102   return 0;
00103 switch (crit) {
00104   case DATE: {
00105     DatePattern dp;
00106     if (!dp.parse(pattern))
00107       return 0;
00108     return new DateExpression(dp);
00109     }
00110     break;
00111   case DOMAIN: {
00112     Domain d;
00113     if (!d.parse(pattern))
00114       return 0;
00115     return new DomainExpression(d);
00116     }
00117     break;
00118   case PATH: {
00119     Path p;
00120     if (!p.parse(pattern))
00121       return 0;
00122     return new PathExpression(p);
00123     }
00124     break;
00125   default: return 0;
00126   }
00127 }

CRITERIUM Configuration::parse_criterium ( istream & is ) [protected]
 

Definition at line 140 of file configuration.C.

Referenced by parse_expression(), and parse_format().

00140                                           {
00141 string word;
00142 if (is >> word) {
00143   if (word=="path")
00144     return PATH;
00145   else if (word=="date")
00146     return DATE;
00147   else if (word=="domain")
00148     return DOMAIN;
00149   else 
00150     return NONE;
00151   }
00152 return NONE;
00153 }

bool Configuration::parse_levels ( istream & is,
set< unsigned int > & levels ) [protected]
 

Definition at line 156 of file configuration.C.

Referenced by parse_format().

00156                                                                  {
00157 levels.clear();
00158 string line;
00159 if (!getline(is,line))
00160   return false;
00161 const char* cline(line.c_str());
00162 const char* start(0);
00163 // The const_cast is needed because strtol's 3rd is wrongly types as char**.
00164 char* end(const_cast<char*>(cline));
00165 
00166 while (start!=end) {
00167   start = end;
00168   long l = strtol(start,&end,10);
00169   if (start!=end) {
00170     if (l<0)
00171       return false;
00172     unsigned int u1(static_cast<unsigned int>(l));
00173     levels.insert(u1);
00174     if (*end=='-') { // a range like 1-4
00175       start = end+1;
00176       if (*start=='\0') // syntax error: something like '1-'
00177         return false;
00178       long l2 = strtol(start,&end,10);
00179       if (start==end) // syntax error: something like '1-asda'
00180         return false;
00181       if (l2<0)
00182         return false;
00183       unsigned int u2(static_cast<unsigned int>(l2));
00184       for (unsigned int u=u1+1; u<=u2; ++u) 
00185         levels.insert(u);
00186       }
00187     }
00188   }
00189 return true;
00190 }

void Configuration::add_expression ( Expression * e ) [protected]
 

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 }


Friends And Related Function Documentation

ostream & operator<< ( ostream & os,
const Configuration & conf ) [friend]
 

Definition at line 193 of file configuration.C.

00193                                                   {
00194 os << "format " <<  conf.format() << " ";
00195 copy(conf.levels().begin(),conf.levels().end(),ostream_iterator<unsigned int>(os," "));
00196 os << "\n";
00197 if (conf.select()) 
00198   os << *(conf.select());
00199 return os;
00200 }


Member Data Documentation

CRITERIUM Configuration::format_ [private]
 

Definition at line 36 of file configuration.h.

set< unsigned int > Configuration::levels_<unsigned int> [private]
 

Definition at line 37 of file configuration.h.

unsigned int Configuration::max_level_ [private]
 

Definition at line 38 of file configuration.h.

AndExpression * Configuration::select_ [private]
 

Definition at line 39 of file configuration.h.


The documentation for this class was generated from the following files:
httpstats-stage03 [ 7 April, 2001]