CTR Pia  4.11.3
Game Communication Engine
clone_UnreliableCloneElement.h
1 /*---------------------------------------------------------------------------*
2  Project: Pia
3  File: clone_UnreliableCloneElement.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_UnreliableCloneElementBase.h>
19 #include <pia/clone/clone_SerializePolicyDefinition.h>
20 
21 namespace nn
22 {
23 namespace pia
24 {
25 namespace clone
26 {
27 
28 
29 /*!
30 @brief Manages the sending and receiving of unreliable data.
31 
32 @tparam Value_ Specifies the type of value to manage.
33 @tparam SerializePolicy_ Specifies the algorithm to use for serializing <span class="argument">Value</span>.
34 
35 @date 2013-07-18 Initial version.
36 */
37 template <typename Value_, 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 <span class="argument">Value</span>.
49 */
50  typedef SerializePolicy_ SerializePolicy;
51 
52 
53 /*!
54 @brief Instantiates the object with default parameters (default constructor).
55 */
57  : UnreliableCloneElementBase(), m_Value()
58  {
59  }
60 
61 
62 /*!
63 @brief Destroys the object (destructor).
64 */
66  {
67  }
68 
69 
70 /*!
71 @brief Sets values.
72 @param[in] value Specifies the flags to set.
73 @return Returns a <tt>Result</tt> value for which the <tt>IsSuccess</tt> function returns <tt>true</tt> if execution succeeds.
74 @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.
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 
110 private:
111  Value m_Value;
112 
113  //! @endcond
114 };
115 
116 
117 //! @cond
118 template <typename Value, typename SerializePolicy>
120 {
121  bool isCopyValue;
122  nn::Result r = SetValueCore(&isCopyValue);
123  if (isCopyValue)
124  {
125  m_Value = value;
126  }
127  return r;
128 }
129 //! @endcond
130 }
131 }
132 } // end of namespace nn::pia::clone
Value_ Value
Specifies the type of value managed by this object.
Definition: clone_UnreliableCloneElement.h:44
This is the base class for managing the sending and receiving of unreliable data. ...
Definition: clone_UnreliableCloneElementBase.h:36
const Value & GetValue() const
Gets a value.
Definition: clone_UnreliableCloneElement.h:83
virtual ~UnreliableCloneElement()
Destroys the object (destructor).
Definition: clone_UnreliableCloneElement.h:65
Definition: assert.h:115
Manages the sending and receiving of unreliable data.
Definition: clone_UnreliableCloneElement.h:38
nn::Result SetValue(const Value &value)
Sets values.
UnreliableCloneElement()
Instantiates the object with default parameters (default constructor).
Definition: clone_UnreliableCloneElement.h:56
SerializePolicy_ SerializePolicy
Specifies the algorithm to use for serializing Value.
Definition: clone_UnreliableCloneElement.h:50