From 7524b1f063d562de7b21a8adcc8d32c3656dc761 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Thu, 25 Jun 2015 09:37:31 -1000 Subject: [PATCH] made string and buffer types templates with DNA base; may now be used in Vector --- include/Athena/DNA.hpp | 59 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/include/Athena/DNA.hpp b/include/Athena/DNA.hpp index daf0bc7..415ca71 100644 --- a/include/Athena/DNA.hpp +++ b/include/Athena/DNA.hpp @@ -36,16 +36,67 @@ struct DNA using Vector = std::vector; template - using Buffer = std::unique_ptr; + struct Buffer : public DNA, public std::unique_ptr + { + Delete expl; + inline void read(IStreamReader& reader) + { + reset(new atUint8[sizeVar]); + reader.readUBytesToBuf(get(), sizeVar); + } + inline void write(IStreamWriter& writer) const + { + writer.writeUBytes(get(), sizeVar); + } + }; template - using String = std::string; + struct String : public DNA, public std::string + { + Delete expl; + inline void read(IStreamReader& reader) + {*this = reader.readString(sizeVar);} + inline void write(IStreamWriter& writer) const + {writer.writeString(*this, sizeVar);} + inline std::string& operator=(const std::string& __str) + {return this->assign(__str);} + inline std::string& operator=(std::string&& __str) + {this->swap(__str); return *this;} + }; template - using WString = std::wstring; + struct WString : public DNA, public std::wstring + { + Delete expl; + inline void read(IStreamReader& reader) + { + reader.setEndian(VE); + *this = reader.readWString(sizeVar); + } + inline void write(IStreamWriter& writer) const + { + writer.setEndian(VE); + writer.writeWString(*this, sizeVar); + } + inline std::wstring& operator=(const std::wstring& __str) + {return this->assign(__str);} + inline std::wstring& operator=(std::wstring&& __str) + {this->swap(__str); return *this;} + }; template - using UTF8 = std::string; + struct UTF8 : public DNA, public std::string + { + Delete expl; + inline void read(IStreamReader& reader) + {*this = reader.readUTF8(sizeVar);} + inline void write(IStreamWriter& writer) const + {writer.writeUTF8(*this, sizeVar);} + inline std::string& operator=(const std::string& __str) + {return this->assign(__str);} + inline std::string& operator=(std::string&& __str) + {this->swap(__str); return *this;} + }; template struct Seek {};