CTR-Pia  5.4.3
Game Communication Engine
 全て クラス ネームスペース 関数 変数 型定義 列挙型 列挙型の値 ページ
common_InetAddress.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 
17 #include <nn/pia/common/common_Definitions.h>
18 #include <nn/pia/common/common_RootObject.h>
19 #include <nn/pia/common/common_ByteOrder.h>
20 
21 namespace nn
22 {
23 namespace pia
24 {
25 namespace common
26 {
27 
28 // 先行宣言。
29 class String;
30 
31 /**
32  * @brief IPv4アドレス構造体です。
33  */
34 struct InAddr
35 {
36  uint32_t addr;
37 };
38 
39 
40 /*!
41  @brief インターネットアドレスを表現するクラスです。
42 
43  @details このクラスには、IPアドレス、ポート番号(共にホストバイトオーダー)などの情報が含まれます。
44  <br>
45  */
46 class InetAddress : public RootObject
47 {
48 public:
49  static const uint32_t SerializeSizeMax = sizeof(uint32_t) + sizeof(uint16_t);
50 
51  /*!
52  @brief デフォルトコンストラクタです。
53  IPアドレス、ポート番号はゼロクリアされた状態にセットされます。
54  */
55  InetAddress();
56 
57  /*!
58  @brief IPアドレスとポート番号を指定して初期化するコンストラクタです。
59 
60  @param[in] uiAddress IPアドレス
61  @param[in] uiPort ポート番号
62  */
63  InetAddress(uint32_t uiAddress, uint16_t uiPort);
64 
65  /*!
66  @brief コピーコンストラクタです。
67 
68  @param[in] oInetAddress コピー対象のオブジェクト。
69  */
70  InetAddress(const InetAddress& oInetAddress);
71 
72  /*!
73  @brief デストラクタです。
74  */
75  ~InetAddress();
76 
77  /*!
78  @brief オブジェクトの内容を初期化します。
79  */
80  void Init()
81  {
82  m_Address = 0;
83  m_Port = 0;
84  }
85 
86  /*!
87  @brief ホストバイトオーダーのIPアドレスを設定します。
88 
89  @param[in] uiAddress IPアドレス(ホストバイトオーダー)
90  @see GetAddress
91  */
92  void SetAddress(const uint32_t uiAddress)
93  {
94  m_Address = uiAddress;
95  }
96 
97  /*!
98  @brief ホストバイトオーダーでIPアドレスを取得します。
99 
100  @return 本オブジェクトに設定されていたIPアドレス(ホストバイトオーダー)
101  @see SetAddress
102  */
103  uint32_t GetAddress() const
104  {
105  return m_Address;
106  }
107 
108  /*!
109  @brief ホストバイトオーダーのポート番号を設定します。
110 
111  @param[in] ui16Port ポート番号(ホストバイトオーダー)
112  @see GetPort
113  */
114  void SetPort(const uint16_t ui16Port)
115  {
116  m_Port = ui16Port;
117  }
118 
119  /*!
120  @brief ホストバイトオーダーのポート番号を取得します。
121 
122  @return 本オブジェクトに設定されていたポート番号(ホストバイトオーダー)
123  @see SetPort
124  */
125  uint16_t GetPort() const
126  {
127  return m_Port;
128  }
129 
130  /*!
131  @brief 比較用のキーを取得します。
132 
133  @return 比較用のキー
134  */
135  int64_t GetKey() const;
136 
137  /*!
138  @brief 代入演算子です。
139 
140  @param[in] oInetAddress 代入するオブジェクトです。
141  @return 本オブジェクトへの参照。
142  */
143  InetAddress& operator=(const InetAddress& oInetAddress);
144 
145  /*!
146  @brief アドレスの文字列表記を得ます。
147  アドレス文字列は、 255.255.255.255:80 といった書式で表記されます。
148 
149  @param[out] pString アドレス文字列表記をセットするための String オブジェクトを指すポインタ。
150  */
151  void GetAddressString(String* pString) const;
152 
153  /*!
154  @brief デバッグに有用な情報をプリントします。
155 
156  @param[in] uiTraceFlag トレースフラグの論理和。詳細は @ref TraceFlag 型を参照してください。
157  */
158  void Trace(uint64_t uiTraceFlag) const;
159 
160  /*!
161  @brief 等値演算子です。
162 
163  @param[in] oInetAddress 比較対象のオブジェクトです。
164  @return 本オブジェクトと比較対象が等しければ true 、等しくなければ false が返ります。
165  */
166  bool operator==(const InetAddress& oInetAddress) const
167  {
168  return (GetKey() == oInetAddress.GetKey());
169  }
170 
171  /*!
172  @brief 等値演算子です。
173 
174  @param[in] oInetAddress 比較対象のオブジェクトです。
175  @return 本オブジェクトと比較対象が等しくなければ true 、等しければ false が返ります。
176  */
177  bool operator!=(const InetAddress& oInetAddress) const
178  {
179  return !operator==(oInetAddress);
180  }
181 
182  /*!
183  @brief 比較演算子です。
184 
185  @param[in] oInetAddress 比較対象のオブジェクトです。
186  @return
187  */
188  bool operator<(const InetAddress& oInetAddress) const
189  {
190  return (GetKey() < oInetAddress.GetKey());
191  }
192 
193  /*!
194  @cond PRIVATE
195  @brief オブジェクトをシリアライズしたデータの長さを得ます。単位はバイトです。
196 
197  @return シリアライズされたデータの長さが返ります。単位はバイトです。
198  @see Serialize, Deserialize
199  */
200  uint32_t GetSerializedSize(void) const
201  {
202  return sizeof(uint32_t) + sizeof(uint16_t);
203  }
204  //! @endcond
205 
206  /*!
207  @cond PRIVATE
208  @brief オブジェクトをシリアライズします。
209 
210  @param[out] pBuffer シリアライズされたデータを書き込むバッファを指すポインタ。
211  @param[out] pDataLen シリアライズされたデータの長さが書き込まれます。単位はバイトです。
212  @param[in] bufferSize pBuffer で指定されたバッファのサイズを指定します。
213  @return 成功すれば、IsSuccess() が true を返す Result が返ります。
214  @retval ResultInvalidArgument 引数が誤っています( NULL ポインタであるなど )。pBuffer, bufferSize で指定されたバッファのサイズが不足していた場合も、このエラーを返します。
215  @see Deserialize, GetSerializedSize
216  */
217  Result Serialize(uint8_t* pBuffer, uint32_t* pDataLen, uint32_t bufferSize) const;
218  //! @endcond
219 
220  /*!
221  @cond PRIVATE
222  @brief シリアライズされたデータから、オブジェクトを復元します。
223 
224  @param[in] pData シリアライズされたデータを指すポインタ。
225 
226  @return 成功すれば、IsSuccess() が true を返す Result が返ります。
227  @retval ResultInvalidArgument 引数が誤っています( NULL ポインタであるなど)。
228  @see Serialize, GetSerializedSize
229  */
230  Result Deserialize(const uint8_t* pData);
231  //! @endcond
232 
233  /*!
234  @cond PRIVATE
235  @brief 有効なアドレスとポートがセットされているかどうかを判定します。
236 
237  @return 有効であれば true が、無効であれば false が返されます。
238  */
239  bool IsValid(void) const;
240  //! @endcond
241 
242  /*!
243  @cond PRIVATE
244  @brief 有効なアドレスがセットされているかどうかを判定します。
245 
246  @return 有効であれば true が、無効であれば false が返されます。
247  */
248  bool IsValidAddress(void) const;
249  //! @endcond
250 
251  /*!
252  @cond PRIVATE
253  @brief 有効なポートがセットされているかどうかを判定します。
254 
255  @return 有効であれば true が、無効であれば false が返されます。
256  */
257  bool IsValidPort(void) const;
258  //! @endcond
259 
260  /*!
261  @cond PRIVATE
262  @brief 無効化します。
263  */
264  void Invalidate()
265  {
266  m_Address = 0;
267  m_Port = 0;
268  }
269  //! @endcond
270 
271  /*!
272  @cond PRIVATE
273  @brief アドレスがプライベートアドレスかどうか判定します。
274 
275  @return プライベートであれば true が、そうでなければ false が返されます。
276  */
277  bool IsPrivate(void) const;
278  //! @endcond
279 
280 
281 protected:
282  uint32_t m_Address;
283  uint16_t m_Port;
284 };
285 }
286 }
287 } // end of namespace nn::pia::common