File: hack_array_seq.icc

package info (click to toggle)
rheolef 7.2-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 88,076 kB
  • sloc: cpp: 110,259; sh: 16,733; makefile: 5,438; python: 1,391; yacc: 218; javascript: 203; xml: 191; awk: 61; sed: 5
file content (125 lines) | stat: -rw-r--r-- 4,242 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
///
/// This file is part of Rheolef.
///
/// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
///
/// Rheolef is free software; you can redistribute it and/or modify
/// it under the terms of the GNU General Public License as published by
/// the Free Software Foundation; either version 2 of the License, or
/// (at your option) any later version.
///
/// Rheolef is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
/// GNU General Public License for more details.
///
/// You should have received a copy of the GNU General Public License
/// along with Rheolef; if not, write to the Free Software
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
/// 
/// =========================================================================
# include "rheolef/hack_array.h"
namespace rheolef {

// ===============================================================
// allocators
// ===============================================================
template<class T, class A>
hack_array_seq_rep<T,A>::hack_array_seq_rep (const A& alloc) 
 : base (alloc),
   _ownership  (),
   _parameter  (),
   _value_size (),
   _data_size  ()
{
}
template<class T, class A>
hack_array_seq_rep<T,A>::hack_array_seq_rep (const distributor& ownership, const parameter_type& param, const A& alloc) 
 : base (alloc),
   _ownership  (ownership),
   _parameter  (param),
   _value_size (T::_size_of  (_parameter)),
   _data_size  (T::_data_size(_parameter))
{
  _init (_ownership, _parameter);
}
template<class T, class A>
hack_array_seq_rep<T,A>::hack_array_seq_rep (size_type n, const parameter_type& param, const A& alloc) 
 : base (alloc),
   _ownership  (distributor::decide, communicator(), n),
   _parameter  (param),
   _value_size (T::_size_of  (_parameter)),
   _data_size  (T::_data_size(_parameter))
{
  _init (_ownership, _parameter);
}
template<class T, class A>
void
hack_array_seq_rep<T,A>::resize (const distributor& ownership, const parameter_type& param) 
{
  _ownership  = ownership;
  _parameter  = param;
  _value_size = T::_size_of  (_parameter);
  _data_size  = T::_data_size(_parameter);
  _init (_ownership, _parameter);
}
template<class T, class A>
void
hack_array_seq_rep<T,A>::resize (size_type n, const parameter_type& param)
{
  _ownership  = distributor  (distributor::decide, communicator(), n);
  _parameter  = param;
  _value_size = T::_size_of  (_parameter);
  _data_size  = T::_data_size(_parameter);
  _init (_ownership, _parameter);
} 
template<class T, class A>
void
hack_array_seq_rep<T,A>::_init (const distributor& ownership, const parameter_type& param) 
{
  base::_ownership = distributor (ownership.dis_size()*_value_size, ownership.comm(), ownership.size()*_value_size),
  base::resize (base::_ownership, std::numeric_limits<raw_type>::max());
  size_type *p = base::begin().operator->();
  for (size_type i = 0, n = ownership.size(); i < n; i++) {
    new (p) T;
    T* q = (T*)p;
    q -> _set_parameter(param);
    p += _value_size;
  }
}
// ===============================================================
// put & get
// ===============================================================
template <class T, class A>
template <class PutFunction>
odiststream&
hack_array_seq_rep<T,A>::put_values (odiststream& ops, PutFunction put_element) const
{
  std::ostream& os = ops.os();
  for (size_type i = 0; i < size(); i++) {
    put_element (os, operator[](i));
    os << std::endl;
  }
  return ops;
}
template <class T, class A>
odiststream&
hack_array_seq_rep<T,A>::put_values (odiststream& ops) const
{
  return put_values (ops, _disarray_put_element_type<generic_value_type>());
}
template <class T, class A>
template <class GetFunction>
idiststream&
hack_array_seq_rep<T,A>::get_values (idiststream& ips, GetFunction get_element) {
  check_macro (load_chunk (ips.is(), begin(), end(), get_element), "read failed on input stream.");
  return ips;
}
template <class T, class A>
idiststream&
hack_array_seq_rep<T,A>::get_values (idiststream& ips) 
{
  return get_values (ips, _disarray_get_element_type<generic_value_type>());
}

} // namespace rheolef