removed nascent ST2052-1 support pending completion
[asdcplib.git] / src / KM_memio.h
index 7ab7267e4065864af4a92ade18ec920b2d5c924d..defea5ed89a151a97a886930e71ea2cbca9e73b8 100755 (executable)
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 2006-2008, John Hurst
+Copyright (c) 2006-2011, John Hurst
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
@@ -61,9 +61,10 @@ namespace Kumu
 
       inline void    Reset() { m_size = 0; }
       inline byte_t* Data() { return m_p; }
+      inline const byte_t* RoData() const { return m_p; }
       inline byte_t* CurrentData() { return m_p + m_size; }
-      inline ui32_t  Length() { return m_size; }
-      inline ui32_t  Remainder() { return m_capacity - m_size; }
+      inline ui32_t  Length() const { return m_size; }
+      inline ui32_t  Remainder() const { return m_capacity - m_size; }
 
       inline bool AddOffset(ui32_t offset) {
        if ( ( m_size + offset ) > m_capacity )
@@ -120,6 +121,13 @@ namespace Kumu
        m_size += sizeof(ui64_t);
        return true;
       }
+
+      inline bool WriteString(const std::string& str) {
+       ui32_t len = static_cast<ui32_t>(str.length());
+       if ( ! WriteUi32BE(len) ) return false;
+       if ( ! WriteRaw((const byte_t*)str.c_str(), len) ) return false;
+       return true;
+      }
     };
 
   //
@@ -143,10 +151,10 @@ namespace Kumu
       ~MemIOReader() {}
 
       inline void          Reset() { m_size = 0; }
-      inline const byte_t* Data() { return m_p; }
-      inline const byte_t* CurrentData() { return m_p + m_size; }
-      inline ui32_t        Offset() { return m_size; }
-      inline ui32_t        Remainder() { return m_capacity - m_size; }
+      inline const byte_t* Data() const { return m_p; }
+      inline const byte_t* CurrentData() const { return m_p + m_size; }
+      inline ui32_t        Offset() const { return m_size; }
+      inline ui32_t        Remainder() const { return m_capacity - m_size; }
 
       inline bool SkipOffset(ui32_t offset) {
        if ( ( m_size + offset ) > m_capacity )
@@ -206,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