// © 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. // Author: [email protected] (Sanjay Ghemawat) // // Abstract interface that consumes a sequence of bytes (ByteSink). // // Used so that we can write a single piece of code that can operate // on a variety of output string types. // // Various implementations of this interface are provided: // ByteSink: // CheckedArrayByteSink Write to a flat array, with bounds checking // StringByteSink Write to an STL string // This code is a contribution of Google code, and the style used here is // a compromise between the original Google code and the ICU coding guidelines. // For example, data types are ICU-ified (size_t,int->int32_t), // and API comments doxygen-ified, but function names and behavior are // as in the original, if possible. // Assertion-style error handling, not available in ICU, was changed to // parameter "pinning" similar to UnicodeString. // // In addition, this is only a partial port of the original Google code, // limited to what was needed so far. The (nearly) complete original code // is in the ICU svn repository at icuhtml/trunk/design/strings/contrib // (see ICU ticket 6765, r25517). #ifndef __BYTESTREAM_H__ #define __BYTESTREAM_H__ /** * \file * \brief C++ API: Interface for writing bytes, and implementation classes. */ #include "unicode/utypes.h" #if U_SHOW_CPLUSPLUS_API #include "unicode/uobject.h" #include "unicode/std_string.h" U_NAMESPACE_BEGIN /** * A ByteSink can be filled with bytes. * @stable ICU 4.2 */ class U_COMMON_API ByteSink : public UMemory { … }; // ------------------------------------------------------------- // Some standard implementations /** * Implementation of ByteSink that writes to a flat byte array, * with bounds-checking: * This sink will not write more than capacity bytes to outbuf. * If more than capacity bytes are Append()ed, then excess bytes are ignored, * and Overflowed() will return true. * Overflow does not cause a runtime error. * @stable ICU 4.2 */ class U_COMMON_API CheckedArrayByteSink : public ByteSink { … }; /** * Implementation of ByteSink that writes to a "string". * The StringClass is usually instantiated with a std::string. * @stable ICU 4.2 */ template<typename StringClass> class StringByteSink : public ByteSink { … }; U_NAMESPACE_END #endif /* U_SHOW_CPLUSPLUS_API */ #endif // __BYTESTREAM_H__