31template <
int num_dimensions,
class elemT>
35 if (!s || (
dynamic_cast<std::ifstream*
>(&s) != 0 && !
dynamic_cast<std::ifstream*
>(&s)->is_open())
36 || (
dynamic_cast<std::fstream*
>(&s) != 0 && !
dynamic_cast<std::fstream*
>(&s)->is_open()))
38 warning(
"read_data: error before reading from stream.\n");
45 const std::streamsize num_to_read =
static_cast<std::streamsize
>(data.
size_all()) *
sizeof(elemT);
51 warning(
"read_data: error after reading from stream.\n");
61 return Succeeded::yes;
67template <
int num_dimensions,
class elemT>
71 FILE* fptr = fptr_ref;
72 if (fptr == NULL || ferror(fptr))
74 warning(
"read_data: error before reading from FILE.\n");
81 const std::size_t num_to_read =
static_cast<std::size_t
>(data.
size_all());
82 const std::size_t num_read = fread(
reinterpret_cast<char*
>(data.
get_full_data_ptr()),
sizeof(elemT), num_to_read, fptr);
85 if (ferror(fptr) || num_to_read != num_read)
87 warning(
"read_data: error after reading from FILE.\n");
94 ByteOrder::swap_order(*iter);
97 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.
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
void release_full_data_ptr()
signal end of access to elemT*
Definition Array.inl:329
elemT * get_full_data_ptr()
member function for access to the data via a elemT*
Definition Array.inl:292
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 read_data_1d(std::istream &s, ArrayType< num_dimensions, elemT > &data, const ByteOrder byte_order)
This is an internal function called by read_data(). It does the actual reading to std::istream.
Definition read_data_1d.inl:33
void warning(const char *const s,...)
Print warning with format string a la printf.
Definition warning.cxx:41
Array< num_dimensions, elemT > ArrayType
type alias for future-proofing for "large" rectangular arrays
Definition ArrayFwd.h:25
Declaration of stir::warning()