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
00027
00028
00029 #ifndef SIENA_TYPES_H
00030 #define SIENA_TYPES_H
00031
00055 namespace siena {
00063 enum operator_id {
00065 eq_id = 1,
00072 lt_id = 2,
00074 gt_id = 3,
00083 sf_id = 4,
00092 pf_id = 5,
00101 ss_id = 6,
00102
00107 any_id = 7,
00109 ne_id = 8,
00110
00122 re_id = 9
00123 };
00124
00131 enum type_id {
00132 string_id = 1,
00133 int_id = 2,
00134 double_id = 3,
00135 bool_id = 4,
00136 anytype_id = 5
00137 };
00138
00139 typedef long long int int_t;
00140 typedef double double_t;
00141 typedef bool bool_t;
00155 class string_t {
00156 public:
00168 class iterator {
00169 const string_t *s;
00170 const char *p;
00171 iterator (const string_t *str, const char *where) throw () :
00172 s (str), p (where) { }
00173
00174 public:
00178 static iterator begin (const string_t &s) throw () {
00179 return iterator (&s, s.begin);
00180 }
00181
00185 static iterator end (const string_t &s) throw () {
00186 return iterator (&s, s.end);
00187 }
00188
00192 iterator (const iterator &i) throw () : s (i.s), p (i.p) { }
00193
00200 bool operator <(const iterator &i) const throw () {
00201 return p < i.p;
00202 }
00203
00210 bool operator <=(const iterator &i) const throw () {
00211 return p <= i.p;
00212 }
00213
00220 bool operator >(const iterator &i) const throw () {
00221 return p > i.p;
00222 }
00223
00230 bool operator >=(const iterator &i) const throw () {
00231 return p >= i.p;
00232 }
00233
00239 bool operator ==(const iterator &i) const throw () {
00240 return p == i.p;
00241 }
00242
00248 bool operator !=(const iterator &i) const throw () {
00249 return p != i.p;
00250 }
00251
00253 iterator &operator =(const iterator &i) throw () {
00254 s = i.s;
00255 p = i.p;
00256 return *this;
00257 }
00258
00264 const char &operator *() const throw () {
00265 return *p;
00266 }
00267
00273 const char &operator [](int n) const throw () {
00274 return *(p + n);
00275 }
00276
00278 iterator &operator += (int n) throw () {
00279 p += n; return *this;
00280 }
00281
00283 iterator operator +(int n) const throw () {
00284 return iterator (s, p + n);
00285 }
00286
00288 iterator &operator ++() throw () {
00289 ++p; return *this;
00290 }
00291
00293 iterator operator ++(int) throw () {
00294 iterator i = *this; ++p; return i;
00295 }
00296
00298 iterator& operator -= (int n) throw () {
00299 p -= n; return *this;
00300 }
00301
00303 iterator operator -(int n) const throw () {
00304 return iterator (s, p - n);
00305 }
00306
00313 int operator -(const iterator &i) const throw () {
00314 return i.p - p;
00315 }
00316
00318 iterator &operator --() throw () {
00319 --p; return *this;
00320 }
00321
00323 iterator operator --(int) throw () {
00324 iterator i = *this; --p; return i;
00325 }
00326
00330 int at_end () const throw () {
00331 return p == s->end;
00332 }
00333
00339 int index () const throw () {
00340 return p - s->begin;
00341 }
00342
00348 void set_index (int index) throw () {
00349 p = s->begin + index;
00350 }
00351 };
00352
00354 const char * begin;
00356 const char * end;
00357
00359 string_t() throw() : begin(0), end(0) {}
00361 string_t(const char * b, const char * e) throw() : begin(b), end(e) {}
00365 string_t(const char * s) throw()
00366 : begin(s), end(s) { while(*end != 0) ++end; }
00368 string_t(const char * s, int len) throw() : begin(s), end(s + len) {}
00376 string_t(const string_t & x) throw() : begin(x.begin), end(x.end) {}
00383 string_t & operator = (const string_t x) throw() {
00384 begin= x.begin; end = x.end; return *this;
00385 }
00390 string_t & assign(const char * b, const char * e) throw() {
00391 begin = b; end = e; return *this;
00392 }
00393
00395 unsigned int length() const throw() { return end - begin; }
00396
00398 const char &operator [] (int x) const throw() {
00399 return begin[x];
00400 }
00401
00403 bool operator == (const string_t & x) const throw() {
00404 if (length() != x.length()) return false;
00405 const char * i = begin;
00406 const char * j = x.begin;
00407 while(i != end)
00408 if (*i++ != *j++) return false;
00409 return true;
00410 }
00411
00417 bool operator < (const string_t & x) const throw() {
00418 const char * i = begin;
00419 const char * j = x.begin;
00420 while(i != end) {
00421 if (j == x.end) return false;
00422 if (*i < *j) return true;
00423 if (*i > *j) return false;
00424 ++i;
00425 ++j;
00426 }
00427 return j != x.end;
00428 }
00429
00435 bool operator > (const string_t & x) const throw() {
00436 return x < *this;
00437 }
00438
00441 bool operator != (const string_t & x) const throw() {
00442 return !(*this == x);
00443 }
00444
00447 bool has_prefix (const string_t & x) const throw();
00448
00451 bool has_suffix (const string_t & x) const throw();
00452
00455 bool has_substring (const string_t & x) const throw();
00456 };
00457
00462 class value {
00463 public:
00465 virtual ~value() {};
00470 virtual type_id type() const = 0;
00477 virtual int_t int_value() const = 0;
00484 virtual string_t string_value() const = 0;
00485
00492 virtual bool_t bool_value() const = 0;
00499 virtual double_t double_value() const = 0;
00500 };
00501
00507 class attribute : public value {
00508 public:
00510 virtual ~attribute() {};
00512 virtual string_t name() const = 0;
00513 };
00514
00521 class constraint : public attribute {
00522 public:
00524 virtual ~constraint() {};
00526 virtual operator_id op() const = 0;
00527
00533 virtual bool covers(const attribute & a) const throw();
00534 };
00535
00542 class message {
00543 public:
00545 virtual ~message() {};
00556 class iterator : public attribute {
00557 public:
00571 virtual bool next() = 0;
00573 virtual ~iterator() {};
00574 };
00575
00585 virtual iterator * first() const = 0;
00586
00596 virtual attribute * find(const string_t &) const = 0;
00597
00599 virtual bool contains(const string_t &) const = 0;
00600 };
00601
00609 class filter {
00610 public:
00612 virtual ~filter() {};
00617 class iterator : public constraint {
00618 public:
00631 virtual bool next() = 0;
00633 virtual ~iterator() {};
00634 };
00640 virtual iterator * first() const = 0;
00641
00649 virtual bool covers(const message & m) const throw();
00650 };
00651
00659 class predicate {
00660 public:
00662 virtual ~predicate() {};
00663
00668 class iterator : public filter {
00669 public:
00682 virtual bool next() = 0;
00684 virtual ~iterator() {};
00685 };
00686
00692 virtual iterator * first() const = 0;
00693
00701 virtual bool covers(const message & m) const throw();
00702 };
00703
00704 }
00705
00706 #endif