MemoryOutStream.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #ifndef UNITTEST_MEMORYOUTSTREAM_H
  2. #define UNITTEST_MEMORYOUTSTREAM_H
  3. #include "Config.h"
  4. #ifndef UNITTEST_USE_CUSTOM_STREAMS
  5. #include <sstream>
  6. namespace UnitTest
  7. {
  8. class MemoryOutStream : public std::ostringstream
  9. {
  10. public:
  11. MemoryOutStream() {}
  12. ~MemoryOutStream() {}
  13. char const* GetText() const;
  14. private:
  15. MemoryOutStream(MemoryOutStream const&);
  16. void operator =(MemoryOutStream const&);
  17. mutable std::string m_text;
  18. };
  19. }
  20. #else
  21. #include <cstddef>
  22. namespace UnitTest
  23. {
  24. class MemoryOutStream
  25. {
  26. public:
  27. explicit MemoryOutStream(int const size = 256);
  28. ~MemoryOutStream();
  29. char const* GetText() const;
  30. MemoryOutStream& operator << (char const* txt);
  31. MemoryOutStream& operator << (int n);
  32. MemoryOutStream& operator << (long n);
  33. MemoryOutStream& operator << (unsigned long n);
  34. MemoryOutStream& operator << (float f);
  35. MemoryOutStream& operator << (double d);
  36. MemoryOutStream& operator << (void const* p);
  37. MemoryOutStream& operator << (unsigned int s);
  38. enum { GROW_CHUNK_SIZE = 32 };
  39. int GetCapacity() const;
  40. private:
  41. void operator= (MemoryOutStream const&);
  42. void GrowBuffer(int capacity);
  43. int m_capacity;
  44. char* m_buffer;
  45. };
  46. }
  47. #endif
  48. #endif