-// 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.
#include "unicode/uobject.h"
#include "unicode/std_string.h"
+#if U_SHOW_CPLUSPLUS_API
U_NAMESPACE_BEGIN
/**
* Virtual destructor.
* @stable ICU 4.2
*/
- virtual ~ByteSink() { }
+ virtual ~ByteSink();
/**
* Append "bytes[0,n-1]" to this.
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;
};
// -------------------------------------------------------------
* @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();
/**
* 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:
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".
* @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
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__