operator_array3.h
説明を見る。
1 //
2 // Copyright (c) 2003-2011, MIST Project, Nagoya University
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the name of the Nagoya University nor the names of its contributors
16 // may be used to endorse or promote products derived from this software
17 // without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
20 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21 // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
26 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //
28 
33 #ifndef __INCLUDE_MIST_OPERATOR_ARRAY3__
34 #define __INCLUDE_MIST_OPERATOR_ARRAY3__
35 
36 
37 
47 template < class T, class Allocator >
48 inline const array3< T, Allocator >& operator +=( array3< T, Allocator > &a1, const array3< T, Allocator > &a2 )
49 {
50  typedef typename array3< T, Allocator >::size_type size_type;
51 #if _CHECK_ARRAY3_OPERATION_ != 0
52  if( a1.size( ) != a2.size( ) )
53  {
54  // 足し算できません例外
55  ::std::cerr << "can't add array3s." << ::std::endl;
56  return( a1 );
57  }
58 #endif
59  for( size_type i = 0 ; i < a1.size( ) ; i++ ) a1[i] += static_cast< T >( a2[i] );
60  return( a1 );
61 }
62 
63 
73 template < class T, class Allocator >
74 inline const array3< T, Allocator >& operator -=( array3< T, Allocator > &a1, const array3< T, Allocator > &a2 )
75 {
76  typedef typename array3< T, Allocator >::size_type size_type;
77 #if _CHECK_ARRAY3_OPERATION_ != 0
78  if( a1.size( ) != a2.size( ) )
79  {
80  // 引き算できません例外
81  ::std::cerr << "can't subtract array3s." << ::std::endl;
82  return( a1 );
83  }
84 #endif
85  for( size_type i = 0 ; i < a1.size( ) ; i++ ) a1[i] -= static_cast< T >( a2[i] );
86  return( a1 );
87 }
88 
89 
99 template < class T, class Allocator >
100 inline const array3< T, Allocator >& operator *=( array3< T, Allocator > &a1, const array3< T, Allocator > &a2 )
101 {
102  typedef typename array3< T, Allocator >::size_type size_type;
103 #if _CHECK_ARRAY3_OPERATION_ != 0
104  if( a1.size( ) != a2.size( ) )
105  {
106  // 掛け算できません例外
107  ::std::cerr << "can't multiply array3s." << ::std::endl;
108  return( a1 );
109  }
110 #endif
111  for( size_type i = 0 ; i < a1.size( ) ; i++ ) a1[i] *= static_cast< T >( a2[i] );
112  return( a1 );
113 }
114 
115 
125 template < class T, class Allocator >
126 inline const array3< T, Allocator >& operator /=( array3< T, Allocator > &a1, const array3< T, Allocator > &a2 )
127 {
128  typedef typename array3< T, Allocator >::size_type size_type;
129 #if _CHECK_ARRAY3_OPERATION_ != 0
130  if( a1.size( ) != a2.size( ) )
131  {
132  // 割り算できません例外
133  ::std::cerr << "can't divide array3s." << ::std::endl;
134  return( a1 );
135  }
136 #endif
137  for( size_type i = 0 ; i < a1.size( ) ; i++ ) a1[i] /= static_cast< T >( a2[i] );
138  return( a1 );
139 }
140 
141 
151 template < class T, class Allocator >
152 inline const array3< T, Allocator >& operator +=( array3< T, Allocator > &a1, typename array3< T, Allocator >::value_type val )
153 {
154  typedef typename array3< T, Allocator >::size_type size_type;
155  for( size_type i = 0 ; i < a1.size( ) ; i++ ) a1[i] += val;
156  return( a1 );
157 }
158 
159 
169 template < class T, class Allocator >
170 inline const array3< T, Allocator >& operator -=( array3< T, Allocator > &a1, typename array3< T, Allocator >::value_type val )
171 {
172  typedef typename array3< T, Allocator >::size_type size_type;
173  for( size_type i = 0 ; i < a1.size( ) ; i++ ) a1[i] -= val;
174  return( a1 );
175 }
176 
177 
187 template < class T, class Allocator >
188 inline const array3< T, Allocator >& operator *=( array3< T, Allocator > &a1, typename array3< T, Allocator >::value_type val )
189 {
190  typedef typename array3< T, Allocator >::size_type size_type;
191  for( size_type i = 0 ; i < a1.size( ) ; i++ ) a1[i] *= val;
192  return( a1 );
193 }
194 
195 
205 template < class T, class Allocator >
206 inline const array3< T, Allocator >& operator /=( array3< T, Allocator > &a1, typename array3< T, Allocator >::value_type val )
207 {
208  typedef typename array3< T, Allocator >::size_type size_type;
209 #if _CHECK_ARRAY3_OPERATION_ != 0
210  if( val == 0 )
211  {
212  // ゼロ除算発生
213  ::std::cerr << "zero division occured." << ::std::endl;
214  return( a1 );
215  }
216 #endif
217  for( size_type i = 0 ; i < a1.size( ) ; i++ ) a1[i] /= val;
218  return( a1 );
219 }
220 
221 
222 
231 template < class T, class Allocator >
232 inline array3< T, Allocator > operator -( const array3< T, Allocator > &a )
233 {
234  typedef typename array3< T, Allocator >::size_type size_type;
235  array3< T, Allocator > o( a.size1( ), a.size2( ), a.size3( ), a.reso1( ), a.reso2( ), a.reso3( ) );
236  for( size_type i = 0 ; i < o.size( ) ; i++ ) o[i] = -a[i];
237  return( o );
238 }
239 
240 
241 
251 template < class T, class Allocator >
252 inline array3< T, Allocator > operator +( const array3< T, Allocator > &a1, const array3< T, Allocator > &a2 )
253 {
254  array3< T, Allocator > tmp( a1 );
255  return( tmp += a2 );
256 }
257 
258 
259 
269 template < class T, class Allocator >
270 inline array3< T, Allocator > operator -( const array3< T, Allocator > &a1, const array3< T, Allocator > &a2 )
271 {
272  array3< T, Allocator > tmp( a1 );
273  return( tmp -= a2 );
274 }
275 
276 
277 
287 template < class T, class Allocator >
288 inline array3< T, Allocator > operator *( const array3< T, Allocator > &a1, const array3< T, Allocator > &a2 )
289 {
290  array3< T, Allocator > tmp( a1 );
291  return( tmp *= a2 );
292 }
293 
294 
295 
305 template < class T, class Allocator >
306 inline array3< T, Allocator > operator /( const array3< T, Allocator > &a1, const array3< T, Allocator > &a2 )
307 {
308  array3< T, Allocator > tmp( a1 );
309  return( tmp /= a2 );
310 }
311 
312 
322 template < class T, class Allocator >
323 inline array3< T, Allocator > operator +( const array3< T, Allocator > &a, typename array3< T, Allocator >::value_type val )
324 {
325  array3< T, Allocator > tmp( a );
326  return( tmp += val );
327 }
328 
329 
339 template < class T, class Allocator >
340 inline array3< T, Allocator > operator +( typename array3< T, Allocator >::value_type val, const array3< T, Allocator > &a )
341 {
342  array3< T, Allocator > tmp( a );
343  return( tmp += val );
344 }
345 
346 
356 template < class T, class Allocator >
357 inline array3< T, Allocator > operator -( const array3< T, Allocator > &a, typename array3< T, Allocator >::value_type val )
358 {
359  array3< T, Allocator > tmp( a );
360  return( tmp -= val );
361 }
362 
363 
373 template < class T, class Allocator >
374 inline array3< T, Allocator > operator -( typename array3< T, Allocator >::value_type val, const array3< T, Allocator > &a )
375 {
376  array3< T, Allocator > tmp( a.size1( ), a.size2( ), a.size3( ), val );
377  return( tmp -= a );
378 }
379 
380 
381 
391 template < class T, class Allocator >
392 inline array3< T, Allocator > operator *( const array3< T, Allocator > &a, typename array3< T, Allocator >::value_type val )
393 {
394  array3< T, Allocator > tmp( a );
395  return( tmp *= val );
396 }
397 
398 
408 template < class T, class Allocator >
409 inline array3< T, Allocator > operator *( typename array3< T, Allocator >::value_type val, const array3< T, Allocator > &a )
410 {
411  array3< T, Allocator > tmp( a );
412  return( tmp *= val );
413 }
414 
415 
416 
426 template < class T, class Allocator >
427 inline array3< T, Allocator > operator /( const array3< T, Allocator > &a, typename array3< T, Allocator >::value_type val )
428 {
429  array3< T, Allocator > tmp( a );
430  return( tmp /= val );
431 }
432 
433 
434 
435 #endif // __INCLUDE_MIST_OPERATOR_ARRAY3__
436 

Generated on Wed Nov 12 2014 19:44:21 for MIST by doxygen 1.8.1.2