STIR  6.2.0
assign.h
Go to the documentation of this file.
1 
2 /*
3  Copyright (C) 2005- 2009, Hammersmith Imanet Ltd
4  This file is part of STIR.
5 
6  SPDX-License-Identifier: Apache-2.0
7 
8  See STIR/LICENSE.txt for details
9 */
10 
11 #ifndef __stir_assign_H__
12 #define __stir_assign_H__
13 
22 #include "stir/VectorWithOffset.h"
23 #include "stir/Array.h"
24 #include "stir/BasicCoordinate.h"
25 #include <vector>
26 
27 START_NAMESPACE_STIR
46 
47 template <class T, class T2>
48 inline void
49 assign(T& x, const T2& y)
50 {
51  x = y;
52 }
53 
54 template <class T, class T2>
55 inline void
56 assign(std::vector<T>& v, const T2& y)
57 {
58  for (typename std::vector<T>::iterator iter = v.begin(); iter != v.end(); ++iter)
59  assign(*iter, y);
60 }
61 
62 template <int num_dimensions, class T, class T2>
63 inline void
64 assign(BasicCoordinate<num_dimensions, T>& v, const T2& y)
65 {
66  for (typename BasicCoordinate<num_dimensions, T>::iterator iter = v.begin(); iter != v.end(); ++iter)
67  assign(*iter, y);
68 }
69 
70 template <class T, class T2>
71 inline void
72 assign(VectorWithOffset<T>& v, const T2& y)
73 {
74  for (typename VectorWithOffset<T>::iterator iter = v.begin(); iter != v.end(); ++iter)
75  assign(*iter, y);
76 }
77 
78 // Even though we have VectorWithOffset above, we still seem to need a version for Arrays as well
79 // for when calling assign(vector<array<1,float> >, 0).
80 // We're not sure why...
81 template <int num_dimensions, class T, class T2>
82 inline void
83 assign(Array<num_dimensions, T>& v, const T2& y)
84 {
85  for (typename Array<num_dimensions, T>::full_iterator iter = v.begin_all(); iter != v.end_all(); ++iter)
86  assign(*iter, y);
87 }
88 
89 // a few common cases given explictly here such that we don't get conversion warnings all the time.
90 inline void
91 assign(double& x, const int y)
92 {
93  x = static_cast<double>(y);
94 }
95 
96 inline void
97 assign(float& x, const int y)
98 {
99  x = static_cast<float>(y);
100 }
102 
103 END_NAMESPACE_STIR
104 
105 #endif
defines the Array class for multi-dimensional (numeric) arrays
This file declares class stir::BasicCoordinate and some functions acting on stir::BasicCoordinate obj...
defines the stir::VectorWithOffset class