basix_doc 0.1
|
00001 00002 /****************************************************************************** 00003 * MODULE : row_tuple.hpp 00004 * DESCRIPTION: Syntactic row_tuple type constructor 00005 * COPYRIGHT : (C) 2006 Joris van der Hoeven 00006 ******************************************************************************* 00007 * This software falls under the GNU general public license and comes WITHOUT 00008 * ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details. 00009 * If you don't have this file, write to the Free Software Foundation, Inc., 00010 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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 * The row_tuple class 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 * Useful conversions 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 #undef TMPL 00084 #undef Row_tuple 00085 } // namespace mmx 00086 #endif // __ROW_TUPLE_HPP