27 _Success_(
return)
bool read_id(_In_ std::istream& stream, _Out_ T_ID &
id, _In_opt_ std::streamoff end = (std::streamoff)-1)
29 if (end == (std::streamoff)-1 || stream.tellg() < end) {
30 stream.read((
char*)&
id,
sizeof(
id));
46 template <
class T_SIZE,
unsigned int ALIGN>
47 bool ignore(_In_ std::istream& stream)
51 stream.read((
char*)&size,
sizeof(size));
52 if (!stream.good())
return false;
55 size += (T_SIZE)(ALIGN - size) % ALIGN;
57 if (!stream.good())
return false;
74 template <
class T_ID,
class T_SIZE,
unsigned int ALIGN>
75 bool find(_In_ std::istream& stream, _In_ T_ID
id, _In_opt_ std::streamoff end = (std::streamoff)-1)
79 while (end == (std::streamoff)-1 || stream.tellg() < end) {
80 stream.read((
char*)&_id,
sizeof(_id));
81 if (!stream.good())
return false;
87 ignore<T_SIZE, ALIGN>(stream);
102 template <
class T_ID,
class T_SIZE>
103 std::streamoff open(_In_ std::ostream& stream, _In_ T_ID
id)
105 std::streamoff start = stream.tellp();
108 if (stream.fail())
return (std::streamoff)-1;
109 stream.write((
const char*)&
id,
sizeof(
id));
112 if (stream.fail())
return (std::streamoff)-1;
114 stream.write((
const char*)&size,
sizeof(size));
128 template <
class T_ID,
class T_SIZE,
unsigned int ALIGN>
129 std::streamoff close(_In_ std::ostream& stream, _In_ std::streamoff start)
131 std::streamoff end = stream.tellp();
133 size = (T_SIZE)(end - start -
sizeof(T_ID) -
sizeof(T_SIZE)),
134 remainder = (T_SIZE)(ALIGN - size) % ALIGN;
138 static const char padding[ALIGN] = {};
139 stream.write(padding, remainder);
144 if (stream.fail())
return (std::streamoff)-1;
145 stream.seekp(start +
sizeof(T_ID));
146 stream.write((
const char*)&size,
sizeof(size));
156 template <
class T,
class T_ID,
class T_SIZE,
unsigned int ALIGN>
197 static std::streamoff
open(_In_ std::ostream& stream)
199 return stdex::idrec::open<T_ID, T_SIZE>(stream,
id);
211 static std::streamoff
close(_In_ std::ostream& stream, _In_ std::streamoff start)
213 return stdex::idrec::close<T_ID, T_SIZE, ALIGN>(stream, start);
227 static bool find(_In_ std::istream& stream, _In_opt_ std::streamoff end = (std::streamoff)-1)
229 return stdex::idrec::find<T_ID, T_SIZE, ALIGN>(stream,
id, end);
233 static const T_ID
id;
248template <
class T,
class T_ID,
class T_SIZE,
unsigned int ALIGN>
253 std::streamoff start = r.open(stream);
254 if (stream.fail())
return stream;
256 r.close(stream, start);
270template <
class T,
class T_ID,
class T_SIZE,
unsigned int ALIGN>
277 stream.read((
char*)&size,
sizeof(size));
278 if (!stream.good())
return stream;
281 std::streamoff start = stream.tellg();
284 size += (T_SIZE)(ALIGN - size) % ALIGN;
285 stream.seekg(start + size);
Helper class for read/write of records to/from memory.
Definition: idrec.h:158
T & data
Record data reference.
Definition: idrec.h:234
static std::streamoff close(std::ostream &stream, std::streamoff start)
Updates record header.
Definition: idrec.h:211
static bool find(std::istream &stream, std::streamoff end=(std::streamoff) -1)
Finds record data.
Definition: idrec.h:227
static const T_ID id
Record id.
Definition: idrec.h:233
static std::streamoff open(std::ostream &stream)
Writes record header.
Definition: idrec.h:197
record(const T &d)
Constructs the class.
Definition: idrec.h:173
record(T &d)
Constructs the class.
Definition: idrec.h:165
const record< T, T_ID, T_SIZE, ALIGN > & operator=(const record< T, T_ID, T_SIZE, ALIGN > &r)
Assignment operator.
Definition: idrec.h:183