00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __BYTESTREAM_H__
00018 #define __BYTESTREAM_H__
00019
00025 #include "unicode/utypes.h"
00026 #include "unicode/uobject.h"
00027 #include "unicode/std_string.h"
00028
00029 U_NAMESPACE_BEGIN
00030
00035 class U_COMMON_API ByteSink : public UMemory {
00036 public:
00041 ByteSink() { }
00046 virtual ~ByteSink() { }
00047
00054 virtual void Append(const char* bytes, int32_t n) = 0;
00055
00098 virtual char* GetAppendBuffer(int32_t min_capacity,
00099 int32_t desired_capacity_hint,
00100 char* scratch, int32_t scratch_capacity,
00101 int32_t* result_capacity);
00102
00110 virtual void Flush();
00111
00112 private:
00113 ByteSink(const ByteSink &);
00114 ByteSink &operator=(const ByteSink &);
00115 };
00116
00117
00118
00119
00129 class U_COMMON_API CheckedArrayByteSink : public ByteSink {
00130 public:
00137 CheckedArrayByteSink(char* outbuf, int32_t capacity);
00144 virtual void Append(const char* bytes, int32_t n);
00159 virtual char* GetAppendBuffer(int32_t min_capacity,
00160 int32_t desired_capacity_hint,
00161 char* scratch, int32_t scratch_capacity,
00162 int32_t* result_capacity);
00168 int32_t NumberOfBytesWritten() const { return size_; }
00175 UBool Overflowed() const { return overflowed_; }
00176 private:
00177 char* outbuf_;
00178 const int32_t capacity_;
00179 int32_t size_;
00180 bool overflowed_;
00181 CheckedArrayByteSink();
00182 CheckedArrayByteSink(const CheckedArrayByteSink &);
00183 CheckedArrayByteSink &operator=(const CheckedArrayByteSink &);
00184 };
00185
00186 #if U_HAVE_STD_STRING
00187
00193 template<typename StringClass>
00194 class StringByteSink : public ByteSink {
00195 public:
00201 StringByteSink(StringClass* dest) : dest_(dest) { }
00208 virtual void Append(const char* data, int32_t n) { dest_->append(data, n); }
00209 private:
00210 StringClass* dest_;
00211 StringByteSink();
00212 StringByteSink(const StringByteSink &);
00213 StringByteSink &operator=(const StringByteSink &);
00214 };
00215
00216 #endif
00217
00218 U_NAMESPACE_END
00219
00220 #endif // __BYTESTREAM_H__