ivl 679
ivl/details/core/conversions/attr.hpp
00001 /* This file is part of the ivl C++ library <http://image.ntua.gr/ivl>.
00002    A C++ template library extending syntax towards mathematical notation.
00003 
00004    Copyright (C) 2012 Yannis Avrithis <iavr@image.ntua.gr>
00005    Copyright (C) 2012 Kimon Kontosis <kimonas@image.ntua.gr>
00006 
00007    ivl is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU Lesser General Public License 
00009    version 3 as published by the Free Software Foundation.
00010 
00011    Alternatively, you can redistribute it and/or modify it under the terms 
00012    of the GNU General Public License version 2 as published by the Free 
00013    Software Foundation.
00014 
00015    ivl is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00018    See the GNU General Public License for more details.
00019 
00020    You should have received a copy of the GNU General Public License 
00021    and a copy of the GNU Lesser General Public License along 
00022    with ivl. If not, see <http://www.gnu.org/licenses/>. */
00023 
00024 #ifndef IVL_CORE_DETAILS_CONVERSIONS_ATTR_HPP
00025 #define IVL_CORE_DETAILS_CONVERSIONS_ATTR_HPP
00026 
00027 namespace ivl {
00028 namespace conversions {
00029 
00030 struct ro;
00031 struct wo;
00032 struct rw;
00033 
00034 struct normal;
00035 
00036 template <class T>
00037 struct get_access_type
00038 {
00039         typedef ro type;
00040 };
00041 
00042 // ---------------------------
00043 /*
00044 template <class ARRAY_TYPE, class CONV_TYPE, class ACCESS_TYPE =
00045         typename get_access_type<CONV_TYPE>::type>
00046 class attr
00047 {
00048 };
00049 */
00050 namespace conversions_details {
00051 
00052 template <class A>
00053 class wrap_op :
00054         public types::change_data_class_set<A, data::wrap_array<A> >::type
00055 {
00056         typedef typename types::change_data_class_set<A,
00057                 data::wrap_array<A> >::type base_class;
00058 public:
00059         template <class K>
00060         wrap_op(K& k) : base_class(k) { }
00061         wrap_op(const wrap_op& k) : base_class(k) { }
00062         A& ref() { return *this; }
00063         typename types::apply_const<A&>::type ref() const { return *this; }
00064 };
00065 
00066 // ---------------------------
00067 
00068 // normal conversion
00069 
00070 template<class A, class D, class C, class M>
00071 class attr_op
00072 {
00073 };
00074 
00075 // ---
00076 
00077 template<class A, class D>
00078 class attr_op<A, D, normal, ro> :
00079         public types::normal_type<A>::type
00080 {
00081         typedef typename types::normal_type<A>::type base_class;
00082 public:
00083         template <class K>
00084         attr_op(K& k) : base_class(k) { }
00085         attr_op(const attr_op& k) : base_class(k) { }
00086         base_class& ref() { return *this; }
00087         const base_class& ref() const { return *this; }
00088 };
00089 
00090 template<class A, class D>
00091 class attr_op<A, D, normal, wo> :
00092         public types::normal_type<A>::type
00093 {
00094         typedef typename types::normal_type<A>::type base_class;
00095         base_class& base() { return *this; }
00096         A* tmp;
00097 public:
00098         attr_op(A& k) : tmp(&k) { }
00099         attr_op(const attr_op& k) : tmp(&k) { }
00100         ~attr_op() { *tmp = base; /*(*tmp).swap(base());*/ }
00101         base_class& ref() { return *this; }
00102         const base_class& ref() const { return *this; }
00103 };
00104 
00105 template<class A, class D>
00106 class attr_op<A, D, normal, rw> :
00107         public types::normal_type<A>::type
00108 {
00109         typedef typename types::normal_type<A>::type base_class;
00110         base_class& base() { return *this; }
00111         A* tmp;
00112 public:
00113         attr_op(A& k) : tmp(&k) { base() = k; /*base().swap(k);*/ }
00114         attr_op(const attr_op& k) : tmp(&k) { base() = k; /*base().swap(k);*/ }
00115         ~attr_op() { *tmp = base; /*(*tmp).swap(base());*/ }
00116         base_class& ref() { return *this; }
00117         const base_class& ref() const { return *this; }
00118 };
00119 
00120 // or maybe only for normal ?
00121 template <class A, class D, class M, class IS_IVL_ARRAY>
00122 class attr_2 :
00123         public conversions_details::attr_op<A, typename A::data_type, D, M>
00124 {
00125         typedef conversions_details::attr_op<A, typename A::data_type, D, M>
00126                 base_class;
00127 public:
00128         typedef attr_2 type;
00129         template<class K>
00130         attr_2(K& k) : base_class(k) { }
00131         attr_2(const attr_2& k) : base_class(k) { }
00132 };
00133 
00134 template <class A, class D, class M>
00135 class attr_2<A, D, M, types::t_false>
00136 {
00137 public:
00138         typedef A& type;
00139 };
00140 
00141 } /* namespace conversions_details */
00142 /*
00143 template <class A, class M>
00144 class attr<A, normal, M> :
00145         public conversions_details::attr_op<A, typename A::data_type, normal, M>
00146 {
00147         typedef conversions_details::attr_op<A, typename A::data_type, normal, M>
00148                 base_class;
00149 public:
00150         template<class K>
00151         attr(K& k) : base_class(k) { }
00152         attr(const attr& k) : base_class(k) { }
00153 };*/
00154 
00155 
00156 template <class ARRAY_TYPE, class CONV_TYPE, class ACCESS_TYPE =
00157         typename get_access_type<CONV_TYPE>::type>
00158 class attr :
00159         public conversions_details::attr_2<ARRAY_TYPE, CONV_TYPE, ACCESS_TYPE,
00160                 typename types::is_ivl_array<ARRAY_TYPE>::type>
00161 {
00162         typedef conversions_details::attr_2<ARRAY_TYPE, CONV_TYPE, ACCESS_TYPE,
00163                 typename types::is_ivl_array<ARRAY_TYPE>::type> base_class;
00164 public:
00165         template<class K>
00166         attr(K& k) : base_class(k) { }
00167         attr(const attr& k) : base_class(k) { }
00168 };
00169 // ---------------------------
00170 
00171 
00172 } /* namespace conversions */
00173 } /* namespace ivl */
00174 
00175 #endif // IVL_CORE_DETAILS_CONVERSIONS_ATTR_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations