ivl 679
ivl/details/array/impl/array_base.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_DETAILS_ARRAY_BASE_ARRAY_BASE_HPP
00025 #define IVL_DETAILS_ARRAY_BASE_ARRAY_BASE_HPP
00026 
00027 namespace ivl {
00028 
00030 template <class T, class SPEC, bool VALID = true>
00031 class array_base
00032 : public SPEC, public types::array_identifier
00033 {
00034 private:
00035         typedef array_base prv_this_type;
00036 
00037         // note: only the array_base can get the derived type directly from SPEC
00038         typedef typename prv_this_type::derived_param prv_derived_type;
00039 
00040         template <class A>
00041         struct hc_tpl
00042         {
00043                 typedef typename types::highest_common<
00044                         prv_derived_type,
00045                         typename A::derived_type>::type_a type;
00046         };
00047         struct invalid_init_arg {};
00048 
00049 public:
00050         typedef T elem_type;
00051         typedef array_base this_type;
00052 
00053         // useful
00054         typedef typename SPEC::template change_derived_param<types::term>
00055                 ::type data_type;
00056         typedef typename data::get_image_channels<data_type>::type im_channels;
00057         enum { Ch = im_channels::value };
00058         //
00059         typedef types::invalid_arg_t<invalid_init_arg> all_init_arg;
00060         typedef types::invalid_arg_t<invalid_init_arg> data_init_arg;
00061 
00062     typedef prv_derived_type derived_type;
00063 
00064         const derived_type& derived() const
00065                 { return *static_cast<const derived_type*>(this); }
00066         derived_type& derived()
00067                 { return *static_cast<derived_type*>(this); }
00068         derived_type& const_cast_derived() const
00069                 { return *static_cast<derived_type*>(const_cast<array_base*>(this)); }
00070 
00071         template <class A>
00072         const typename hc_tpl<A>::type& highest_common_class(const A* = 0) const
00073                 { return *static_cast<const typename hc_tpl<A>::type*>(this); }
00074         template <class A>
00075         typename hc_tpl<A>::type& highest_common_class(const A* = 0)
00076                 { return *static_cast<typename hc_tpl<A>::type*>(this); }
00077 
00078 };
00079 
00080 template <class T, class S>
00081 class array_base<T, S, false>
00082 {
00083         array_base() {} // private
00084 };
00085 
00086 // TODO: this is just wrong! no functions should be actually declared for array_base.
00087 // there is array_common_base for such purposes
00089 template<class T, class S>
00090 std::ostream& operator<<(std::ostream& os, const array_base<T, S, true>& in)
00091 {
00092         return in.derived().print(os);
00093 }
00094 
00095 template <class C>
00096 class array_common_base
00097 {
00098 };
00099 
00100 template <class T, class C>
00101 class common_container_base
00102 {
00103 };
00104 
00105 } //namespace ivl
00106 
00107 #endif // IVL_DETAILS_ARRAY_BASE_ARRAY_BASE_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations