ivl 679
ivl/details/core/data/elem_func_array.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_ARRAY_DETAILS_ELEM_FUNC_ARRAY_HPP
00025 #define IVL_ARRAY_DETAILS_ELEM_FUNC_ARRAY_HPP
00026 
00027 
00028 namespace ivl {
00029 
00030 namespace data {
00031 
00032 template <class T, template <typename, typename, typename> class A, class DI,
00033         template<typename, typename, typename> class F, class A1, class A2>
00034 class elem_func_binary_set
00035 {
00036 };
00037 
00038 template <template<typename, typename, typename> class F, class A1, class A2>
00039 struct use_elem_func_binary_set
00040 {
00041         template <class T, template <typename, typename, typename> class A,
00042                 class DERIVED_CLASS>
00043         struct instance
00044         {
00045                 typedef elem_func_binary_set <T, A, DERIVED_CLASS, F, A1, A2> type;
00046         };
00047 };
00048 
00049 template <class T, class DI,
00050         template<typename, typename, typename> class F, class A1, class A2>
00051 class elem_func_binary_set<T, array, DI, F, A1, A2>
00052 {
00053 private:
00054         typedef elem_func_binary_set<T, array, DI, F, A1, A2> this_type;
00055         const A1& in1;
00056         const A2& in2;
00057         typedef typename types::elem_func_binary_info<T, F, A1, A2, DI>::elem_type1 elem_type1;
00058         typedef typename types::elem_func_binary_info<T, F, A1, A2, DI>::elem_type2 elem_type2;
00059 
00060 public:
00061         typedef typename types::elem_func_binary_info<T, F, A1, A2, DI>::
00062                 created_data_class_set created_data_class_set;
00063 
00064 
00065         elem_func_binary_set(const A1& in_array1, const A2& in_array2) :
00066                 in1(in_array1), in2(in_array2) {};
00067 
00068         // for array<T>
00069 
00070         size_t length() const
00071         {
00072                 CHECK(in1.derived().length() == in2.derived().length(), eshape);
00073                 return in1.derived().length();
00074         }
00075 
00076         T operator[](size_t i) const
00077         {
00078                 return (F<T, elem_type1, elem_type2>::elem_op(in1.derived()[i], in2.derived()[i]));
00079         }
00080 
00081         // no resize
00082 
00083         struct iterator : public data::index_iterator<T, this_type>
00084         {
00085                 iterator(this_type& me, size_t pos) : data::index_iterator<T, this_type> (me, pos) { };
00086         };
00087         struct const_iterator : public data::index_iterator<const T, this_type>
00088         {
00089                 const_iterator(this_type& me, size_t pos) : data::index_iterator<const T, this_type> (me, pos) { };
00090         };
00091 
00092         iterator begin() { return iterator(*this, 0); }
00093         iterator end() { return iterator(*this, length()); }
00094         const_iterator begin() const { return const_iterator(*this, 0); }
00095         const_iterator end() const { return const_iterator(*this, length()); }
00096 
00097 
00098         // no c_ptr
00099 };
00100 
00101 
00102 
00103 
00104 
00105 
00106 
00107 } //namespace data
00108 
00109 } //namespace ivl
00110 
00111 
00112 #endif // IVL_ARRAY_DETAILS_ELEM_FUNC_ARRAY_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations