CTR-Pia  5.4.3
Game Communication Engine
 全て クラス ネームスペース 関数 変数 型定義 列挙型 列挙型の値 ページ
clone_ReliableLargeCloneElement.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/clone/clone_Definitions.h>
17 #include <nn/pia/clone/clone_ReliableLargeCloneElementBase.h>
18 
19 namespace nn
20 {
21 namespace pia
22 {
23 namespace clone
24 {
25 
26 
27 /*!
28  @brief 到達保証されたサイズの大きい値の送受信を管理します。
29 
30  @tparam Value_ 管理する値の型です。値を初期化する関数 void Value_::Clear() が定義されている必要があります。
31  @tparam SerializedSize シリアライズした Value のサイズです。正の値を指定する必要があります。@ref CloneProtocol::GetElementSizeMax() より大きな値は使用できません。
32  @tparam DivideSize 分割後のデータ 1 つ当たりのサイズです。正の値を指定する必要があります。@ref CloneProtocol::GetElementSizeMax() より大きな値は使用できません。
33  */
34 template <typename Value_, uint32_t SerializedSize, uint32_t DivideSize = 1094>
36 {
37 public:
38  /*!
39  @brief このオブジェクトが管理する値の型です。
40  */
41  typedef Value_ Value;
42 
43 
44  /*!
45  @brief Value をシリアライズするためのアルゴリズムです。
46  */
48 
49 
50  /*!
51  @brief デフォルトコンストラクタです。
52  */
54  : ReliableLargeCloneElementBase(m_SerializedBuffer, m_aDivideInfo, Size, DivideSize, DivideNum),
55  m_Value()
56  {
57  }
58 
59 
60  /*!
61  @brief デストラクタです。
62  */
64  {
65  }
66 
67 
68  /*!
69  @brief 値を設定します。
70  @param[in] value 設定する値です。
71  @return 成功すれば、IsSuccess() が true を返す Result が返されます。
72  @retval ResultInvalidState 登録している CloneBase が送信可能状態ではありません。プログラミングエラーです。このエラーが返らないようにソースコードを修正してください。
73  @retval ResultTemporaryUnavailable 値を設定できるタイミングではありません。値を設定するためには時刻を進める必要があります。アプリケーションで適切にハンドリングしてください。
74  */
75  Result SetValue(const Value& value);
76 
77 
78  /*!
79  @brief 値を取得します。
80  @return このオブジェクトが管理する値です。 IsValidValue() が false の場合に取得できる値は不定です。
81  */
82  const Value& GetValue() const
83  {
84  return m_Value;
85  }
86 
87 
88  //! @cond PRIVATE
89 
90 protected:
91  virtual void Serialize()
92  {
93  ValueSerializePolicy::Serialize(m_SerializedBuffer, m_Value);
94  }
95  virtual void Deserialize()
96  {
97  ValueSerializePolicy::Deserialize(&m_Value, m_SerializedBuffer);
98  }
99  virtual void ClearValue()
100  {
101  m_Value.Clear();
102  }
103 
104 
105 private:
106  static const uint32_t Size = SerializedSize;
107  static const uint32_t DivideLastSize = (Size - 1) % DivideSize + 1;
108  static const uint32_t DivideNum = (Size - DivideLastSize) / DivideSize + 1;
109 
110 private:
111  Value m_Value;
112  uint8_t m_SerializedBuffer[Size];
113  DivideInfo m_aDivideInfo[DivideNum];
114 
115  //! @endcond
116 };
117 
118 
119 //! @cond
120 template <typename Value, uint32_t SerializedSize, uint32_t DivideSize>
122 {
123  PIA_COMPILE_ASSERT(DivideNum <= 0xffff);
124 
125  Result r = SetValueCore();
126  if (r.IsSuccess())
127  {
128  m_Value = value;
129  PostSetValue();
130  }
131  return r;
132 }
133 //! @endcond
134 }
135 }
136 } // end of namespace nn::pia::clone