00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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(¶meter,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 }
00276
00277 #endif // OXYGEN_PREDICATE_H