Skip to content

Commit 7510e7f

Browse files
committed
r23 | charles.nicholson | 2010-03-18 19:14:06 -0500 (Thu, 18 Mar 2010) | 1 line
long long streaming for MemoryOutStream, from sony
1 parent 7b9e3a1 commit 7510e7f

File tree

3 files changed

+55
-15
lines changed

3 files changed

+55
-15
lines changed

src/MemoryOutStream.cpp

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ char const* MemoryOutStream::GetText() const
5757
return m_buffer;
5858
}
5959

60-
MemoryOutStream& MemoryOutStream::operator << (char const* txt)
60+
MemoryOutStream& MemoryOutStream::operator <<(char const* txt)
6161
{
6262
using namespace std;
6363

@@ -74,37 +74,59 @@ MemoryOutStream& MemoryOutStream::operator << (char const* txt)
7474
return *this;
7575
}
7676

77-
MemoryOutStream& MemoryOutStream::operator << (int const n)
77+
MemoryOutStream& MemoryOutStream::operator <<(int const n)
7878
{
7979
FormatToStream(*this, "%i", n);
8080
return *this;
8181
}
8282

83-
MemoryOutStream& MemoryOutStream::operator << (long const n)
83+
MemoryOutStream& MemoryOutStream::operator <<(long const n)
8484
{
8585
FormatToStream(*this, "%li", n);
8686
return *this;
8787
}
8888

89-
MemoryOutStream& MemoryOutStream::operator << (unsigned long const n)
89+
MemoryOutStream& MemoryOutStream::operator <<(unsigned long const n)
9090
{
9191
FormatToStream(*this, "%lu", n);
9292
return *this;
9393
}
9494

95-
MemoryOutStream& MemoryOutStream::operator << (float const f)
95+
MemoryOutStream& MemoryOutStream::operator <<(long long const n)
96+
{
97+
#ifdef UNITTEST_WIN32
98+
FormatToStream(*this, "%I64d", n);
99+
#else
100+
FormatToStream(*this, "%lld", n);
101+
#endif
102+
103+
return *this;
104+
}
105+
106+
MemoryOutStream& MemoryOutStream::operator <<(unsigned long long const n)
107+
{
108+
#ifdef UNITTEST_WIN32
109+
FormatToStream(*this, "%I64u", n);
110+
#else
111+
FormatToStream(*this, "%llu", n);
112+
#endif
113+
114+
return *this;
115+
}
116+
117+
MemoryOutStream& MemoryOutStream::operator <<(float const f)
96118
{
97119
FormatToStream(*this, "%ff", f);
98120
return *this;
99121
}
100122

101-
MemoryOutStream& MemoryOutStream::operator << (void const* p)
123+
MemoryOutStream& MemoryOutStream::operator <<(void const* p)
102124
{
103125
FormatToStream(*this, "%p", p);
104126
return *this;
105127
}
106128

107-
MemoryOutStream& MemoryOutStream::operator << (unsigned int const s)
129+
MemoryOutStream& MemoryOutStream::operator <<(unsigned int const s)
108130
{
109131
FormatToStream(*this, "%u", s);
110132
return *this;

src/MemoryOutStream.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,16 @@ class UNITTEST_LINKAGE MemoryOutStream
4242

4343
char const* GetText() const;
4444

45-
MemoryOutStream& operator << (char const* txt);
46-
MemoryOutStream& operator << (int n);
47-
MemoryOutStream& operator << (long n);
48-
MemoryOutStream& operator << (unsigned long n);
49-
MemoryOutStream& operator << (float f);
50-
MemoryOutStream& operator << (double d);
51-
MemoryOutStream& operator << (void const* p);
52-
MemoryOutStream& operator << (unsigned int s);
45+
MemoryOutStream& operator <<(char const* txt);
46+
MemoryOutStream& operator <<(int n);
47+
MemoryOutStream& operator <<(long n);
48+
MemoryOutStream& operator <<(long long n);
49+
MemoryOutStream& operator <<(unsigned long n);
50+
MemoryOutStream& operator <<(unsigned long long n);
51+
MemoryOutStream& operator <<(float f);
52+
MemoryOutStream& operator <<(double d);
53+
MemoryOutStream& operator <<(void const* p);
54+
MemoryOutStream& operator <<(unsigned int s);
5355

5456
enum { GROW_CHUNK_SIZE = 32 };
5557
int GetCapacity() const;

src/tests/TestMemoryOutStream.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include "../MemoryOutStream.h"
44
#include <cstring>
5+
#include <climits>
6+
#include <cstdlib>
57

68
using namespace UnitTest;
79
using namespace std;
@@ -57,6 +59,20 @@ TEST(StreamingUnsignedLongWritesCorrectCharacters)
5759
CHECK_EQUAL("123", stream.GetText());
5860
}
5961

62+
TEST(StreamingLongLongWritesCorrectCharacters)
63+
{
64+
MemoryOutStream stream;
65+
stream << (long long)(ULONG_MAX) * 2;
66+
CHECK_EQUAL("8589934590", stream.GetText());
67+
}
68+
69+
TEST(StreamingUnsignedLongLongWritesCorrectCharacters)
70+
{
71+
MemoryOutStream stream;
72+
stream << (unsigned long long)(ULONG_MAX) * 2;
73+
CHECK_EQUAL("8589934590", stream.GetText());
74+
}
75+
6076
TEST(StreamingFloatWritesCorrectCharacters)
6177
{
6278
MemoryOutStream stream;

0 commit comments

Comments
 (0)