31template <
int num_dimensions,
class elemT>
35 if (!s || (
dynamic_cast<std::ofstream*
>(&s) != 0 && !
dynamic_cast<std::ofstream*
>(&s)->is_open())
36 || (
dynamic_cast<std::fstream*
>(&s) != 0 && !
dynamic_cast<std::fstream*
>(&s)->is_open()))
38 warning(
"write_data: error before writing to stream.\n");
64 const std::streamsize num_to_write =
static_cast<std::streamsize
>(data.
size_all()) *
sizeof(elemT);
65 bool writing_ok =
true;
84 if (!writing_ok || !s)
86 warning(
"write_data: error after writing to stream.\n");
90 return Succeeded::yes;
96template <
int num_dimensions,
class elemT>
100 FILE* fptr = fptr_ref;
101 if (fptr == 0 || ferror(fptr))
103 warning(
"write_data: error before writing to FILE.\n");
104 return Succeeded::no;
121 Array<num_dimensions, elemT>& data_ref =
const_cast<Array<num_dimensions, elemT>&
>(data);
122 for (
auto iter = data_ref.begin_all(); iter != data_ref.end_all(); ++iter)
123 ByteOrder::swap_order(*iter);
129 const std::size_t num_to_write =
static_cast<std::size_t
>(data.
size_all());
130 const std::size_t num_written
137 Array<num_dimensions, elemT>& data_ref =
const_cast<Array<num_dimensions, elemT>&
>(data);
138 for (
auto iter = data_ref.begin_all(); iter != data_ref.end_all(); ++iter)
139 ByteOrder::swap_order(*iter);
142 if (num_written != num_to_write || ferror(fptr))
144 warning(
"write_data: error after writing to FILE.\n");
145 return Succeeded::no;
148 return Succeeded::yes;
defines the stir::Array class for multi-dimensional (numeric) arrays
This file declares the stir::ByteOrder class.
Declaration of class stir::Succeeded.
This class defines multi-dimensional (numeric) arrays.
Definition Array.h:78
full_iterator begin_all()
start value for iterating through all elements in the array, see full_iterator
Definition Array.inl:213
size_t size_all() const
return the total number of elements in this array
Definition Array.inl:262
const elemT * get_const_full_data_ptr() const
member function for access to the data via a const elemT*
Definition Array.inl:311
void release_const_full_data_ptr() const
signal end of access to const elemT*
Definition Array.inl:345
full_iterator end_all()
end value for iterating through all elements in the array, see full_iterator
Definition Array.inl:185
This class provides member functions to find out what byte-order your machine is and to swap numbers.
Definition ByteOrder.h:100
bool is_native_order() const
check if the object refers to the native order.
Definition ByteOrder.inl:39
static void swap_order(NUMBER &value)
swap the byteorder of the argument
Definition ByteOrder.h:122
a class containing an enumeration type that can be used by functions to signal successful operation o...
Definition Succeeded.h:44
Succeeded write_data_1d(std::ostream &s, const Array< num_dimensions, elemT > &data, const ByteOrder byte_order, const bool can_corrupt_data)
This is an internal function called by write_data(). It does the actual writing to std::ostream.
Definition write_data_1d.inl:33
void warning(const char *const s,...)
Print warning with format string a la printf.
Definition warning.cxx:41
Declaration of stir::warning()