1
0
Fork 0

convenient streaming of null-terminated strings

This commit is contained in:
Kevin Matz 2023-05-18 14:33:40 -04:00
parent c0e7464919
commit 45c2e5c116
2 changed files with 28 additions and 0 deletions

View File

@ -345,6 +345,30 @@ bufferstream &bufferstream::operator<< (const streamable &obj)
}
/**
* @brief bufferstream::operator >>
* @param str
* @return
*/
bufferstream &bufferstream::operator>> (std::string &str)
{
readString(str, 0, true); // variable length, null-terminated
return *this;
}
/**
* @brief bufferstream::operator <<
* @param str
* @return
*/
bufferstream &bufferstream::operator<< (const std::string &str)
{
writeString(str, 0, true); // variable length, null-terminated
return *this;
}
/**
* @brief bufferstream::readString
* @param str std::string to which the read string will be appended.

View File

@ -84,6 +84,10 @@ public:
bufferstream &operator>> (streamable &obj);
bufferstream &operator<< (const streamable &obj);
// null-terminated strings
bufferstream &operator>> (std::string &str);
bufferstream &operator<< (const std::string &str);
// strings
void readString(std::string& str, const int fixed_length = 0, const bool terminated = true);
void writeString(const std::string& str, const size_t fixed_length = 0,