00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "predicate.h"
00023
00024 using namespace zeitgeist;
00025 using namespace oxygen;
00026 using namespace boost;
00027 using namespace std;
00028
00030 const zeitgeist::ParameterList Predicate::nullParamList;
00031
00032 Predicate::Iterator::Iterator(const ParameterList* l,
00033 ParameterList::TVector::const_iterator i)
00034 : list(l),iter(i) {};
00035
00036 Predicate::Iterator::Iterator(const ParameterList* l)
00037 : list(l),iter(l->begin()) {}
00038
00039 Predicate::Iterator::Iterator(const Predicate& predicate)
00040 : list(&predicate.parameter), iter(predicate.parameter.begin()) {}
00041
00042 Predicate::Iterator::Iterator()
00043 : list(&nullParamList), iter(nullParamList.begin()) {};
00044
00045 const boost::any& Predicate::Iterator::operator * () const
00046 {
00047 return (*iter);
00048 }
00049
00050 void Predicate::Iterator::operator ++ ()
00051 {
00052 if (iter != list->end())
00053 {
00054 ++iter;
00055 }
00056 }
00057
00058 Predicate::Iterator Predicate::Iterator::begin() const
00059 {
00060 return Iterator(list, list->begin());
00061 }
00062
00063 Predicate::Iterator Predicate::Iterator::end() const
00064 {
00065 return Iterator(list, list->end());
00066 }
00067
00068 bool Predicate::Iterator::operator != (const Iterator& i) const
00069 {
00070 return (
00071 (list != i.list) ||
00072 (iter != i.iter)
00073 );
00074 }
00075
00076 bool Predicate::Iterator::operator == (const Iterator& i) const
00077 {
00078 return (
00079 (list == i.list) &&
00080 (iter == i.iter)
00081 );
00082 }
00083
00084 const ParameterList::TVector::const_iterator&
00085 Predicate::Iterator::GetIterator() const
00086 {
00087 return iter;
00088 }
00089
00090 ParameterList::TVector::const_iterator& Predicate::Iterator::GetIterator()
00091 {
00092 return iter;
00093 }
00094
00095 const ParameterList* Predicate::Iterator::GetList() const
00096 {
00097 return list;
00098 }
00099
00102 bool
00103 ParameterName::operator()(const boost::any& param, const string& pred) const
00104 {
00105 try
00106 {
00107
00108 const any* v = ¶m;
00109 const ParameterList* lst = any_cast<ParameterList>(v);
00110
00111 if ( (lst == 0) || (lst->IsEmpty()))
00112 {
00113 return false;
00114 }
00115
00116 string s;
00117 lst->GetValue(lst->begin(),s);
00118
00119 return (pred == s);
00120 }
00121
00122 catch(const boost::bad_any_cast &)
00123 {
00124 return false;
00125 }
00126 }
00127
00128 bool
00129 Predicate::FindParameter(Iterator& iter, const string& name) const
00130 {
00131 const ParameterList* list = iter.GetList();
00132
00133 Iterator test
00134 (
00135 list,
00136 find_if(
00137 list->begin(), list->end(),
00138 bind2nd(ParameterName(), name)
00139 )
00140 );
00141
00142 if (test == test.end())
00143 {
00144 return false;
00145 }
00146
00147
00148 const ParameterList* paramList
00149 = boost::any_cast<ParameterList>(&(*test));
00150 if (
00151 (paramList == 0) ||
00152 (paramList->GetSize() < 2)
00153 )
00154 {
00155 return false;
00156 }
00157
00158
00159
00160 iter = Iterator(paramList,paramList->begin());
00161 ++iter;
00162
00163 return true;
00164 }
00165
00166 bool Predicate::DescentList(Iterator& iter) const
00167 {
00168 try
00169 {
00170 const any* v = &(*iter.GetIterator());
00171 const ParameterList* l = any_cast<ParameterList>(v);
00172 iter = Iterator(l);
00173 return true;
00174 }
00175
00176 catch(const std::bad_cast&)
00177 {
00178 return false;
00179 }
00180
00181 }
00182
00184 PredicateList::PredicateList()
00185 {
00186 }
00187
00188 PredicateList::~PredicateList()
00189 {
00190 }
00191
00192 PredicateList::TList::const_iterator PredicateList::begin() const
00193 {
00194 return mList.begin();
00195 }
00196
00197 PredicateList::TList::const_iterator PredicateList::end() const
00198 {
00199 return mList.end();
00200 }
00201
00202 Predicate& PredicateList::AddPredicate()
00203 {
00204 mList.push_back(Predicate());
00205 return mList.back();
00206 }
00207
00208 int PredicateList::GetSize() const
00209 {
00210 return mList.size();
00211 }
00212
00213 void PredicateList::Clear()
00214 {
00215 mList.clear();
00216 }
00217
00218
00219
00220