summaryrefslogtreecommitdiff
path: root/src/KM_memio.h
diff options
context:
space:
mode:
authorjhurst <jhurst@cinecert.com>2010-05-13 19:12:13 +0000
committerjhurst <>2010-05-13 19:12:13 +0000
commitf6382ee078c3d7de2dbf3a01f5624345d2c61e4a (patch)
tree9418a7065bdedb15e9551d97743ec1a9b8cd8f71 /src/KM_memio.h
parent6413d43575d39c8560673515ca7e75e1e2c789a9 (diff)
release candidate
Diffstat (limited to 'src/KM_memio.h')
-rwxr-xr-xsrc/KM_memio.h41
1 files changed, 26 insertions, 15 deletions
diff --git a/src/KM_memio.h b/src/KM_memio.h
index 9c906d5..5349749 100755
--- a/src/KM_memio.h
+++ b/src/KM_memio.h
@@ -1,5 +1,5 @@
/*
-Copyright (c) 2006-2009, John Hurst
+Copyright (c) 2006-2010, John Hurst
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -121,6 +121,13 @@ namespace Kumu
m_size += sizeof(ui64_t);
return true;
}
+
+ inline bool WriteString(const std::string& str)
+ {
+ if ( ! WriteUi32BE(str.length()) ) return false;
+ if ( ! WriteRaw((const byte_t*)str.c_str(), str.length()) ) return false;
+ return true;
+ }
};
//
@@ -207,27 +214,31 @@ namespace Kumu
m_size += sizeof(ui64_t);
return true;
}
+
+ inline bool ReadString(std::string& str)
+ {
+ ui32_t str_length;
+ if ( ! ReadUi32BE(&str_length) ) return false;
+ if ( ( m_size + str_length ) > m_capacity ) return false;
+ str.assign((const char*)CurrentData(), str_length);
+ if ( ! SkipOffset(str_length) ) return false;
+ return true;
+ }
};
//
inline bool
- UnarchiveString(MemIOReader& Reader, std::string& str)
- {
- ui32_t str_length;
- if ( ! Reader.ReadUi32BE(&str_length) ) return false;
- str.assign((const char*)Reader.CurrentData(), str_length);
- if ( ! Reader.SkipOffset(str_length) ) return false;
- return true;
- }
+ UnarchiveString(MemIOReader& Reader, std::string& str) {
+ return Reader.ReadString(str);
+ }
//
inline bool
- ArchiveString(MemIOWriter& Writer, const std::string& str)
- {
- if ( ! Writer.WriteUi32BE(str.length()) ) return false;
- if ( ! Writer.WriteRaw((const byte_t*)str.c_str(), str.length()) ) return false;
- return true;
- }
+ ArchiveString(MemIOWriter& Writer, const std::string& str)
+ {
+ return Writer.WriteString(str);
+ }
+
} // namespace Kumu