CTR Pia  4.11.3
Game Communication Engine
clone_ReliableLargeCloneElement.h
1 /*---------------------------------------------------------------------------*
2  Project: Pia
3  File: clone_ReliableLargeCloneElement.h
4 
5  Copyright Nintendo. All rights reserved.
6 
7  These coded instructions, statements, and computer programs contain
8  proprietary information of Nintendo of America Inc. and/or Nintendo
9  Company Ltd., and are protected by Federal copyright law. They may
10  not be disclosed to third parties or copied or duplicated in any form,
11  in whole or in part, without the prior written consent of Nintendo.
12  *---------------------------------------------------------------------------*/
13 
14 
15 #pragma once
16 
17 #include <pia/clone/clone_definitions.h>
18 #include <pia/clone/clone_ReliableLargeCloneElementBase.h>
19 
20 namespace nn
21 {
22 namespace pia
23 {
24 namespace clone
25 {
26 
27 
28 /*!
29  @brief Manages sending and receiving reliable large-sized data.
30 
31  @tparam Value_ Specifies the type of value to manage. The function that initializes the value, <tt>void Value_::Clear</tt>, must be defined.
32  @tparam DIVIDE_SIZE The size of a single data unit, post division. Specify a positive value. A value larger than <tt>@ref CloneProtocol::GetElementSizeMax</tt> cannot be used.
33  @tparam SerializePolicy_ Specifies the algorithm to use for serializing \a Value.
34 
35  @date 2014-10-08 Initial version.
36 */
37 template <typename Value_, size_t DIVIDE_SIZE = 1094, typename SerializePolicy_ = HostByteOrderSerializePolicy<Value_> >
39 {
40 public:
41 /*!
42  @brief Specifies the type of value managed by this object.
43 */
44  typedef Value_ Value;
45 
46 
47 /*!
48  @brief Specifies the algorithm to use for serializing \a Value.
49 */
50  typedef SerializePolicy_ SerializePolicy;
51 
52 
53 
54 /*!
55  @brief Instantiates the object with default parameters (default constructor).
56 */
57  ReliableLargeCloneElement() : ReliableLargeCloneElementBase(m_SerializedBuffer, m_aDivideInfo, SIZE, DIVIDE_SIZE, DIVIDE_NUM),
58  m_Value()
59  {
60  }
61 
62 
63 /*!
64  @brief Destructor.
65 */
67  {
68  }
69 
70 
71 /*!
72  @brief Sets values.
73  @param[in] value Specifies the flags to set.
74  @return Returns a <tt>Result</tt> value for which the <tt>IsSuccess</tt> function returns <tt>true</tt> if execution succeeds.
75  @retval ResultInvalidState Indicates that the registered <tt>CloneBase</tt> cannot send in its current state. Programming error. Fix your program so that this error is not returned.
76  @retval ResultInvalidTiming Indicates that a value cannot be set at this time. The clock must be advanced to set a value. Handle appropriately in the application.
77 */
78  nn::Result SetValue(const Value& value);
79 
80 
81 /*!
82  @brief Gets a value.
83  @return Returns the value managed by this object. This value is undefined when <tt>IsValidValue</tt> returns <tt>false</tt>.
84 */
85  const Value& GetValue() const
86  {
87  return m_Value;
88  }
89 
90 
91  //! @cond PRIVATE
92 
93 protected:
94  virtual void Serialize()
95  {
96  SerializePolicy::Serialize(m_SerializedBuffer, m_Value);
97  }
98  virtual void Deserialize()
99  {
100  SerializePolicy::Deserialize(&m_Value, m_SerializedBuffer);
101  }
102  virtual void ClearValue()
103  {
104  m_Value.Clear();
105  }
106 
107 
108 private:
109  static const size_t SIZE = SerializePolicy::SIZE;
110  static const size_t DIVIDE_LAST_SIZE = (SIZE - 1) % DIVIDE_SIZE + 1;
111  static const u32 DIVIDE_NUM = (SIZE - DIVIDE_LAST_SIZE) / DIVIDE_SIZE + 1;
112 
113 private:
114  Value m_Value;
115  u8 m_SerializedBuffer[SIZE];
116  DivideInfo m_aDivideInfo[DIVIDE_NUM];
117 
118  //! @endcond
119 };
120 
121 
122 //! @cond
123 template <typename Value, size_t DIVIDE_SIZE, typename SerializePolicy>
125 {
126  PIA_COMPILE_ASSERT(DIVIDE_NUM <= 0xffff);
127 
128  nn::Result r = SetValueCore();
129  if (r.IsSuccess())
130  {
131  m_Value = value;
132  PostSetValue();
133  }
134  return r;
135 }
136 //! @endcond
137 }
138 }
139 } // end of namespace nn::pia::clone
ReliableLargeCloneElement()
Instantiates the object with default parameters (default constructor).
Definition: clone_ReliableLargeCloneElement.h:57
Definition: assert.h:115
virtual ~ReliableLargeCloneElement()
Destructor.
Definition: clone_ReliableLargeCloneElement.h:66
const Value & GetValue() const
Gets a value.
Definition: clone_ReliableLargeCloneElement.h:85
Value_ Value
Specifies the type of value managed by this object.
Definition: clone_ReliableLargeCloneElement.h:44
nn::Result SetValue(const Value &value)
Sets values.
The base class for managing the sending and receiving of reliable large-sized data.
Definition: clone_ReliableLargeCloneElementBase.h:38
Manages sending and receiving reliable large-sized data.
Definition: clone_ReliableLargeCloneElement.h:38
SerializePolicy_ SerializePolicy
Specifies the algorithm to use for serializing Value.
Definition: clone_ReliableLargeCloneElement.h:50