From 69c052df6a501b592895c7b9314a1d6b3eb8a6a8 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Wed, 18 Feb 2015 15:22:48 +0100 Subject: [PATCH] [DEV] add stream write of data for FSNode (test) --- etk/os/FSNode.cpp | 33 +++++++++++++++++++++++++++++++++ etk/os/FSNode.h | 11 +++++++++++ 2 files changed, 44 insertions(+) diff --git a/etk/os/FSNode.cpp b/etk/os/FSNode.cpp index 50367eb..558d03d 100644 --- a/etk/os/FSNode.cpp +++ b/etk/os/FSNode.cpp @@ -1708,6 +1708,39 @@ int64_t etk::FSNode::fileWrite(const void * _data, int64_t _blockSize, int64_t _ #endif return fwrite(_data, _blockSize, _nbBlock, m_PointerFile); } +/* +etk::FSNode& etk::FSNode::operator<< (const std::ostream& _data) { + fileWrite(_data.str().c_str(), 1, _data.str().size()); + return *this; +} +*/ +etk::FSNode& etk::FSNode::operator<< (const std::stringstream& _data) { + std::string sss = _data.str(); + fileWrite(sss.c_str(), 1, sss.size()); + return *this; +} +etk::FSNode& etk::FSNode::operator<< (const std::string& _data) { + fileWrite(_data.c_str(), 1, _data.size()); + return *this; +} +etk::FSNode& etk::FSNode::operator<< (const char* _data) { + fileWrite(_data, 1, strlen(_data)); + return *this; +} +etk::FSNode& etk::FSNode::operator<< (const int32_t _data) { + std::stringstream tmp; + tmp << _data; + std::string sss = tmp.str(); + fileWrite(sss.c_str(), 1, sss.size()); + return *this; +} +etk::FSNode& etk::FSNode::operator<< (const uint32_t _data) { + std::stringstream tmp; + tmp << _data; + std::string sss = tmp.str(); + fileWrite(sss.c_str(), 1, sss.size()); + return *this; +} bool etk::FSNode::fileSeek(long int _offset, enum etk::seekNode _origin) { diff --git a/etk/os/FSNode.h b/etk/os/FSNode.h index 948f340..dbcd182 100644 --- a/etk/os/FSNode.h +++ b/etk/os/FSNode.h @@ -452,6 +452,17 @@ namespace etk { * @return Number of element written (in block number) */ int64_t fileWrite(const void* _data, int64_t _blockSize, int64_t _nbBlock); + /** + * @brief Stream write mode + * @param[in] _data Stream to write + * @note not stable API ... + */ + //etk::FSNode& operator<< (const std::ostream& _data); + etk::FSNode& operator<< (const std::stringstream& _data); + etk::FSNode& operator<< (const std::string& _data); + etk::FSNode& operator<< (const char* _data); + etk::FSNode& operator<< (const int32_t _data); + etk::FSNode& operator<< (const uint32_t _data); /** * @brief Get the position in the file. * @return the requested position.