1 /*! ========================================================================
2 ** Extended Template Library
3 ** Trivializing Template Class Implementation
6 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
8 ** This package is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU General Public License as
10 ** published by the Free Software Foundation; either version 2 of
11 ** the License, or (at your option) any later version.
13 ** This package is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ** General Public License for more details.
18 ** === N O T E S ===========================================================
20 ** This is an internal header file, included by other ETL headers.
21 ** You should not attempt to use it directly.
23 ** ========================================================================= */
25 /* === S T A R T =========================================================== */
27 #ifndef __ETL__TRIVIAL_H
28 #define __ETL__TRIVIAL_H
30 /* === H E A D E R S ======================================================= */
32 /* === M A C R O S ========================================================= */
34 /* === T Y P E D E F S ===================================================== */
36 /* === C L A S S E S & S T R U C T S ======================================= */
40 /*! ========================================================================
42 ** \brief Trivializes the constructor of a given class
44 ** This class makes the given type 'trivial',
45 ** effectively disabling the constructor and
46 ** destructor. (This is useful for unions)
47 ** Some extra casting may be necessary to get
48 ** it to work properly.
55 typedef const T& const_reference;
57 typedef const T* const_pointer;
62 { return *reinterpret_cast<pointer>(data); }
64 // HACK - Rather dangerous
65 //operator reference()const
66 //{ return *reinterpret_cast<pointer>(const_cast<char *>(data)); }
68 operator const_reference()const
69 { return *reinterpret_cast<const_pointer>(data); }
72 { return *reinterpret_cast<pointer>(data); }
74 const_reference get()const
75 { return *reinterpret_cast<const_pointer>(data); }
78 { new(&get()) value_type(); }
81 { get().~value_type(); }
83 void destroy() { destruct(); }
85 template<class U> reference
86 operator=(const U &rhs)
89 template<class U>reference
90 operator=(const trivial<U> &rhs)
91 { return get()=rhs.get(); }
93 template<class U> reference
94 operator+=(const U &rhs)
95 { return get()+=rhs; }
97 template<class U> reference
98 operator-=(const U &rhs)
99 { return get()-=rhs; }
101 template<class U> reference
102 operator*=(const U &rhs)
103 { return get()*=rhs; }
105 template<class U> reference
106 operator/=(const U &rhs)
107 { return get()/=rhs; }
109 template<class U> reference
110 operator%=(const U &rhs)
111 { return get()%=rhs; }
113 template<class U> reference
114 operator^=(const U &rhs)
115 { return get()^=rhs; }
117 template<class U> reference
118 operator&=(const U &rhs)
119 { return get()&=rhs; }
121 template<class U> reference
122 operator>>=(const U &rhs)
123 { return get()>>=rhs; }
125 template<class U> reference
126 operator<<=(const U &rhs)
127 { return get()<<=rhs; }
132 bool operator!()const
134 }; // END of template class trivial
138 //#include <iostream>
141 template<typename T, typename _CharT, class _Traits> std::basic_istream<_CharT, _Traits>&
142 operator>>(std::basic_istream<_CharT, _Traits>& s, etl::trivial<T>& rhs)
143 { return s>>(T)(rhs); }
145 template<typename T,typename _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>&
146 operator<<(std::basic_ostream<_CharT, _Traits>& s, const etl::trivial<T>& rhs)
147 { return s<<(T)(rhs); }
151 template<typename T> std::istream&
152 operator>>(std::istream& s, etl::trivial<T>& rhs)
153 { return s>>(T)(rhs); }
155 template<typename T> std::ostream&
156 operator<<(std::ostream& s, const etl::trivial<T>& rhs)
157 { return s<<(T)(rhs); }
160 /* === E X T E R N S ======================================================= */
162 /* === E N D =============================================================== */