X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2FKM_util.h;h=b209d27841a890814e1841885a5e1abae6ed4f4d;hb=7ce81497e2592d5787b9a4285d6a89ae09f79022;hp=2ca17935d7b662fa47e5b1e0c242460c5c040bf5;hpb=528cacb6122b33f73a805fbb47b4ae83a46db418;p=asdcplib.git diff --git a/src/KM_util.h b/src/KM_util.h index 2ca1793..b209d27 100755 --- a/src/KM_util.h +++ b/src/KM_util.h @@ -36,7 +36,6 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include -#include #include namespace Kumu @@ -257,6 +256,35 @@ namespace Kumu } }; + // + class ArchivableUi16 : public Kumu::IArchive + { + ui16_t m_Value; + + public: + ArchivableUi16() : m_Value(0) {} + ArchivableUi16(const ui16_t& value) : m_Value(value) {} + virtual ~ArchivableUi16() {} + + bool HasValue() const { return true; } + ui32_t ArchiveLength() const { return sizeof(ui16_t); } + + bool Archive(MemIOWriter* Writer) const { + if ( Writer == 0 ) return false; + return Writer->WriteUi16BE(m_Value); + } + + bool Unarchive(MemIOReader* Reader) { + if ( Reader == 0 ) return false; + return Reader->ReadUi16BE(&m_Value); + } + + const char* EncodeString(char* str_buf, ui32_t buf_len) const { + snprintf(str_buf, buf_len, "%hu", m_Value); + return str_buf; + } + }; + // typedef Kumu::ArchivableList StringList; @@ -531,7 +559,7 @@ namespace Kumu }; inline void hexdump(const ByteString& buf, FILE* stream = 0) { - hexdump(buf.RoData(), buf.Length()); + hexdump(buf.RoData(), buf.Length(), stream); } // Locates the first occurrence of the null-terminated string s2 in the string s1, where not more @@ -544,6 +572,27 @@ namespace Kumu // adjacent instances of the separator. E.g., "/foo//bar/" will return ["", "foo", "", "bar", ""]. std::list km_token_split(const std::string& str, const std::string& separator); + // Join the tokens in the given list using delimiter. If prefix is defined then each token + // will be concatenated with the prefix before being added to the composite string. + template + std::string + km_join(const T& list, const std::string& delimiter, const std::string& prefix = "") + { + std::string result; + + for ( typename T::const_iterator i = list.begin(); i != list.end(); ++i ) + { + if ( i != list.begin() ) + { + result += delimiter; + } + + result += prefix + *i; + } + + return result; + } + } // namespace Kumu