convenient streaming of null-terminated strings
This commit is contained in:
parent
c0e7464919
commit
45c2e5c116
|
@ -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.
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue