00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 #ifndef __MMX__INSTANCE__HPP
00014 #define __MMX__INSTANCE__HPP
00015 
00016 #include <basix/table.hpp>
00017 #include <basix/wrap.hpp>
00018 #include <basix/literal.hpp>
00019 #include <basix/compound.hpp>
00020 
00021 namespace mmx {
00022 #define TMPL template<typename Cat, nat Nr>
00023 #define Instance instance<Cat,Nr>
00024 
00025 
00026 
00027 
00028 
00029 TMPL
00030 class instance {
00031 MMX_ALLOCATORS
00032   generic rep;
00033 public:
00034   static Cat Cur;
00035 public:
00036   inline generic operator * () const { return rep; }
00037   inline instance (const instance& prg2): rep (prg2.rep) {}
00038   inline instance (const generic& prg): rep (prg) {}
00039   instance ();
00040   template<typename C1>
00041   instance (const C1& c1);
00042   template<typename C1, typename C2>
00043   instance (const C1& c1, const C2& c2);
00044   template<typename C1, typename C2, typename C3>
00045   instance (const C1& c1, const C2& c2, const C3& c3);
00046 };
00047 
00048 WRAP_WRAPPED_IMPL(TMPL,Instance);
00049 WRAP_PRINT_IMPL(TMPL,Instance);
00050 WRAP_BINARY_IMPL(TMPL,Instance,generic,"Ins","Ins")
00051 
00052 TMPL Cat Instance::Cur = Cat ();
00053 
00054 template<typename Dest, typename Src> inline Dest
00055 view_as (const Src& src) {
00056   return *((Dest*) ((void*) &src));
00057 }
00058 
00059 template<typename Dest, typename Src> inline Dest&
00060 view_as (Src& src) {
00061   return *((Dest*) ((void*) &src));
00062 }
00063 
00064 
00065 
00066 
00067 
00068 template<typename Cat, nat Nr>
00069 struct constructor_0 {
00070   static inline generic op () {
00071     return Instance::Cur -> sample_1 (); }
00072 };
00073 
00074 TMPL inline
00075 Instance::instance ():
00076   rep (constructor_0<Cat,Nr>::op ()) {}
00077 
00078 template<typename Cat, nat Nr, typename C1>
00079 struct constructor_1 {
00080   static inline generic op (const C1& c1) {
00081     generic r;
00082     set_as (view_as<Instance> (r), c1);
00083     return r;
00084   }
00085 };
00086 
00087 TMPL template<typename C1> inline
00088 Instance::instance (const C1& c1):
00089   rep (constructor_1<Cat,Nr,C1>::op (c1)) {}
00090 
00091 template<typename Cat, nat Nr, typename C1, typename C2>
00092 struct constructor_2 {
00093   static inline generic op (const C1& c1, const C2& c2) {
00094     generic r;
00095     set_as (view_as<Instance> (r), c1, c2);
00096     return r;
00097   }
00098 };
00099 
00100 TMPL template<typename C1, typename C2> inline
00101 Instance::instance (const C1& c1, const C2& c2):
00102   rep (constructor_2<Cat,Nr,C1,C2>::op (c1, c2)) {}
00103 
00104 template<typename Cat, nat Nr, typename C1, typename C2, typename C3>
00105 struct constructor_3 {
00106   static inline generic op (const C1& c1, const C2& c2, const C3& c3) {
00107     generic r;
00108     set_as (view_as<Instance> (r), c1, c2, c3);
00109     return r;
00110   }
00111 };
00112 
00113 TMPL template<typename C1, typename C2, typename C3> inline
00114 Instance::instance (const C1& c1, const C2& c2, const C3& c3):
00115   rep (constructor_3<Cat,Nr,C1,C2,C3>::op (c1, c2, c3)) {}
00116 
00117 
00118 
00119 
00120 
00121 TMPL inline bool operator == (const Instance& x, const int& i) {
00122   return x == promote (i, x); }
00123 TMPL inline bool operator != (const Instance& x, const int& i) {
00124   return x != promote (i, x); }
00125 TMPL inline bool operator < (const Instance& x, const int& i) {
00126   return x < promote (i, x); }
00127 TMPL inline bool operator > (const Instance& x, const int& i) {
00128   return x > promote (i, x); }
00129 TMPL inline bool operator <= (const Instance& x, const int& i) {
00130   return x <= promote (i, x); }
00131 TMPL inline bool operator >= (const Instance& x, const int& i) {
00132   return x >= promote (i, x); }
00133 
00134 
00135 
00136 
00137 
00138 TMPL
00139 class local_instance_type {
00140   Cat Old;
00141 public:
00142   inline local_instance_type (const Cat& New):
00143     Old (Instance::Cur) { Instance::Cur = New; }
00144   inline ~local_instance_type () {
00145     Instance::Cur = Old; }
00146 };
00147 
00148 #undef TMPL
00149 #undef Instance
00150 } 
00151 #endif // __MMX__INSTANCE__HPP