libpnicore
add_op.hpp
1 //
2 // (c) Copyright 2011 DESY, Eugen Wintersberger <eugen.wintersberger@desy.de>
3 //
4 // This file is part of libpnicore.
5 //
6 // libpnicore is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // libpnicore is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with libpnicore. If not, see <http://www.gnu.org/licenses/>.
18 //
19 // ============================================================================
20 //
21 // Created on: Jul 25,2012
22 // Author: Eugen Wintersberger <eugen.wintersberger@desy.de>
23 //
24 #pragma once
25 
26 #include "op_traits.hpp"
27 #include "../../utilities/container_iterator.hpp"
28 
29 namespace pni{
30 namespace core{
31 
32  template<typename ATYPE> class array_view;
33 
34 
42  template<
43  typename OP1T,
44  typename OP2T
45  >
46  class add_op
47  {
48  private:
53  public:
54  //--------------------public types---------------------------------
56  typedef typename OP1T::value_type value_type;
60  typedef void storage_type;
65 
72 
78 
79  //===================constructors==================================
86  add_op(const OP1T &o1,const OP2T &o2):
87  _op1(o1),
88  _op2(o2)
89  { }
90 
91  //====================public methods===============================
99  value_type operator[](size_t i) const
100  {
101  return this->_op1[i]+this->_op2[i];
102 
103  }
104 
105  //-----------------------------------------------------------------
116  value_type at(size_t i) const
117  {
118  if(i>=size())
119  throw index_error(EXCEPTION_RECORD,"array index exceeded!");
120 
121  return (*this)[i];
122  }
123 
124  //-----------------------------------------------------------------
131  size_t size() const
132  {
133  return _op1.size() > _op2.size() ? _op1.size() : _op2.size();
134  }
135 
136  //=====================iterators===================================
140  const_iterator begin() const
141  {
142  return const_iterator(this,0);
143  }
144 
145  //-----------------------------------------------------------------
149  const_iterator end() const
150  {
151  return const_iterator(this,this->size());
152  }
153 
154  };
155 
156 
157 //end of namespace
158 }
159 }
OP1::inplace_arithmetic inplace_arithmetic
inplace arithmetic type
Definition: op_traits.hpp:88
#define EXCEPTION_RECORD
macro creating an instance of ExceptionRecord
Definition: exceptions.hpp:48
const_iterator end() const
get const iterator to last+1 element
Definition: add_op.hpp:149
void storage_type
storage type
Definition: add_op.hpp:60
add_op(const OP1T &o1, const OP2T &o2)
constructor
Definition: add_op.hpp:86
iterator type
Definition: container_iterator.hpp:59
OP1::map_type map_type
index map type
Definition: op_traits.hpp:86
array_trait< OP1T, OP2T >::map_type map_type
index map type
Definition: add_op.hpp:74
container_iterator< array_type > iterator
non-const iterator type - just for interface
Definition: add_op.hpp:62
index error
Definition: exceptions.hpp:437
array_trait< OP1T, OP2T >::inplace_arithmetic inplace_arithmetic
inplace arithmetic type
Definition: add_op.hpp:77
Definition: add_op.hpp:29
OP1T::value_type value_type
result type of the operation
Definition: add_op.hpp:56
value_type at(size_t i) const
get result at i
Definition: add_op.hpp:116
const_iterator begin() const
get const iterator to the first element
Definition: add_op.hpp:140
container_iterator< array_type > reverse_iterator
reverse iterator type
Definition: add_op.hpp:67
value_type operator[](size_t i) const
get result at i
Definition: add_op.hpp:99
op_trait< OP1T >::ref_type _op1
reference to the left operand
Definition: add_op.hpp:50
container_iterator< const array_type > const_reverse_iterator
const reverse iterator type
Definition: add_op.hpp:69
operator reference trait
Definition: op_traits.hpp:43
container_iterator< const array_type > const_iterator
const iterator type
Definition: add_op.hpp:64
array_view< array_type > view_type
view type
Definition: add_op.hpp:71
add_op< OP1T, OP2T > array_type
type of the expression template
Definition: add_op.hpp:58
op_trait< OP2T >::ref_type _op2
reference to the right operand
Definition: add_op.hpp:52
addition expression template
Definition: add_op.hpp:46
size_t size() const
get size
Definition: add_op.hpp:131
provides a view on a part of an array
Definition: add_op.hpp:32