28 _Success_(
return)
bool read_id(_In_ std::istream& stream, _Out_ T_ID &
id, _In_opt_ std::streamoff end = (std::streamoff)-1)
30 if (end == (std::streamoff)-1 || stream.tellg() < end) {
31 stream.read((
char*)&
id,
sizeof(
id));
47 template <
class T_SIZE,
unsigned int ALIGN>
48 bool ignore(_In_ std::istream& stream)
52 stream.read((
char*)&size,
sizeof(size));
53 if (!stream.good())
return false;
56 size += (T_SIZE)(ALIGN - size) % ALIGN;
58 if (!stream.good())
return false;
75 template <
class T_ID,
class T_SIZE,
unsigned int ALIGN>
76 bool find(_In_ std::istream& stream, _In_ T_ID
id, _In_opt_ std::streamoff end = (std::streamoff)-1)
80 while (end == (std::streamoff)-1 || stream.tellg() < end) {
81 stream.read((
char*)&_id,
sizeof(_id));
82 if (!stream.good())
return false;
88 ignore<T_SIZE, ALIGN>(stream);
103 template <
class T_ID,
class T_SIZE>
104 std::streamoff open(_In_ std::ostream& stream, _In_ T_ID
id)
106 std::streamoff start = stream.tellp();
109 if (stream.fail())
return (std::streamoff)-1;
110 stream.write((
const char*)&
id,
sizeof(
id));
113 if (stream.fail())
return (std::streamoff)-1;
115 stream.write((
const char*)&size,
sizeof(size));
129 template <
class T_ID,
class T_SIZE,
unsigned int ALIGN>
130 std::streamoff close(_In_ std::ostream& stream, _In_ std::streamoff start)
132 std::streamoff end = stream.tellp();
134 size = (T_SIZE)(end - start -
sizeof(T_ID) -
sizeof(T_SIZE)),
135 remainder = (T_SIZE)(ALIGN - size) % ALIGN;
139 static const char padding[ALIGN] = {};
140 stream.write(padding, remainder);
145 if (stream.fail())
return (std::streamoff)-1;
146 stream.seekp(start +
sizeof(T_ID));
147 stream.write((
const char*)&size,
sizeof(size));
157 template <
class T,
class T_ID, const T_ID ID,
class T_SIZE,
unsigned int ALIGN>
180 static const T_ID
id()
207 static std::streamoff
open(_In_ std::ostream& stream)
209 return stdex::idrec::open<T_ID, T_SIZE>(stream, ID);
221 static std::streamoff
close(_In_ std::ostream& stream, _In_ std::streamoff start)
223 return stdex::idrec::close<T_ID, T_SIZE, ALIGN>(stream, start);
237 static bool find(_In_ std::istream& stream, _In_opt_ std::streamoff end = (std::streamoff)-1)
239 return stdex::idrec::find<T_ID, T_SIZE, ALIGN>(stream, ID, end);
257template <
class T,
class T_ID, T_ID ID,
class T_SIZE,
unsigned int ALIGN>
262 std::streamoff start = r.open(stream);
263 if (stream.fail())
return stream;
265 r.close(stream, start);
279template <
class T,
class T_ID, T_ID ID,
class T_SIZE,
unsigned int ALIGN>
286 stream.read((
char*)&size,
sizeof(size));
287 if (!stream.good())
return stream;
290 std::streamoff start = stream.tellg();
293 size += (T_SIZE)(ALIGN - size) % ALIGN;
294 stream.seekg(start + size);
Helper class for read/write of records to/from memory.
Definition: idrec.hpp:159
static bool find(std::istream &stream, std::streamoff end=(std::streamoff) -1)
Finds record data.
Definition: idrec.hpp:237
T & data
Record data reference.
Definition: idrec.hpp:243
static const T_ID id()
Returns record id.
Definition: idrec.hpp:180
static std::streamoff open(std::ostream &stream)
Writes record header.
Definition: idrec.hpp:207
const record< T, T_ID, ID, T_SIZE, ALIGN > & operator=(const record< T, T_ID, ID, T_SIZE, ALIGN > &r)
Assignment operator.
Definition: idrec.hpp:193
record(T &d)
Constructs the class.
Definition: idrec.hpp:166
record(const T &d)
Constructs the class.
Definition: idrec.hpp:174
static std::streamoff close(std::ostream &stream, std::streamoff start)
Updates record header.
Definition: idrec.hpp:221