Siena Fast Forwarding documentation (v. 1.0.0)

Main Page   Class Hierarchy   Compound List   File List   Compound Members   Examples  

constraint_index.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 //  See the file AUTHORS for full details. 
00008 //
00009 //  Copyright (C) 2001-2002 University of Colorado
00010 //
00011 //  This program is free software; you can redistribute it and/or
00012 //  modify it under the terms of the GNU General Public License
00013 //  as published by the Free Software Foundation; either version 2
00014 //  of the License, or (at your option) any later version.
00015 //
00016 //  This program is distributed in the hope that it will be useful,
00017 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 //  GNU General Public License for more details.
00020 //
00021 //  You should have received a copy of the GNU General Public License
00022 //  along with this program; if not, write to the Free Software
00023 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
00024 //  USA, or send email to [email protected].
00025 //
00026 //
00027 // $Id: constraint_index.h,v 1.6 2002/09/30 04:51:48 carzanig Exp $
00028 //
00029 #ifndef CONSTRAINT_INDEX_H
00030 #define CONSTRAINT_INDEX_H
00031 
00032 #include "fwd_table.h"
00033 #include "ft_allocator.h"
00034 
00044 template<class T>
00045 class constraint_index {
00046 private:
00047     class node {
00048     public:
00049         T value;
00050         Constraint * c;
00051         
00052         node(const T & v, Constraint * d): value(v), c(d) {}
00053 
00054         bool operator < (const T & x) const { return value < x; }
00055         bool operator > (const T & x) const { return value > x; }
00056         bool operator == (const T & x) const { return value == x; }
00057     };
00058 
00059     typedef vector<node> v_index;
00060     typedef map<T, Constraint *> m_index;
00061 
00062     v_index lt_map;
00063     v_index gt_map;
00064     m_index eq_map;
00065     
00066 public:
00067     Constraint * add_lt(const T & v, FTAllocator & ftmemory) {
00068         v_index::iterator i = lower_bound(lt_map.begin(), lt_map.end(), v);
00069         if (i == lt_map.end() || (*i).value != v)  
00070             i = lt_map.insert(i, node(v, new (ftmemory)Constraint()));
00071 
00072         return (*i).c;
00073     }
00074 
00075     Constraint * add_gt(const T & v, FTAllocator & ftmemory)  {
00076         v_index::iterator i = lower_bound(gt_map.begin(), gt_map.end(), v);
00077         if (i == gt_map.end() || (*i).value != v) 
00078             i = gt_map.insert(i, node(v, new (ftmemory)Constraint()));
00079 
00080         return (*i).c;
00081     }
00082 
00083     Constraint * add_eq(const T & v, FTAllocator & ftmemory) {
00084         pair<m_index::iterator, bool> pib;
00085         pib = eq_map.insert(m_index::value_type(v, NULL));
00086         if (pib.second) 
00087             (*pib.first).second = new (ftmemory)Constraint();
00088 
00089         return (*pib.first).second;
00090     }
00091 
00092     bool match(const T & v, CProcessor & p) const {
00093         //
00094         // equality first
00095         //
00096         m_index::const_iterator i = eq_map.find(v);
00097         if (i != eq_map.end()) 
00098             if (p.process_constraint((*i).second))
00099                 return true;
00100         //
00101         // now greater-than
00102         //
00103         v_index::const_iterator vi;
00104         for(vi = gt_map.begin(); vi != gt_map.end() && *vi < v; ++vi) 
00105             if (p.process_constraint((*vi).c))
00106                 return true;
00107         //
00108         // now less-than
00109         //
00110         v_index::const_reverse_iterator vri;
00111         for(vri = lt_map.rbegin(); vri != lt_map.rend() && *vri > v; ++vri) 
00112             if (p.process_constraint((*vri).c))
00113                 return true;
00114         return false;
00115     }
00116 };
00117 
00118 #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