Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

predicate.h

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
00002 
00003    this file is part of rcssserver3D
00004    Fri May 9 2003
00005    Copyright (C) 2002,2003 Koblenz University
00006    Copyright (C) 2004 RoboCup Soccer Server 3D Maintenance Group
00007    $Id: predicate.h,v 1.7 2004/04/05 14:51:08 rollmark Exp $
00008 
00009    This program is free software; you can redistribute it and/or modify
00010    it under the terms of the GNU General Public License as published by
00011    the Free Software Foundation; version 2 of the License.
00012 
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with this program; if not, write to the Free Software
00020    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00021 */
00022 #ifndef OXYGEN_PREDICATE_H
00023 #define OXYGEN_PREDICATE_H
00024 
00025 #include <list>
00026 #include <string>
00027 #include <functional>
00028 #include <boost/any.hpp>
00029 #include <salt/vector.h>
00030 #include <zeitgeist/logserver/logserver.h>
00031 
00032 namespace oxygen
00033 {
00049 class Predicate
00050 {
00051  public:
00065     struct Iterator
00066     {
00067     public:
00069         Iterator(const zeitgeist::ParameterList* l,
00070                  zeitgeist::ParameterList::TVector::const_iterator i);
00071 
00074         Iterator::Iterator(const zeitgeist::ParameterList* l);
00075 
00078         Iterator(const Predicate& predicate);
00079 
00085         Iterator();
00086 
00088         const boost::any& operator * () const;
00089 
00091         void operator ++ ();
00092 
00095         Iterator begin() const;
00096 
00099         Iterator end() const;
00100 
00102         bool operator != (const Iterator& i) const;
00103 
00105         bool operator == (const Iterator& i) const;
00106 
00108         const zeitgeist::ParameterList::TVector::const_iterator&
00109         GetIterator() const;
00110 
00112         zeitgeist::ParameterList::TVector::const_iterator& GetIterator();
00113 
00115         const zeitgeist::ParameterList* GetList() const;
00116 
00117     protected:
00119         const zeitgeist::ParameterList* list;
00120 
00122         zeitgeist::ParameterList::TVector::const_iterator iter;
00123     };
00124 
00125 public:
00126     const Iterator begin() const
00127     {
00128         return Iterator(&parameter,parameter.begin());
00129     }
00130 
00153     bool FindParameter(Iterator& iter, const std::string& name) const;
00154 
00173     template<typename T> f_inline bool
00174     GetValue(const Iterator& iter, const std::string& name, T& value) const
00175     {
00176         Iterator tmp(iter);
00177         return AdvanceValue(tmp,name,value);
00178    }
00179 
00184     template<typename T> f_inline bool
00185     AdvanceValue(Iterator& iter, const std::string&name, T& value) const
00186     {
00187         if (! FindParameter(iter,name))
00188             {
00189                 return false;
00190             }
00191 
00192         return AdvanceValue(iter,value);
00193     }
00194 
00200     template<typename T> f_inline bool
00201     AdvanceValue(Iterator& iter, T& value) const
00202     {
00203         return iter.GetList()->AdvanceValue(iter.GetIterator(),value);
00204     }
00205 
00209     template<typename T> f_inline bool
00210     GetValue(const Iterator& iter, T& value) const
00211     {
00212         return iter.GetList()->GetValue(iter.GetIterator(),value);
00213     }
00214 
00215     template<typename T> f_inline bool
00216     GetAnyValue(const Iterator& iter, T& value) const
00217     {
00218         return iter.GetList()->GetAnyValue(iter.GetIterator(),value);
00219     }
00220 
00224     bool DescentList(Iterator& iter) const;
00225 
00226  public:
00228     std::string name;
00229 
00231     zeitgeist::ParameterList parameter;
00232 
00233 protected:
00234     static const zeitgeist::ParameterList nullParamList;
00235 };
00236 
00240 class ParameterName : public std::binary_function<boost::any,std::string,bool>
00241 {
00242 public:
00243     bool operator()(const boost::any& param, const std::string& pred) const;
00244 };
00245 
00246 class PredicateList
00247 {
00248 public:
00249     typedef std::list<Predicate> TList;
00250 public:
00251     PredicateList();
00252     virtual ~PredicateList();
00253 
00256     TList::const_iterator begin() const;
00257 
00260     TList::const_iterator end() const;
00261 
00264     int GetSize() const;
00265 
00267     void Clear();
00268 
00269     Predicate& AddPredicate();
00270 
00271 protected:
00272     TList mList;
00273 };
00274 
00275 }  // namespace oxygen
00276 
00277 #endif // OXYGEN_PREDICATE_H

Generated on Thu Apr 6 15:25:39 2006 for rcssserver3d by  doxygen 1.4.4