CTR Pia  4.11.3
Game Communication Engine
clone_ReliableCloneElement.h
1 /*---------------------------------------------------------------------------*
2  Project: Pia
3  File: clone_ReliableCloneElement.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_ReliableCloneElementBase.h>
19 
20 namespace nn
21 {
22 namespace pia
23 {
24 namespace clone
25 {
26 
27 
28 /*!
29 @brief Manages the sending and receiving of reliable data.
30 
31 @tparam Value_ Specifies the type of value to manage.
32 @tparam SerializePolicy_ Specifies the algorithm to use for serializing <span class="argument">Value</span>.
33 
34 @date 2013-07-18 Initial version.
35 */
36 template <typename Value_, typename SerializePolicy_ = HostByteOrderSerializePolicy<Value_> >
38 {
39 public:
40 /*!
41 @brief Specifies the type of value managed by this object.
42 */
43  typedef Value_ Value;
44 
45 
46 /*!
47 @brief Specifies the algorithm to use for serializing <span class="argument">Value</span>.
48 */
49  typedef SerializePolicy_ SerializePolicy;
50 
51 
52 /*!
53 @brief Instantiates the object with default parameters (default constructor).
54 */
56  : ReliableCloneElementBase(), m_Value()
57  {
58  }
59 
60 
61 /*!
62 @brief Destroys the object (destructor).
63 */
65  {
66  }
67 
68 
69 /*!
70 @brief Sets values.
71 @param[in] value Specifies the flags to set.
72 @return Returns a <tt>Result</tt> value for which the <tt>IsSuccess</tt> function returns <tt>true</tt> if execution succeeds.
73 @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.
74 @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.
75 */
76  nn::Result SetValue(const Value& value);
77 
78 
79 /*!
80 @brief Gets a value.
81 @return Returns the value managed by this object. This value is undefined when <tt>IsValidValue</tt> returns <tt>false</tt>.
82 */
83  const Value& GetValue() const
84  {
85  return m_Value;
86  }
87 
88 
89  //! @cond PRIVATE
90 
91 protected:
92  virtual size_t GetSize() const
93  {
94  return SerializePolicy::GetSize();
95  }
96  virtual void Serialize(void* pBuffer) const
97  {
98  SerializePolicy::Serialize(pBuffer, m_Value);
99  }
100  virtual void Deserialize(const void* cpData)
101  {
102  SerializePolicy::Deserialize(&m_Value, cpData);
103  }
104  virtual void ClearValue()
105  {
106  m_Value = Value();
107  }
108 
109 private:
110  Value m_Value;
111 
112  //! @endcond
113 };
114 
115 
116 //! @cond
117 template <typename Value, typename SerializePolicy>
119 {
120  nn::Result r = SetValueCore();
121  if (r.IsSuccess())
122  {
123  m_Value = value;
124  }
125  return r;
126 }
127 //! @endcond
128 }
129 }
130 } // end of namespace nn::pia::clone
virtual ~ReliableCloneElement()
Destroys the object (destructor).
Definition: clone_ReliableCloneElement.h:64
Definition: assert.h:115
ReliableCloneElement()
Instantiates the object with default parameters (default constructor).
Definition: clone_ReliableCloneElement.h:55
const Value & GetValue() const
Gets a value.
Definition: clone_ReliableCloneElement.h:83
This is the base class for managing the sending and receiving of reliable data.
Definition: clone_ReliableCloneElementBase.h:36
nn::Result SetValue(const Value &value)
Sets values.
SerializePolicy_ SerializePolicy
Specifies the algorithm to use for serializing Value.
Definition: clone_ReliableCloneElement.h:49
Value_ Value
Specifies the type of value managed by this object.
Definition: clone_ReliableCloneElement.h:43
Manages the sending and receiving of reliable data.
Definition: clone_ReliableCloneElement.h:37