Siena Fast Forwarding Documentation (v. 2.0.1)
attributes.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // This file is part of Siena, a wide-area event notification system.
4 // See http://www.inf.usi.ch/carzaniga/siena/
5 //
6 // Authors: Antonio Carzaniga
7 // See the file AUTHORS for full details.
8 //
9 // Copyright (C) 2002-2003 University of Colorado
10 //
11 // Siena is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation, either version 3 of the License, or
14 // (at your option) any later version.
15 //
16 // Siena is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with Siena. If not, see <http://www.gnu.org/licenses/>.
23 //
24 #ifndef SIENA_ATTRIBUTES_H_INCLUDED
25 #define SIENA_ATTRIBUTES_H_INCLUDED
26 
27 #include <exception>
28 #include <string>
29 
62 namespace siena {
70 enum OperatorId {
75  EQ = 1,
82  LT = 2,
87  GT = 3,
96  SF = 4,
105  PF = 5,
114  SS = 6,
115 
120  ANY = 7,
127  NE = 8,
128 
140  RE = 9
141 };
142 
150 enum TypeId {
151  STRING = 1,
152  INT = 2,
153  DOUBLE = 3,
154  BOOL = 4,
155  ANYTYPE = 5
156 };
157 
158 typedef long int Int;
159 typedef double Double;
160 typedef bool Bool;
177 class String {
178 public:
180  const char * begin;
182  const char * end;
183 
185  String() : begin(0), end(0) {}
186 
188  String(const char * b, const char * e) : begin(b), end(e) {}
189 
193  String(const char * s)
194  : begin(s), end(s) { while(*end != 0) ++end; }
195 
197  String(const char * s, int len) : begin(s), end(s + len) {}
198 
206  String(const String & x) : begin(x.begin), end(x.end) {}
207 
214  String & operator = (const String x) {
215  begin= x.begin; end = x.end; return *this;
216  }
217 
222  String & assign(const char * b, const char * e) {
223  begin = b; end = e; return *this;
224  }
225 
227  unsigned int length() const {
228  return end - begin;
229  }
230 
232  const char &operator [] (int x) const {
233  return begin[x];
234  }
235 
237  bool operator == (const String & x) const;
238 
244  bool operator < (const String & x) const;
245 
251  bool operator > (const String & x) const {
252  return x < *this;
253  }
254 
257  bool operator != (const String & x) const {
258  return !(*this == x);
259  }
260 
262  bool has_prefix (const String & x) const;
263 
265  bool has_suffix (const String & x) const;
266 
269  bool has_substring (const String & x) const;
270 
273  std::string & to_string(std::string & s) const;
274 
277  std::string to_string() const;
278 };
279 
307 class Value {
308 public:
310  virtual ~Value() {};
311 
314  virtual TypeId type() const = 0;
315 
324  virtual Int int_value() const = 0;
325 
334  virtual String string_value() const = 0;
335 
344  virtual Bool bool_value() const = 0;
345 
354  virtual Double double_value() const = 0;
355 };
356 
362 class Attribute : public Value {
363 public:
365  virtual ~Attribute() {};
367  virtual String name() const = 0;
368 };
369 
411 class Constraint : public Attribute {
412 public:
414  virtual ~Constraint() {};
416  virtual OperatorId op() const = 0;
417 
423  virtual bool covers(const Attribute & a) const;
424 };
425 
428 class BadConstraint : public std::exception {
429  std::string err_descr;
430 
431 public:
435  BadConstraint(const std::string & e)
436  : err_descr(e) {}
437 
438  virtual ~BadConstraint() throw() {}
439 
442  virtual const char* what() const throw() {
443  return err_descr.c_str();
444  }
445 };
446 
454 class Message {
455 public:
457  virtual ~Message() {};
468  class Iterator : public Attribute {
469  public:
483  virtual bool next() = 0;
485  virtual ~Iterator() {};
486  };
487 
497  virtual Iterator * first() const = 0;
498 
508  virtual Attribute * find(const String &) const = 0;
509 
511  virtual bool contains(const String &) const = 0;
512 };
513 
521 class Filter {
522 public:
524  virtual ~Filter() {};
529  class Iterator : public Constraint {
530  public:
543  virtual bool next() = 0;
545  virtual ~Iterator() {};
546  };
552  virtual Iterator * first() const = 0;
553 
561  virtual bool covers(const Message & m) const;
562 };
563 
571 class Predicate {
572 public:
574  virtual ~Predicate() {};
575 
580  class Iterator : public Filter {
581  public:
594  virtual bool next() = 0;
596  virtual ~Iterator() {};
597  };
598 
604  virtual Iterator * first() const = 0;
605 
613  virtual bool covers(const Message & m) const;
614 };
615 
616 } // end namespace siena
617 
618 #endif