From bf95986e06eb00202f728daf6d197d17321b3f12 Mon Sep 17 00:00:00 2001 From: zawz Date: Wed, 5 Feb 2020 14:26:25 +0100 Subject: [PATCH] filedat: add string overload --- include/filedat.hpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/include/filedat.hpp b/include/filedat.hpp index 74e1ddb..1fef2b9 100644 --- a/include/filedat.hpp +++ b/include/filedat.hpp @@ -151,6 +151,8 @@ namespace ztd @return String value of the whole chunk data */ std::string strval(unsigned int alignment=0, std::string const& aligner="\t") const; + //! @brief alias for strval() + inline std::string str(unsigned int alignment=0, std::string const& aligner="\t") const { return strval(alignment, aligner); } void addToMap(std::string const& name, chunkdat const& val); void addToMap(std::vector> const& vec); @@ -230,23 +232,27 @@ namespace ztd inline chunkdat& operator[](const unsigned int a) const { return subChunkRef(a); } //! @brief Set chunk data and return *this. @see set(chunkdat const& in) inline chunkdat& operator=(chunkdat const& a) { set(a); return *this; } - //! @brief add and return *this. @see add(std::string const& name, chunkdat const& val) + //! @brief add() and return *this. @see add(std::string const& name, chunkdat const& val) inline chunkdat& operator+=(std::pair const& a) { add(a.first, a.second); return *this; } - //! @brief add and return *this. @see add(std::vector> const& vec) + //! @brief add() and return *this. @see add(std::vector> const& vec) inline chunkdat& operator+=(std::vector> const& a) { add(a); return *this; } - //! @brief add and return *this. @see add(chunkdat const& val) + //! @brief add() and return *this. @see add(chunkdat const& val) inline chunkdat& operator+=(chunkdat const& a) { add(a); return *this; } - //! @brief add and return *this. @see add(std::vector const& vec) + //! @brief add() and return *this. @see add(std::vector const& vec) inline chunkdat& operator+=(std::vector const& a) { add(a); return *this; } //! @brief concatenate and return *this. @see concatenate(chunkdat const& chk) inline chunkdat& operator*=(chunkdat const& a) { concatenate(a); return *this; } - //! @brief remove and return *this. @see remove(const std::string& key) + //! @brief erase() and return *this. @see remove(const std::string& key) inline chunkdat& operator-=(const std::string& key) { erase(key); return *this; } - //! @brief remove and return *this. @see remove(const unsigned int index) + //! @brief erase() and return *this. @see remove(const unsigned int index) inline chunkdat& operator-=(const unsigned int index) { erase(index); return *this; } //add operator+ and operator* + //! @brief give strval + inline operator std::string() const { return this->strval(); } +// inline operator const char*() const { return this->strval().c_str(); } + protected: filedat* m_parent; @@ -255,6 +261,8 @@ namespace ztd chunk_abstract* m_achunk; }; + inline bool operator==(const chunkdat& a, const char* b) { return a.strval() == b; } + //! @brief add inline chunkdat operator+(const chunkdat& a, const std::pair& b) { chunkdat ret(a); ret += b; return ret; } //! @brief add @@ -367,6 +375,9 @@ namespace ztd //! @brief Is a read char static bool isRead(char in); + inline operator chunkdat() const { return *m_dataChunk; } +// inline operator std::string() const { if(m_dataChunk!=nullptr) return m_dataChunk->strval(); else return ""; } + private: //functions void generateChunk();