rheolef  6.6
vec_concat.h
Go to the documentation of this file.
1 #ifndef _RHEOLEF_VEC_CONCAT_H
2 #define _RHEOLEF_VEC_CONCAT_H
3 #include "rheolef/vec.h"
4 
5 namespace rheolef {
6 
7 template <class T, class M>
8 struct vec_concat_value {
9  typedef enum { scalar, scalars, vector} variant_type;
10  vec_concat_value (int x) : s(x), ss(), v(), variant(scalar) {}
11 #ifdef _RHEOLEF_HAVE_QD
12  vec_concat_value (double x) : s(x), ss(), v(), variant(scalar) {}
13 #endif // _RHEOLEF_HAVE_QD
14  vec_concat_value (const T& x) : s(x), ss(), v(), variant(scalar) {}
15  vec_concat_value (const std::vector<T>& x) : s(), ss(x), v(), variant(scalars) {}
16  vec_concat_value (const vec<T,M>& x) : s(), ss(), v(x), variant(vector) {}
17 #ifdef TO_CLEAN
18 // io/debug:
19  friend std::ostream& operator<< (std::ostream& o, const vec_concat_value<T,M>& x) {
20  if (x.variant == scalar) return o << "s";
21  if (x.variant == scalars) return o << "ss";
22  else return o << "v";
23  }
24 #endif // TO_CLEAN
25 public:
26  T s;
27  std::vector<T> ss;
30 };
31 
32 template <class T, class M>
33 struct vec_concat {
34  typedef typename vec<T,M>::size_type size_type;
36 
37 
38  vec_concat () : _l() {}
39  vec<T,M> build_vec() const;
40 
41 #ifdef _RHEOLEF_HAVE_STD_INITIALIZER_LIST
42  vec_concat (const std::initializer_list<value_type>& il) : _l() {
43 #ifdef _RHEOLEF_HAVE_STD_INITIALIZER_ITERATOR
44  typedef typename std::initializer_list<value_type>::const_iterator const_iterator;
45 #else // _RHEOLEF_HAVE_STD_INITIALIZER_ITERATOR
46  typedef const value_type* const_iterator;
47 #endif // _RHEOLEF_HAVE_STD_INITIALIZER_ITERATOR
48  for (const_iterator iter = il.begin(); iter != il.end(); ++iter) {
49  _l.push_back(*iter);
50  }
51  }
52 #endif // _RHEOLEF_HAVE_STD_INITIALIZER_LIST
53 
54 #ifdef TO_CLEAN
55  friend std::ostream& operator<< (std::ostream& o, const vec_concat<T,M>& x) {
56  std::cout << "{";
57  for(typename std::list<value_type>::const_iterator iter = x._l.begin(); iter != x._l.end(); ++iter) {
58  std::cout << *iter << " ";
59  }
60  return std::cout << "}";
61  }
62 #endif // TO_CLEAN
63 
64 protected:
65  std::list<value_type> _l;
66 };
67 
68 #ifdef _RHEOLEF_HAVE_STD_INITIALIZER_LIST
69 template <class T, class M>
70 inline
71 vec<T,M>::vec (const std::initializer_list<vec_concat_value<T,M> >& init_list)
72 {
73  vec_concat<T,M> vc (init_list);
75 }
76 template <class T, class M>
77 inline
78 vec<T,M>&
79 vec<T,M>::operator= (const std::initializer_list<vec_concat_value<T,M> >& init_list)
80 {
81  vec_concat<T,M> vc (init_list);
82  vec<T,M>::operator= (vc.build_vec());
83  return *this;
84 }
85 #endif // _RHEOLEF_HAVE_STD_INITIALIZER_LIST
86 
87 } // namespace rheolef
88 #endif // _RHEOLEF_VEC_CONCAT_H
vec< T, M >::size_type size_type
Definition: vec_concat.h:34
irheostream, orheostream - large data streams
Definition: compiler.h:7
vec_concat_value(const T &x)
Definition: vec_concat.h:14
vec_concat_value(const vec< T, M > &x)
Definition: vec_concat.h:16
vec - vector in distributed environment
Definition: vec.h:44
vec(const distributor &ownership, const T &init_val=std::numeric_limits< T >::max())
Definition: vec.h:112
std::vector< T > ss
Definition: vec_concat.h:27
std::list< value_type > _l
Definition: vec_concat.h:65
vec_concat_value< T, M > value_type
Definition: vec_concat.h:35
vec< T, M > build_vec() const
Definition: vec_concat.cc:7
base::size_type size_type
Definition: vec.h:49
vec_concat_value(const std::vector< T > &x)
Definition: vec_concat.h:15
vec< T, M > & operator=(const vec_range< T, M > &vr)
Definition: vec.h:173