00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef __ROW_TUPLE_HPP
00014 #define __ROW_TUPLE_HPP
00015 #include <basix/vector.hpp>
00016 #include <basix/wrap.hpp>
00017
00019
00020 namespace mmx {
00021 #define TMPL template<typename C>
00022 #define Row_tuple row_tuple<C>
00023 generic vector_to_compound (const vector<generic>& v);
00024
00025
00026
00027
00028
00029 template<typename C>
00030 class row_tuple {
00031 MMX_ALLOCATORS
00032 generic rep;
00033 public:
00034 inline generic operator * () const { return rep; }
00035 inline row_tuple (): rep (gen (GEN_ROW)) {}
00036 inline row_tuple (const generic& g): rep (g) {}
00037 inline row_tuple (const vector<C>& v):
00038 rep (gen (GEN_ROW, as<vector<generic> > (v))) {};
00039 inline row_tuple (const Row_tuple& t): rep (t.rep) {}
00040 inline C operator[] (nat i) const { return as<C> (rep[i+1]); }
00041 };
00042
00043 TMPL inline nat N (const Row_tuple& t) { return N(*t)-1; }
00044
00045 WRAP_INDIRECT_IMPL(TMPL inline,Row_tuple)
00046
00047 TMPL syntactic
00048 flatten (const Row_tuple& t) {
00049 return as_syntactic (gen (GEN_ROW, cdr (compound_to_vector (*t))));
00050 }
00051
00052 WRAP_BINARY_IMPL_1(TMPL,Row_tuple,generic,"Rtu","Row_tuple",C)
00053
00054
00055
00056
00057
00058 TMPL Row_tuple
00059 as_row_tuple (const vector<C>& a) {
00060 nat i, n= N(a);
00061 vector<generic> t= fill<generic> (n+1);
00062 t[0]= GEN_ROW;
00063 for (i=0; i<n; i++)
00064 t[i+1]= as<generic> (a[i]);
00065 return Row_tuple (vector_to_compound (t));
00066 }
00067
00068 TMPL vector<C>
00069 as_vector (const Row_tuple& t) {
00070 nat i, n= N(t);
00071 vector<C> a= fill<C> (n);
00072 for (i=0; i<n; i++)
00073 a[i]= t[i];
00074 return a;
00075 }
00076
00077 template<typename T, typename F>
00078 struct as_helper<row_tuple<T>,row_tuple<F> > {
00079 static row_tuple<T> cv (const row_tuple<F>& r) {
00080 return as_row_tuple<T> (as<vector<T> > (as_vector<F> (r))); }
00081 };
00082
00083
00084
00085
00086
00087 template<typename S1, typename D> row_tuple<D>
00088 map (const function_1<D,Argument(S1) >& fun, const row_tuple<S1>& v1,
00089 const format<D>& fm) {
00090 return as_row_tuple (map (fun, as_vector (v1), fm)); }
00091
00092 #undef TMPL
00093 #undef Row_tuple
00094 }
00095 #endif // __ROW_TUPLE_HPP