00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef __BYTESTREAM_H__
00031 #define __BYTESTREAM_H__
00032
00038 #include "unicode/utypes.h"
00039 #include "unicode/uobject.h"
00040 #include "unicode/std_string.h"
00041
00042 U_NAMESPACE_BEGIN
00043
00048 class U_COMMON_API ByteSink : public UMemory {
00049 public:
00054 ByteSink() { }
00059 virtual ~ByteSink();
00060
00067 virtual void Append(const char* bytes, int32_t n) = 0;
00068
00111 virtual char* GetAppendBuffer(int32_t min_capacity,
00112 int32_t desired_capacity_hint,
00113 char* scratch, int32_t scratch_capacity,
00114 int32_t* result_capacity);
00115
00124 virtual void Flush();
00125
00126 private:
00127 ByteSink(const ByteSink &);
00128 ByteSink &operator=(const ByteSink &);
00129 };
00130
00131
00132
00133
00143 class U_COMMON_API CheckedArrayByteSink : public ByteSink {
00144 public:
00151 CheckedArrayByteSink(char* outbuf, int32_t capacity);
00156 virtual ~CheckedArrayByteSink();
00165 virtual CheckedArrayByteSink& Reset();
00172 virtual void Append(const char* bytes, int32_t n);
00187 virtual char* GetAppendBuffer(int32_t min_capacity,
00188 int32_t desired_capacity_hint,
00189 char* scratch, int32_t scratch_capacity,
00190 int32_t* result_capacity);
00196 int32_t NumberOfBytesWritten() const { return size_; }
00203 UBool Overflowed() const { return overflowed_; }
00211 int32_t NumberOfBytesAppended() const { return appended_; }
00212 private:
00213 char* outbuf_;
00214 const int32_t capacity_;
00215 int32_t size_;
00216 int32_t appended_;
00217 UBool overflowed_;
00218 CheckedArrayByteSink();
00219 CheckedArrayByteSink(const CheckedArrayByteSink &);
00220 CheckedArrayByteSink &operator=(const CheckedArrayByteSink &);
00221 };
00222
00223 #if U_HAVE_STD_STRING
00224
00230 template<typename StringClass>
00231 class StringByteSink : public ByteSink {
00232 public:
00238 StringByteSink(StringClass* dest) : dest_(dest) { }
00245 virtual void Append(const char* data, int32_t n) { dest_->append(data, n); }
00246 private:
00247 StringClass* dest_;
00248 StringByteSink();
00249 StringByteSink(const StringByteSink &);
00250 StringByteSink &operator=(const StringByteSink &);
00251 };
00252
00253 #endif
00254
00255 U_NAMESPACE_END
00256
00257 #endif // __BYTESTREAM_H__