11 #include "IStreamReader.hpp" 12 #include "IStreamWriter.hpp" 23 template <
size_t sizeVar, Endian VE>
26 template <atInt32 sizeVar, Endian VE>
29 template <atInt32 sizeVar, Endian VE>
32 template <atInt32 sizeVar, Endian VE>
44 template <Endian DNAE>
62 virtual size_t binarySize(
size_t __isz)
const=0;
69 template <
typename T, Endian VE = DNAE>
78 template <
typename T,
size_t cntVar, Endian VE = DNAE>
86 template <
size_t sizeVar>
94 template <atInt32 sizeVar = -1>
102 template <atInt32 sizeVar = -1, Endian VE = DNAE>
110 template <atInt32 sizeVar = -1>
118 template <off_t offset, SeekOrigin direction>
125 template <
size_t align>
139 template <
typename T>
142 for (
const auto& val : v)
143 __isz = val.binarySize(__isz);
151 template <
size_t sizeVar, Endian VE>
152 struct Buffer :
public DNA<VE>,
public std::unique_ptr<atUint8[]>
157 reset(
new atUint8[sizeVar]);
166 return __isz + sizeVar;
173 template <atInt32 sizeVar, Endian VE>
174 struct String :
public DNA<VE>,
public std::string
178 {this->assign(std::move(reader.
readString(sizeVar)));}
182 {
return __isz + ((sizeVar<0)?(this->size()+1):sizeVar);}
183 std::string& operator=(
const std::string& __str)
184 {
return this->assign(__str);}
185 std::string& operator=(std::string&& __str)
186 {this->swap(__str);
return *
this;}
192 template <atInt32 sizeVar, Endian VE>
193 struct WString :
public DNA<VE>,
public std::wstring
198 reader.setEndian(VE);
199 this->assign(std::move(reader.
readWString(sizeVar)));
203 writer.setEndian(VE);
207 {
return __isz + (((sizeVar<0)?(this->size()+1):sizeVar)*2);}
208 std::wstring& operator=(
const std::wstring& __str)
209 {
return this->assign(__str);}
210 std::wstring& operator=(std::wstring&& __str)
211 {this->swap(__str);
return *
this;}
217 template <atInt32 sizeVar, Endian VE>
226 {
return __isz + (((sizeVar<0)?(this->size()+1):sizeVar)*2);}
227 std::string& operator=(
const std::string& __str)
228 {
return this->assign(__str);}
229 std::string& operator=(std::string&& __str)
230 {this->swap(__str);
return *
this;}
235 void read(athena::io::IStreamReader&); \ 236 void write(athena::io::IStreamWriter&) const; \ 237 size_t binarySize(size_t __isz) const; 240 #define DECL_EXPLICIT_DNA \ 241 void read(athena::io::IStreamReader&); \ 242 void write(athena::io::IStreamWriter&) const; \ 243 size_t binarySize(size_t __isz) const; \ 248 #define DNA_COUNT(cnt) sizeof(cnt) 250 #define DNA_COUNT(cnt) 0 virtual size_t binarySize(size_t __isz) const =0
Common virtual binary size computation for all DNA types.
void write(IStreamWriter &writer) const
Common virtual write function for all DNA types.
size_t binarySize(size_t __isz) const
Common virtual binary size computation for all DNA types.
Meta Template preventing atdna from emitting read/write implementations.
std::string readWStringAsString(atInt32 fixedLen=-1)
Reads a wide-char string (using endianness from setEndian), converts to UTF8 and advances the positio...
std::wstring readWString(atInt32 fixedLen=-1)
Reads a wstring and advances the position in the file.
virtual void write(IStreamWriter &) const =0
Common virtual write function for all DNA types.
void writeWString(const std::wstring &str, atInt32 fixedLen=-1)
Writes an wstring to the buffer and advances the buffer.
Base DNA class used against 'atdna'.
virtual void writeUBytes(const atUint8 *data, atUint64 len)=0
Writes the given buffer with the specified length, buffers can be bigger than the length however it's...
size_t binarySize(size_t __isz) const
Common virtual binary size computation for all DNA types.
void read(IStreamReader &reader)
Common virtual read function for all DNA types.
Concrete converting-wstring type used by DNA::WStringAsString.
The IStreamReader class defines a basic API for reading from streams, Implementors are provided with ...
Concrete buffer type used by DNA::Buffer.
void read(IStreamReader &reader)
Common virtual read function for all DNA types.
virtual void read(IStreamReader &)=0
Common virtual read function for all DNA types.
size_t binarySize(size_t __isz) const
Common virtual binary size computation for all DNA types.
void writeStringAsWString(const std::string &str, atInt32 fixedLen=-1)
Converts a UTF8 string to a wide-char string in the buffer and advances the buffer. It also swaps the bytes depending on the platform and Stream settings.
void write(IStreamWriter &writer) const
Common virtual write function for all DNA types.
size_t binarySize(size_t __isz) const
Common virtual binary size computation for all DNA types.
Concrete wstring type used by DNA::WString.
void read(IStreamReader &reader)
Common virtual read function for all DNA types.
void write(IStreamWriter &writer) const
Common virtual write function for all DNA types.
std::string readString(atInt32 fixedLen=-1)
Reads a string and advances the position in the file.
Meta Template signaling atdna to insert an aligning stream seek where it's used.
Meta Template signaling atdna to insert a stream seek where it's used.
T Value
Template type signaling atdna to capture the value where it's used.
void write(IStreamWriter &writer) const
Common virtual write function for all DNA types.
void writeString(const std::string &str, atInt32 fixedLen=-1)
Writes an string to the buffer and advances the buffer.
Concrete string type used by DNA::String.
std::vector< T > Vector
Template type wrapping std::vector and signaling atdna to manipulate it where it's used...
virtual atUint64 readUBytesToBuf(void *buf, atUint64 len)=0
Attempts to read a fixed length of data into a pre-allocated buffer, this function is client defined ...
static size_t __EnumerateSize(size_t __isz, const T &v)
Internal DNA helper for accumulating binarySize.
void read(IStreamReader &reader)
Common virtual read function for all DNA types.