CTR-Pia  5.4.3
Game Communication Engine
 全て クラス ネームスペース 関数 変数 型定義 列挙型 列挙型の値 ページ
common_StringStream.h
1 /*--------------------------------------------------------------------------------*
2  Copyright (C)Nintendo All rights reserved.
3 
4  These coded instructions, statements, and computer programs contain proprietary
5  information of Nintendo and/or its licensed developers and are protected by
6  national and international copyright laws. They may not be disclosed to third
7  parties or copied or duplicated in any form, in whole or in part, without the
8  prior written consent of Nintendo.
9 
10  The content herein is highly confidential and should be handled accordingly.
11  *--------------------------------------------------------------------------------*/
12 
13 
14 #pragma once
15 
16 #include <nn/pia/pia_Platform.h>
17 #include <nn/pia/common/common_RootObject.h>
18 
19 
20 //n2788:0埋め16進数表示を追加
21 #define NN_PIA_ENABLE_ZERO_FILL_HEX 1
22 
23 namespace nn
24 {
25 namespace pia
26 {
27 namespace common
28 {
29 
30 const uint32_t StringStreamInitialSize = 128;
31 
32 //n2619:グローバルなnewをBeginSetup()~EndSetup()外で
33 //行ってしまう処理を有効にするかどうか(基本的に永久に0)
34 #define PIA_ENABLE_RESIZE_BUFFER 0
35 
36 /*!
37  @cond PRIVATE
38  @brief 文字列のストリームクラスです。
39  マニピュレータ(<<)を使用して文字列を結合します。
40  */
41 class StringStream : public RootObject
42 {
43 public:
44  /*!
45  @brief コンストラクタです。
46  */
47  StringStream(void);
48 
49  /*!
50  @brief デストラクタです。
51  */
52  virtual ~StringStream(void);
53 
54  // Returns the stream length
55  uint32_t GetLength() const;
56 
57  // Returns the m_szBuffer size (capacity)
58  uint32_t GetSize() const
59  {
60  return m_uiSize;
61  }
62 
63  const char* CStr() const
64  {
65  return m_szBuffer;
66  }
67 
68  void Clear();
69 
70  // Streaming of basic types
71  StringStream& operator<<(const char* szText);
72  StringStream& operator<<(const void* pPointer);
73  StringStream& operator<<(bool bValue);
74  StringStream& operator<<(double dValue);
75  StringStream& operator<<(float fValue);
76 
77  StringStream& operator<<(uint8_t uiValue)
78  {
79  return StreamNumber(uiValue);
80  }
81  StringStream& operator<<(int8_t iValue)
82  {
83  return StreamNumber(iValue);
84  }
85  StringStream& operator<<(uint16_t uiValue)
86  {
87  return StreamNumber(uiValue);
88  }
89  StringStream& operator<<(int16_t iValue)
90  {
91  return StreamNumber(iValue);
92  }
93  StringStream& operator<<(uint32_t uiValue)
94  {
95  return StreamNumber(uiValue);
96  }
97  StringStream& operator<<(int32_t iValue)
98  {
99  return StreamNumber(iValue);
100  }
101 
102  StringStream& operator<<(uint64_t uiValue);
103  StringStream& operator<<(int64_t uiValue);
104 
105  StringStream& operator<<(const StringStream& oSS);
106 
107  // Manipulators
108  StringStream& operator<<(StringStream& (*pf)(StringStream&))
109  {
110  return (*pf)(*this);
111  }
112 
113 #if !NN_PIA_ENABLE_ZERO_FILL_HEX
114  StringStream& Manip_hex()
115  {
116  m_IsHex = true;
117  return *this;
118  }
119  StringStream& Manip_dec()
120  {
121  m_IsHex = false;
122  return *this;
123  }
124 #else // !NN_PIA_ENABLE_ZERO_FILL_HEX
125  StringStream& Manip_hex()
126  {
127  m_IsHex = true;
128  m_IsZeroHex = false;
129  return *this;
130  }
131  StringStream& Manip_dec()
132  {
133  m_IsHex = false;
134  m_IsZeroHex = false;
135  return *this;
136  }
137  StringStream& Manip_zerohex()
138  {
139  m_IsHex = true;
140  m_IsZeroHex = true;
141  return *this;
142  }
143 #endif // !NN_PIA_ENABLE_ZERO_FILL_HEX
144 
145  StringStream& Manip_showbase()
146  {
147  m_IsShowBase = true;
148  return *this;
149  }
150  StringStream& Manip_noshowbase()
151  {
152  m_IsShowBase = false;
153  return *this;
154  }
155 
156  StringStream& Manip_boolalpha()
157  {
158  m_IsBoolAlpha = true;
159  return *this;
160  }
161  StringStream& Manip_noboolalpha()
162  {
163  m_IsBoolAlpha = false;
164  return *this;
165  }
166 
167  const char& operator[](uint32_t uiPos) const
168  {
169  return m_szBuffer[uiPos];
170  }
171 
172 protected:
173 private:
174 #if PIA_ENABLE_RESIZE_BUFFER
175  void FreeBuffer();
176  void FreeBuffer(char* szBuffer);
177  void ResizeBuffer(uint32_t uiSize);
178 #endif
179  void AddBaseIfRequired();
180 
181  StringStream& StreamNumber(uint32_t uiValue);
182  StringStream& StreamNumber(int32_t iValue);
183  void TestFreeRoom(uint32_t uiNewSize);
184 
185  //n2619
186  int32_t AddStringToRoom(const char* szBuffer);
187 
188 private:
189  char* m_szBuffer;
190  uint32_t m_uiSize;
191  char* m_szCurrentPosition;
192 
193  char m_szInitialBuffer[StringStreamInitialSize];
194  //n2619
195  char m_szBufferToAdd[StringStreamInitialSize];
196 
197  bool m_IsHex;
198  bool m_IsShowBase;
199  bool m_IsBoolAlpha;
200 
201 #if NN_PIA_ENABLE_ZERO_FILL_HEX
202  //n2788
203  bool m_IsZeroHex;
204 #else
205  uint8_t m_padding1; // to avoid compiler warning.
206 #endif // NN_PIA_ENABLE_ZERO_FILL_HEX
207 
208  NN_PIA_DISALLOW_COPY(StringStream);
209 };
210 
211 // Manipulators.
212 
213 extern StringStream& hex(StringStream& oStringStream);
214 extern StringStream& dec(StringStream& oStringStream);
215 extern StringStream& endl(StringStream& oStringStream);
216 extern StringStream& showbase(StringStream& oStringStream);
217 extern StringStream& noshowbase(StringStream& oStringStream);
218 extern StringStream& boolalpha(StringStream& oStringStream);
219 extern StringStream& noboolalpha(StringStream& oStringStream);
220 
221 #if NN_PIA_ENABLE_ZERO_FILL_HEX
222 extern StringStream& zerohex(StringStream& oStringStream);
223 #endif // NN_PIA_ENABLE_ZERO_FILL_HEX
224 }
225 }
226 } // end of namespace nn::pia::common
227 //! @endcond