_trivial.h

Go to the documentation of this file.
00001 
00025 /* === S T A R T =========================================================== */
00026 
00027 #ifndef __ETL_TRIVIAL_H
00028 #define __ETL_TRIVIAL_H
00029 
00030 /* === H E A D E R S ======================================================= */
00031 
00032 /* === M A C R O S ========================================================= */
00033 
00034 /* === T Y P E D E F S ===================================================== */
00035 
00036 /* === C L A S S E S & S T R U C T S ======================================= */
00037 
00038 _ETL_BEGIN_NAMESPACE
00039 
00050 template <class T>
00051 class trivial
00052 {
00053     typedef T value_type;
00054     typedef T& reference;
00055     typedef const T& const_reference;
00056     typedef T* pointer;
00057     typedef const T* const_pointer;
00058     
00059     char data[sizeof(T)];
00060 public:
00061     operator reference() 
00062     { return *reinterpret_cast<pointer>(data); }
00063 
00064     // HACK - Rather dangerous
00065     //operator reference()const 
00066     //{ return *reinterpret_cast<pointer>(const_cast<char *>(data)); }
00067     
00068     operator const_reference()const 
00069     { return *reinterpret_cast<const_pointer>(data); }
00070     
00071     reference get()
00072     { return *reinterpret_cast<pointer>(data); }
00073 
00074     const_reference get()const
00075     { return *reinterpret_cast<const_pointer>(data); }
00076     
00077     void construct()
00078     { new(&get()) value_type(); }
00079 
00080     void destruct()
00081     { get().~value_type(); }
00082     
00083     void destroy() { destruct(); }
00084     
00085     template<class U> reference
00086     operator=(const U &rhs)
00087     { return get()=rhs; }
00088 
00089     template<class U>reference
00090     operator=(const trivial<U> &rhs)
00091     { return get()=rhs.get(); }
00092 
00093     template<class U> reference
00094     operator+=(const U &rhs)
00095     { return get()+=rhs; }
00096 
00097     template<class U> reference
00098     operator-=(const U &rhs)
00099     { return get()-=rhs; }
00100 
00101     template<class U> reference
00102     operator*=(const U &rhs)
00103     { return get()*=rhs; }
00104 
00105     template<class U> reference
00106     operator/=(const U &rhs)
00107     { return get()/=rhs; }
00108 
00109     template<class U> reference
00110     operator%=(const U &rhs)
00111     { return get()%=rhs; }
00112 
00113     template<class U> reference
00114     operator^=(const U &rhs)
00115     { return get()^=rhs; }
00116 
00117     template<class U> reference
00118     operator&=(const U &rhs)
00119     { return get()&=rhs; }
00120 
00121     template<class U> reference
00122     operator>>=(const U &rhs)
00123     { return get()>>=rhs; }
00124 
00125     template<class U> reference
00126     operator<<=(const U &rhs)
00127     { return get()<<=rhs; }
00128     
00129     operator bool()const 
00130     { return get(); }
00131 
00132     bool operator!()const 
00133     { return !get(); }
00134 }; // END of template class trivial
00135 
00136 _ETL_END_NAMESPACE
00137 
00138 //#include <iostream>
00139 
00140 /*
00141 template<typename T, typename _CharT, class _Traits> std::basic_istream<_CharT, _Traits>&
00142 operator>>(std::basic_istream<_CharT, _Traits>& s, etl::trivial<T>& rhs)
00143 { return s>>(T)(rhs); }
00144 
00145 template<typename T,typename _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>&
00146 operator<<(std::basic_ostream<_CharT, _Traits>& s, const etl::trivial<T>& rhs)
00147 { return s<<(T)(rhs); }
00148 */
00149 
00150 /*
00151 template<typename T> std::istream&
00152 operator>>(std::istream& s, etl::trivial<T>& rhs)
00153 { return s>>(T)(rhs); }
00154 
00155 template<typename T> std::ostream&
00156 operator<<(std::ostream& s, const etl::trivial<T>& rhs)
00157 { return s<<(T)(rhs); }
00158 */
00159 
00160 /* === E X T E R N S ======================================================= */
00161 
00162 /* === E N D =============================================================== */
00163 
00164 #endif

Generated on Wed Jun 21 16:25:59 2006 for ETL by  doxygen 1.4.6