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 #include "conf/conf_int.h"
00027
00028
00029 #include <stdlib.h>
00030 #include <iostream>
00031
00032
00033 #include "text/strings.h"
00034
00035 using namespace std;
00036 using namespace Tanl::Text;
00037
00038 namespace IXE {
00039
00040
00048
00049 conf<int>::conf(char const *name, int default_value, int min, int max)
00050 : VarDefault<int>(name, default_value), min_(min), max_(max)
00051 { }
00052
00053
00060
00061 conf<int>&
00062 conf<int>::operator =(int new_value)
00063 {
00064 if (new_value >= min_ && new_value <= max_) {
00065 value = new_value;
00066 return *this;
00067 }
00068
00069 cerr << "Configuration error: " << '"' << name() << "\" value \""
00070 << new_value << "\" not in range [" << min_ << '-';
00071 if (max_ == INT_MAX)
00072 cerr << "infinity";
00073 else
00074 Configuration::error() << max_; cerr << ']' << endl;
00075 return *this;
00076 }
00077
00078
00088
00089
00090 void
00091 conf<int>::parseValue(char const*& lines)
00092 {
00093 if (!lines || !*lines) {
00094 Configuration::error() << "Configuration error: " << '"' << name() << "\" has no value" << endl;
00095 return;
00096 }
00097
00098 char const* line = next_token_line(lines, " \t\r");
00099 if (!strncasecmp(line, "infinity", 8)) {
00100 operator =(INT_MAX);
00101 return;
00102 }
00103 int const n = ::atoi(line);
00104 if (n || *line == '0') {
00105 operator =(n);
00106 return;
00107 }
00108 Configuration::error() << "Configuration error: " << '"' << name() << "\" has a non-numeric value" << endl;
00109 }
00110
00111 }