@@ -27,9 +27,9 @@ namespace detail
27
27
28
28
/* **************** version for ostream *******************************/
29
29
30
- template <class elemT >
30
+ template <int num_dimensions, class elemT >
31
31
inline Succeeded
32
- write_data_1d (std::ostream& s, const Array<1 , elemT>& data, const ByteOrder byte_order, const bool can_corrupt_data)
32
+ write_data_1d (std::ostream& s, const Array<num_dimensions , elemT>& data, const ByteOrder byte_order, const bool can_corrupt_data)
33
33
{
34
34
if (!s || (dynamic_cast <std::ofstream*>(&s) != 0 && !dynamic_cast <std::ofstream*>(&s)->is_open ())
35
35
|| (dynamic_cast <std::fstream*>(&s) != 0 && !dynamic_cast <std::fstream*>(&s)->is_open ()))
@@ -44,40 +44,40 @@ write_data_1d(std::ostream& s, const Array<1, elemT>& data, const ByteOrder byte
44
44
/*
45
45
if (!byte_order.is_native_order())
46
46
{
47
- Array<1 , elemT> a_copy(data);
47
+ Array<num_dimensions , elemT> a_copy(data);
48
48
for(int i=data.get_min_index(); i<=data.get_max_index(); i++)
49
49
ByteOrder::swap_order(a_copy[i]);
50
50
return write_data(s, a_copy, ByteOrder::native, true);
51
51
}
52
52
*/
53
53
if (!byte_order.is_native_order ())
54
54
{
55
- Array<1 , elemT>& data_ref = const_cast <Array<1 , elemT>&>(data);
56
- for (int i = data. get_min_index (); i <= data. get_max_index (); ++i )
57
- ByteOrder::swap_order (data_ref[i] );
55
+ Array<num_dimensions , elemT>& data_ref = const_cast <Array<num_dimensions , elemT>&>(data);
56
+ for (auto iter = data_ref. begin_all (); iter != data_ref. end_all (); ++iter )
57
+ ByteOrder::swap_order (*iter );
58
58
}
59
59
60
60
// note: find num_to_write (using size()) outside of s.write() function call
61
61
// otherwise Array::check_state() in size() might abort if
62
62
// get_const_data_ptr() is called before size() (which is compiler dependent)
63
- const std::streamsize num_to_write = static_cast <std::streamsize>(data.size ()) * sizeof (elemT);
63
+ const std::streamsize num_to_write = static_cast <std::streamsize>(data.size_all ()) * sizeof (elemT);
64
64
bool writing_ok = true ;
65
65
try
66
66
{
67
- s.write (reinterpret_cast <const char *>(data.get_const_data_ptr ()), num_to_write);
67
+ s.write (reinterpret_cast <const char *>(data.get_const_full_data_ptr ()), num_to_write);
68
68
}
69
69
catch (...)
70
70
{
71
71
writing_ok = false ;
72
72
}
73
73
74
- data.release_const_data_ptr ();
74
+ data.release_const_full_data_ptr ();
75
75
76
76
if (!can_corrupt_data && !byte_order.is_native_order ())
77
77
{
78
- Array<1 , elemT>& data_ref = const_cast <Array<1 , elemT>&>(data);
79
- for (int i = data. get_min_index (); i <= data. get_max_index (); ++i )
80
- ByteOrder::swap_order (data_ref[i] );
78
+ Array<num_dimensions , elemT>& data_ref = const_cast <Array<num_dimensions , elemT>&>(data);
79
+ for (auto iter = data_ref. begin_all (); iter != data_ref. end_all (); ++iter )
80
+ ByteOrder::swap_order (*iter );
81
81
}
82
82
83
83
if (!writing_ok || !s)
@@ -92,9 +92,9 @@ write_data_1d(std::ostream& s, const Array<1, elemT>& data, const ByteOrder byte
92
92
/* **************** version for FILE *******************************/
93
93
// largely a copy of above, but with calls to stdio function
94
94
95
- template <class elemT >
95
+ template <int num_dimensions, class elemT >
96
96
inline Succeeded
97
- write_data_1d (FILE*& fptr_ref, const Array<1 , elemT>& data, const ByteOrder byte_order, const bool can_corrupt_data)
97
+ write_data_1d (FILE*& fptr_ref, const Array<num_dimensions , elemT>& data, const ByteOrder byte_order, const bool can_corrupt_data)
98
98
{
99
99
FILE* fptr = fptr_ref;
100
100
if (fptr == 0 || ferror (fptr))
@@ -109,33 +109,33 @@ write_data_1d(FILE*& fptr_ref, const Array<1, elemT>& data, const ByteOrder byte
109
109
/*
110
110
if (!byte_order.is_native_order())
111
111
{
112
- Array<1 , elemT> a_copy(data);
112
+ Array<num_dimensions , elemT> a_copy(data);
113
113
for(int i=data.get_min_index(); i<=data.get_max_index(); i++)
114
114
ByteOrder::swap_order(a_copy[i]);
115
115
return write_data(s, a_copy, ByteOrder::native, true);
116
116
}
117
117
*/
118
118
if (!byte_order.is_native_order ())
119
119
{
120
- Array<1 , elemT>& data_ref = const_cast <Array<1 , elemT>&>(data);
121
- for (int i = data. get_min_index (); i <= data. get_max_index (); ++i )
122
- ByteOrder::swap_order (data_ref[i] );
120
+ Array<num_dimensions , elemT>& data_ref = const_cast <Array<num_dimensions , elemT>&>(data);
121
+ for (auto iter = data_ref. begin_all (); iter != data_ref. end_all (); ++iter )
122
+ ByteOrder::swap_order (*iter );
123
123
}
124
124
125
125
// note: find num_to_write (using size()) outside of s.write() function call
126
126
// otherwise Array::check_state() in size() might abort if
127
127
// get_const_data_ptr() is called before size() (which is compiler dependent)
128
- const std::size_t num_to_write = static_cast <std::size_t >(data.size ());
128
+ const std::size_t num_to_write = static_cast <std::size_t >(data.size_all ());
129
129
const std::size_t num_written
130
- = fwrite (reinterpret_cast <const char *>(data.get_const_data_ptr ()), sizeof (elemT), num_to_write, fptr);
130
+ = fwrite (reinterpret_cast <const char *>(data.get_const_full_data_ptr ()), sizeof (elemT), num_to_write, fptr);
131
131
132
- data.release_const_data_ptr ();
132
+ data.release_const_full_data_ptr ();
133
133
134
134
if (!can_corrupt_data && !byte_order.is_native_order ())
135
135
{
136
- Array<1 , elemT>& data_ref = const_cast <Array<1 , elemT>&>(data);
137
- for (int i = data. get_min_index (); i <= data. get_max_index (); ++i )
138
- ByteOrder::swap_order (data_ref[i] );
136
+ Array<num_dimensions , elemT>& data_ref = const_cast <Array<num_dimensions , elemT>&>(data);
137
+ for (auto iter = data_ref. begin_all (); iter != data_ref. end_all (); ++iter )
138
+ ByteOrder::swap_order (*iter );
139
139
}
140
140
141
141
if (num_written != num_to_write || ferror (fptr))
0 commit comments