00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef ACEDIA_ANY_ARRAY_H
00031 #define ACEDIA_ANY_ARRAY_H
00032
00033 #include "acedia_preprocessor.hpp"
00034
00035 #include "any.hpp"
00036 #include "metaclass.hpp"
00037 #include "exceptions.hpp"
00038
00039 namespace acedia
00040 {
00041
00047 class AnyArray
00048 {
00049 template<typename A>
00050 inline bool singleMatch(const Any &any) const
00051 {
00052 return any.instanceOf<A>();
00053 }
00054
00055 public:
00056
00057 virtual ~AnyArray();
00058
00063 inline bool isEmpty() const { return length() == 0; }
00064
00068 virtual bool isTuple() const;
00069
00073 virtual bool isMessage() const;
00074
00078 virtual boost::uint32_t length() const = 0;
00079
00084 virtual const Any &at(boost::uint32_t pos) const = 0;
00085
00095 inline MetaClass *metaClassAt(boost::uint32_t pos) const
00096 {
00097 return at(pos).metaClass();
00098 }
00099
00104 inline const Any &operator[](boost::uint32_t pos) const
00105 {
00106 return at(pos);
00107 }
00108
00115 template<typename T>
00116 inline const T &valueAt(boost::uint32_t pos) const
00117 {
00118 const Any &v = at(pos);
00119 return v.value<T>();
00120 }
00121
00122
00123 template<typename T>
00124 inline const T &uncheckedValueAt(boost::uint32_t pos) const
00125 {
00126 if (util::IsUnit<T>::VALUE)
00127 return reinterpret_cast<const T &>(Unit::instance());
00128 const Any &v = at(pos);
00129 return v.uncheckedValue<T>();
00130 }
00131
00136 template<typename A>
00137 inline bool match() const
00138 {
00139 return length() == 1 && singleMatch<A>(at(0));
00140 }
00141
00146 template<typename A, class Cond1>
00147 inline bool match(const Cond1 &c1) const
00148 {
00149 return match<A>() && c1(valueAt<A>(0));
00150 }
00151
00156 template<typename A, typename B>
00157 inline bool match() const
00158 {
00159 return length() == 2 && BOOST_PP_SEQ_FOR_EACH_I(ACEDIA_MSG_SUBMATCH, ~, (A)(B));
00160 }
00161
00167 template<typename A, typename B, class Cond1, class Cond2>
00168 inline bool match(const Cond1 &c1, const Cond2 &c2) const
00169 {
00170 return match<A, B>() && c1(valueAt<A>(0)) && c2(valueAt<B>(1));
00171 }
00172
00177 template<typename A, typename B, typename C>
00178 inline bool match() const
00179 {
00180 return length() == 3 && BOOST_PP_SEQ_FOR_EACH_I(ACEDIA_MSG_SUBMATCH, ~, (A)(B)(C));
00181 }
00182
00188 template<typename A, typename B, typename C, class Cond1, class Cond2, class Cond3>
00189 inline bool match(const Cond1 &c1, const Cond2 &c2, const Cond3 &c3) const
00190 {
00191 return match<A,B,C>() && c1(valueAt<A>(0)) && c2(valueAt<B>(1)) && c3(valueAt<C>(2));
00192 }
00193
00198 template<typename A, typename B, typename C, typename D>
00199 inline bool match() const
00200 {
00201 return length() == 4 && BOOST_PP_SEQ_FOR_EACH_I(ACEDIA_MSG_SUBMATCH, ~, (A)(B)(C)(D));
00202 }
00203
00209 template<typename A, typename B, typename C, typename D, class Cond1, class Cond2, class Cond3, class Cond4>
00210 inline bool match(const Cond1 &c1, const Cond2 &c2, const Cond3 &c3, const Cond4 &c4) const
00211 {
00212 return match<A,B,C,D>() && c1(valueAt<A>(0)) && c2(valueAt<B>(1)) && c3(valueAt<C>(2)) && c4(valueAt<D>(3));
00213 }
00214
00219 template<typename A, typename B, typename C, typename D, typename E>
00220 inline bool match() const
00221 {
00222 return length() == 5 && BOOST_PP_SEQ_FOR_EACH_I(ACEDIA_MSG_SUBMATCH, ~, (A)(B)(C)(D)(E));
00223 }
00224
00230 template<typename A, typename B, typename C, typename D, typename E, class Cond1, class Cond2, class Cond3, class Cond4, class Cond5>
00231 inline bool match(const Cond1 &c1, const Cond2 &c2, const Cond3 &c3, const Cond4 &c4, const Cond5 &c5) const
00232 {
00233 return match<A,B,C,D>() && c1(valueAt<A>(0)) && c2(valueAt<B>(1)) && c3(valueAt<C>(2)) && c4(valueAt<D>(3)) && c5(valueAt<E>(4));
00234 }
00235
00240 template<typename A, typename B, typename C, typename D, typename E, typename F>
00241 inline bool match() const
00242 {
00243 return length() == 6 && BOOST_PP_SEQ_FOR_EACH_I(ACEDIA_MSG_SUBMATCH, ~, (A)(B)(C)(D)(E)(F));
00244 }
00245
00251 template<typename A, typename B, typename C, typename D, typename E, typename F, class Cond1, class Cond2, class Cond3, class Cond4, class Cond5, class Cond6>
00252 inline bool match(const Cond1 &c1, const Cond2 &c2, const Cond3 &c3, const Cond4 &c4, const Cond5 &c5, const Cond6 &c6) const
00253 {
00254 return match<A,B,C,D>() && c1(valueAt<A>(0)) && c2(valueAt<B>(1)) && c3(valueAt<C>(2)) && c4(valueAt<D>(3)) && c5(valueAt<E>(4)) && c6(valueAt<F>(5));
00255 }
00256
00261 template<typename A, typename B, typename C, typename D, typename E, typename F, typename G>
00262 inline bool match() const
00263 {
00264 return length() == 7 && BOOST_PP_SEQ_FOR_EACH_I(ACEDIA_MSG_SUBMATCH, ~, (A)(B)(C)(D)(E)(F)(G));
00265 }
00266
00272 template<typename A, typename B, typename C, typename D, typename E, typename F, typename G, class Cond1, class Cond2, class Cond3, class Cond4, class Cond5, class Cond6, class Cond7>
00273 inline bool match(const Cond1 &c1, const Cond2 &c2, const Cond3 &c3, const Cond4 &c4, const Cond5 &c5, const Cond6 &c6, const Cond7 &c7) const
00274 {
00275 return match<A,B,C,D>() && c1(valueAt<A>(0)) && c2(valueAt<B>(1)) && c3(valueAt<C>(2)) && c4(valueAt<D>(3)) && c5(valueAt<E>(4)) && c6(valueAt<F>(5)) && c7(valueAt<G>(6));
00276 }
00277
00282 template<typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H>
00283 inline bool match() const
00284 {
00285 return length() == 8 && BOOST_PP_SEQ_FOR_EACH_I(ACEDIA_MSG_SUBMATCH, ~, (A)(B)(C)(D)(E)(F)(G)(H));
00286 }
00287
00293 template<typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, class Cond1, class Cond2, class Cond3, class Cond4, class Cond5, class Cond6, class Cond7, class Cond8>
00294 inline bool match(const Cond1 &c1, const Cond2 &c2, const Cond3 &c3, const Cond4 &c4, const Cond5 &c5, const Cond6 &c6, const Cond7 &c7, const Cond8 &c8) const
00295 {
00296 return match<A,B,C,D>() && c1(valueAt<A>(0)) && c2(valueAt<B>(1)) && c3(valueAt<C>(2)) && c4(valueAt<D>(3)) && c5(valueAt<E>(4)) && c6(valueAt<F>(5)) && c7(valueAt<G>(6)) && c8(valueAt<H>(7));
00297 }
00298
00303 template<typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, typename I>
00304 inline bool match() const
00305 {
00306 return length() == 9 && BOOST_PP_SEQ_FOR_EACH_I(ACEDIA_MSG_SUBMATCH, ~, (A)(B)(C)(D)(E)(F)(G)(H)(I));
00307 }
00308
00314 template<typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, typename I, class Cond1, class Cond2, class Cond3, class Cond4, class Cond5, class Cond6, class Cond7, class Cond8, class Cond9>
00315 inline bool match(const Cond1 &c1, const Cond2 &c2, const Cond3 &c3, const Cond4 &c4, const Cond5 &c5, const Cond6 &c6, const Cond7 &c7, const Cond8 &c8, const Cond9 &c9) const
00316 {
00317 return match<A,B,C,D>() && c1(valueAt<A>(0)) && c2(valueAt<B>(1)) && c3(valueAt<C>(2)) && c4(valueAt<D>(3)) && c5(valueAt<E>(4)) && c6(valueAt<F>(5)) && c7(valueAt<G>(6)) && c8(valueAt<H>(7)) && c9(valueAt<I>(8));
00318 }
00319
00320 };
00321
00322 }
00323
00324 #endif