]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/common/unicode/bytestream.h
ICU-64232.0.1.tar.gz
[apple/icu.git] / icuSources / common / unicode / bytestream.h
index fb9e07a25dcd9b95d9a37a0b8a72b35e63a1ffb8..b12e64d736976c224817a1042ecf0b08f856adf7 100644 (file)
@@ -1,4 +1,6 @@
-// Copyright (C) 2009-2010, International Business Machines
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+// Copyright (C) 2009-2012, International Business Machines
 // Corporation and others. All Rights Reserved.
 //
 // Copyright 2007 Google Inc. All Rights Reserved.
@@ -39,6 +41,7 @@
 #include "unicode/uobject.h"
 #include "unicode/std_string.h"
 
+#if U_SHOW_CPLUSPLUS_API
 U_NAMESPACE_BEGIN
 
 /**
@@ -56,7 +59,7 @@ public:
    * Virtual destructor.
    * @stable ICU 4.2
    */
-  virtual ~ByteSink() { }
+  virtual ~ByteSink();
 
   /**
    * Append "bytes[0,n-1]" to this.
@@ -124,8 +127,8 @@ public:
   virtual void Flush();
 
 private:
-  ByteSink(const ByteSink &); // copy constructor not implemented
-  ByteSink &operator=(const ByteSink &); // assignment operator not implemented
+  ByteSink(const ByteSink &) = delete;
+  ByteSink &operator=(const ByteSink &) = delete;
 };
 
 // -------------------------------------------------------------
@@ -149,13 +152,18 @@ public:
    * @stable ICU 4.2
    */
   CheckedArrayByteSink(char* outbuf, int32_t capacity);
+  /**
+   * Destructor.
+   * @stable ICU 4.2
+   */
+  virtual ~CheckedArrayByteSink();
   /**
    * Returns the sink to its original state, without modifying the buffer.
    * Useful for reusing both the buffer and the sink for multiple streams.
    * Resets the state to NumberOfBytesWritten()=NumberOfBytesAppended()=0
    * and Overflowed()=FALSE.
    * @return *this
-   * @draft ICU 4.6
+   * @stable ICU 4.6
    */
   virtual CheckedArrayByteSink& Reset();
   /**
@@ -201,7 +209,7 @@ public:
    * If Overflowed() then NumberOfBytesAppended()>NumberOfBytesWritten()
    * else they return the same number.
    * @return number of bytes written to the buffer
-   * @draft ICU 4.6
+   * @stable ICU 4.6
    */
   int32_t NumberOfBytesAppended() const { return appended_; }
 private:
@@ -210,12 +218,11 @@ private:
   int32_t size_;
   int32_t appended_;
   UBool overflowed_;
-  CheckedArrayByteSink(); ///< default constructor not implemented 
-  CheckedArrayByteSink(const CheckedArrayByteSink &); ///< copy constructor not implemented
-  CheckedArrayByteSink &operator=(const CheckedArrayByteSink &); ///< assignment operator not implemented
-};
 
-#if U_HAVE_STD_STRING
+  CheckedArrayByteSink() = delete;
+  CheckedArrayByteSink(const CheckedArrayByteSink &) = delete;
+  CheckedArrayByteSink &operator=(const CheckedArrayByteSink &) = delete;
+};
 
 /** 
  * Implementation of ByteSink that writes to a "string".
@@ -231,6 +238,19 @@ class StringByteSink : public ByteSink {
    * @stable ICU 4.2
    */
   StringByteSink(StringClass* dest) : dest_(dest) { }
+  /**
+   * Constructs a ByteSink that reserves append capacity and will append bytes to the dest string.
+   * 
+   * @param dest pointer to string object to append to
+   * @param initialAppendCapacity capacity beyond dest->length() to be reserve()d
+   * @stable ICU 60
+   */
+  StringByteSink(StringClass* dest, int32_t initialAppendCapacity) : dest_(dest) {
+    if (initialAppendCapacity > 0 &&
+        (uint32_t)initialAppendCapacity > (dest->capacity() - dest->length())) {
+      dest->reserve(dest->length() + initialAppendCapacity);
+    }
+  }
   /**
    * Append "bytes[0,n-1]" to this.
    * @param data the pointer to the bytes
@@ -240,13 +260,13 @@ class StringByteSink : public ByteSink {
   virtual void Append(const char* data, int32_t n) { dest_->append(data, n); }
  private:
   StringClass* dest_;
-  StringByteSink(); ///< default constructor not implemented 
-  StringByteSink(const StringByteSink &); ///< copy constructor not implemented
-  StringByteSink &operator=(const StringByteSink &); ///< assignment operator not implemented
-};
 
-#endif
+  StringByteSink() = delete;
+  StringByteSink(const StringByteSink &) = delete;
+  StringByteSink &operator=(const StringByteSink &) = delete;
+};
 
 U_NAMESPACE_END
+#endif // U_SHOW_CPLUSPLUS_API
 
 #endif  // __BYTESTREAM_H__