gwnavruntime/containers/stringstream.h Source File

stringstream.h
Go to the documentation of this file.
1 /*
2 * Copyright 2015 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 
8 // primary contact: ? - secondary contact: NOBODY
9 #ifndef Navigation_StringStream_H
10 #define Navigation_StringStream_H
11 
15 
16 namespace Kaim
17 {
18 
19 
20 class StringStream
21 {
22 private:
23  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
24  KY_CLASS_WITHOUT_COPY(StringStream)
25 
26 public:
27  StringStream() : m_ownString(), m_string(m_ownString) {}
28 
29  explicit StringStream(String& str) : m_string(str) {}
30 
31  const String& Str() const { return m_string; }
32 
33  const char* CStr() const { return m_string.ToCStr(); }
34 
35  void Clear() { m_string.Clear(); }
36 
37  StringStream& AppendString(const char* str, KyUInt32 length);
38 
39  StringStream& AppendChar(char value) { return AppendString(&value, 1); }
40 
41  template <typename T>
42  StringStream& AppendValue(T value, const char* format)
43  {
44  char tempBuffer[64];
45  KyUInt32 length = (KyUInt32)SFsprintf(tempBuffer, 64, format, value);
46  AppendString(tempBuffer, length);
47  return *this;
48  }
49 
50 private:
51  String m_ownString;
52  String& m_string;
53 };
54 
55 
56 inline StringStream& operator<<(StringStream& ss, KyInt32 value) { return ss.AppendValue(value, "%i"); }
57 inline StringStream& operator<<(StringStream& ss, KyUInt32 value) { return ss.AppendValue(value, "%u"); }
58 inline StringStream& operator<<(StringStream& ss, KyInt64 value) { return ss.AppendValue((KyInt32)value, "%i"); }
59 inline StringStream& operator<<(StringStream& ss, KyUInt64 value) { return ss.AppendValue((KyUInt32)value, "%u"); }
60 inline StringStream& operator<<(StringStream& ss, KyFloat32 value) { return ss.AppendValue(value, "%f"); }
61 inline StringStream& operator<<(StringStream& ss, KyFloat64 value) { return ss.AppendValue(value, "%f"); }
62 inline StringStream& operator<<(StringStream& ss, bool value) { return value ? ss.AppendString("true", 4) : ss.AppendString("false", 5); }
63 inline StringStream& operator<<(StringStream& ss, char value) { return ss.AppendChar(value); }
64 inline StringStream& operator<<(StringStream& ss, const char* str)
65 {
66  if (str == KY_NULL)
67  return ss;
68  return ss.AppendString(str, (KyUInt32)(SFstrlen(str)));
69 }
70 
71 
72 
73 } // namespace Kaim
74 
75 #endif // Navigation_StringStream_H
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
#define KY_NULL
Null value.
Definition: types.h:247
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:387
unsigned __int64 KyUInt64
Type used internally to represent an unsigned 64-bit integer.
Definition: types.h:38
Definition: gamekitcrowddispersion.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
double KyFloat64
Type used internally to represent a 64-bit floating-point number.
Definition: types.h:44
__int64 KyInt64
Type used internally to represent a 64-bit integer.
Definition: types.h:37
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43