Siena Fast Forwarding documentation (v. 1.0.0)

Main Page   Class Hierarchy   Compound List   File List   Compound Members   Examples  

siena_types.h

00001 // -*- C++ -*-
00002 //
00003 //  This file is part of Siena, a wide-area event notification system.
00004 //  See http://www.cs.colorado.edu/serl/siena/
00005 //
00006 //  Authors: Antonio Carzaniga <[email protected]>
00007 //           Jing Deng <[email protected]>
00008 //  See the file AUTHORS for full details. 
00009 //
00010 //  Copyright (C) 2001-2002 University of Colorado
00011 //
00012 //  This program is free software; you can redistribute it and/or
00013 //  modify it under the terms of the GNU General Public License
00014 //  as published by the Free Software Foundation; either version 2
00015 //  of the License, or (at your option) any later version.
00016 //
00017 //  This program is distributed in the hope that it will be useful,
00018 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //  GNU General Public License for more details.
00021 //
00022 //  You should have received a copy of the GNU General Public License
00023 //  along with this program; if not, write to the Free Software
00024 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
00025 //  USA, or send email to [email protected].
00026 //
00027 //
00028 // $Id: siena_types.h,v 1.6 2002/09/30 04:50:25 carzanig Exp $
00029 //
00030 #ifndef SIENA_TYPES_H
00031 #define SIENA_TYPES_H
00032 
00033 #include <map>
00034 #include <set>
00035 #include <string>
00036 #include <vector>
00037 #include <iostream>
00038 
00039 using namespace std;
00040 
00080 enum sx_operator {
00083     SX_eq               = 1, 
00090     SX_lt               = 2, 
00093     SX_gt               = 3, 
00096     SX_ge               = 4, 
00099     SX_le               = 5, 
00108     SX_sf               = 7,
00117     SX_pf               = 6,
00122     SX_any              = 8, 
00125     SX_ne               = 9, 
00134     SX_ss               = 10 
00135 };
00136 
00139 enum sx_type {
00140     SX_null             = 0,
00141     SX_string           = 1,
00142     SX_int              = 2,
00143     SX_double           = 3,
00144     SX_bool             = 4
00145 };
00146 
00147 //
00148 // I have more optimized representations for these, but for now I will
00149 // use the standard types.
00150 //
00151 typedef string          sx_name;
00152 typedef string          sx_string_t;
00153 typedef int             sx_int_t;
00154 typedef double          sx_double_t;
00155 typedef bool            sx_bool_t;
00156 
00157 typedef string          sx_identity;
00158 
00161 class sx_value {
00162 private:
00163     sx_type             _type;
00164     union {
00165         sx_string_t *   string_v;
00166         sx_int_t        int_v;
00167         sx_bool_t       bool_v;
00168         sx_double_t     double_v;
00169     };
00170 public:
00171     sx_value(): _type(SX_null) {};
00172     ~sx_value() { if (_type == SX_string) delete(string_v); }
00173     sx_value(const sx_value & x): _type(x._type) {
00174         switch (x._type) {
00175         case SX_string: string_v = new string(*x.string_v); break;
00176         case SX_int: int_v = x.int_v; break;
00177         case SX_double: double_v = x.double_v;
00178         case SX_bool: bool_v = x.bool_v;
00179         }
00180     };
00181 
00182     sx_value(sx_int_t x): _type(SX_int) { int_v = x; }
00183     sx_value(sx_bool_t x): _type(SX_bool) { bool_v = x; }
00184     sx_value(sx_double_t x): _type(SX_double) { double_v = x; }
00185     sx_value(const sx_string_t & x): _type(SX_string) { 
00186         string_v = new string(x); }
00187 
00188     sx_type             type()          const { return _type; };
00189     const sx_string_t & string_value()  const { return *string_v; };
00190     sx_int_t            int_value()     const { return int_v; };
00191     sx_bool_t           bool_value()    const { return bool_v; };
00192     sx_double_t         double_value()  const { return double_v; };
00193 
00194     sx_value &          operator = (const sx_value & x) {
00195         switch (x._type) {
00196         case SX_string: return operator = (*x.string_v);
00197         case SX_int: return operator = (x.int_v);
00198         case SX_double: return operator = (x.double_v);
00199         case SX_bool: return operator = (x.bool_v);
00200         }
00201         _type = x._type;
00202     };
00203 
00204     sx_value &          operator = (const string & s) {
00205         if (_type != SX_string) {
00206             _type =  SX_string;
00207             string_v = new string(s);
00208         } else {
00209             *string_v = s;
00210         }
00211         return *this;
00212     }
00213 
00214     sx_value &          operator = (sx_int_t i) {
00215         if (_type == SX_string) {
00216             delete(string_v);
00217         } 
00218         _type = SX_int;
00219         int_v = i;
00220         return *this;
00221     }
00222 
00223     sx_value &          operator = (sx_bool_t b) {
00224         if (_type == SX_string) {
00225             delete(string_v);
00226         } 
00227         _type = SX_bool;
00228         bool_v = b;
00229         return *this;
00230     }
00231 
00232     sx_value &          operator = (sx_double_t d) {
00233         if (_type == SX_string) {
00234             delete(string_v);
00235         } 
00236         _type = SX_double;
00237         double_v = d;
00238         return *this;
00239     }
00240 };
00241 
00242 class sx_attribute {
00243 public:
00244     sx_name     name;
00245     sx_value    value;
00246 };
00247 
00248 class sx_constraint {
00249 public:
00250     sx_name name;
00251     sx_operator op;
00252     sx_value    value;
00253 
00254     sx_constraint() : name(), op(SX_any), value(0) {};
00255 
00256     sx_constraint(const sx_name &n, sx_operator o, const sx_value & v)
00257         : name(n), op(o), value(v) { };
00258 
00259     sx_constraint(const sx_constraint & x)
00260         : name(x.name), op(x.op), value(x.value) {} ; 
00261 };
00262 
00263 struct constraint_comparator {
00264     bool operator() (const sx_constraint & x, const sx_constraint & y) {
00265         return x.name < y.name;
00266     }
00267 };
00268 
00269 class sx_message : public map<sx_name, sx_value> {
00270 };
00271 
00272 // 
00273 // a Filter is a *conjunction* ("and") of constraints 
00274 //
00275 // WARNING: the forwarding table ASSUMES that constraints are
00276 // alphabetically ordered, so be careful when you change this
00277 // definition
00278 // 
00279 class sx_filter : public multiset<sx_constraint, constraint_comparator> {
00280 public:
00281     void add_constraint(const sx_constraint & c) {
00282         insert(c);
00283     }
00284 };
00285 
00286 // 
00287 // a predicate is a *disjunction* ("or") of filters
00288 //
00289 class sx_predicate : public vector<sx_filter> {
00290 };
00291 
00292 extern ostream & operator << (ostream &, const sx_predicate &);
00293 extern ostream & operator << (ostream &, const sx_constraint &);
00294 extern ostream & operator << (ostream &, const sx_message &);
00295 extern ostream & operator << (ostream &, const sx_value &);
00296 extern ostream & operator << (ostream &, const sx_constraint &);
00297 
00298 extern bool covers(const sx_predicate &, const sx_message &);
00299 extern bool covers(const sx_filter &, const sx_message &);
00300 extern bool covers(const sx_constraint &, const sx_message &);
00301 
00302 #endif

Copyright © 2001-2002 University of Colorado.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License". This documentation is authored and maintained by Antonio Carzaniga