CTR-Pia  5.4.3
Game Communication Engine
 全て クラス ネームスペース 関数 変数 型定義 列挙型 列挙型の値 ページ
clone_ReverseSerializePolicy.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 #pragma once
14 #if 0
15 
16 #include <nn/pia/clone/clone_Definitions.h>
17 #include <nn/pia/common/common_ByteOrder.h>
18 
19 
20 namespace nn
21 {
22 namespace pia
23 {
24 namespace clone
25 {
26 
27 
28 /*!
29  @brief 元のデータのバイトオーダーを反転させてシリアライズします。
30 
31  @tparam Type_ シリアライズ対象のデータ型です。
32 
33  @details このクラスが実装されているのは、 Type が uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t, float, double のものだけです。
34  任意の型に対してこのクラスを使用するためには、その型に対応した Reverse() 関数を実装する必要があります。
35 
36  例えば、
37  @code
38  struct Val
39  {
40  uint32_t a;
41  float b;
42  };
43  @endcode
44  という型に対して、
45  @code
46  template<> void ReverseSerializePolicy<Val>::Reverse(Val* pTo, const Val* cpFrom)
47  {
48  ReverseValue(&pTo->a, &cpFrom->a);
49  ReverseValue(&pTo->b, &cpFrom->b);
50  }
51  @endcode
52  と実装する必要があります。
53  */
54 template <typename Type_>
55 class ReverseSerializePolicy
56 {
57 public:
58  /*!
59  @brief シリアライズ対象のデータ型です。
60  */
61  typedef Type_ Type;
62 
63 
64  /*!
65  @cond PRIVATE
66  @brief シリアライズします。
67  @param[out] pBuffer 出力先バッファです。
68  @param[in] value シリアライズ対象のデータです。
69  */
70  static void Serialize(void* pBuffer, const Type& value)
71  {
72  Reverse(reinterpret_cast<Type*>(pBuffer), &value);
73  }
74  //! @endcond
75 
76 
77  /*!
78  @cond PRIVATE
79  @brief デシリアライズします。
80  @param[out] pValue デシリアライズされたデータの保存先です。
81  @param[in] cpData デシリアライズするバイト列です。
82  */
83  static void Deserialize(Type* pValue, const void* cpData)
84  {
85  Reverse(pValue, reinterpret_cast<const Type*>(cpData));
86  }
87  //! @endcond
88 
89 
90  /*!
91  @cond PRIVATE
92  @brief シリアライズされたサイズを取得します。
93  @details @ref nn::pia::clone::CloneProtocol::GetElementSizeMax() "CloneProtocol::GetElementSizeMax()" より大きな値は使用できません。
94  @return シリアライズされたサイズです。
95  */
96  static uint32_t GetSize()
97  {
98  return sizeof(Type);
99  }
100  //! @endcond
101 
102 
103  /*!
104  @cond PRIVATE
105  @brief シリアライズされたサイズです。
106  @details @ref nn::pia::clone::ReliableLargeCloneElement で使用するときは @ref GetSize() ではなくこちらの値が使われます。
107  */
108  static const uint32_t Size = sizeof(Type);
109  //! @endcond
110 
111 private:
112  /*!
113  @brief バイトオーダーを反転させます。
114 
115  @details この関数が実装されているのは、 Type が uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t, float, double のものだけです。
116  任意の型に対してこのクラスを使用するためには、その型に対応した Reverse() 関数を実装する必要があります。
117  @attention pTo や cpFrom のアライメントは不正な場合があります。
118 
119  @param[out] pTo 反転させたデータの出力先です。
120  @param[in] cpFrom 元データです。
121  */
122  static void Reverse(Type* pTo, const Type* cpFrom);
123 
124 
125  /*!
126  @brief 基本型の値のバイトオーダーを反転させます。
127 
128  @tparam T 反転させる値の型です。
129 
130  @param[out] pTo 反転させた値の出力先です。
131  @param[in] cpFrom 元データです。
132  */
133  template <typename T>
134  static void ReverseValue(T* pTo, const T* cpFrom)
135  {
136  common::ByteOrder::Swap<sizeof(T)>(pTo, cpFrom);
137  }
138 
139  NN_PIA_DISALLOW_COPY(ReverseSerializePolicy);
140 };
141 
142 //! @cond
143 
144 template <>
145 inline void ReverseSerializePolicy<uint8_t>::Reverse(Type* pTo, const Type* pFrom)
146 {
147  ReverseValue(pTo, pFrom);
148 }
149 template <>
150 inline void ReverseSerializePolicy<int8_t>::Reverse(Type* pTo, const Type* pFrom)
151 {
152  ReverseValue(pTo, pFrom);
153 }
154 template <>
155 inline void ReverseSerializePolicy<uint16_t>::Reverse(Type* pTo, const Type* pFrom)
156 {
157  ReverseValue(pTo, pFrom);
158 }
159 template <>
160 inline void ReverseSerializePolicy<int16_t>::Reverse(Type* pTo, const Type* pFrom)
161 {
162  ReverseValue(pTo, pFrom);
163 }
164 template <>
165 inline void ReverseSerializePolicy<uint32_t>::Reverse(Type* pTo, const Type* pFrom)
166 {
167  ReverseValue(pTo, pFrom);
168 }
169 template <>
170 inline void ReverseSerializePolicy<int32_t>::Reverse(Type* pTo, const Type* pFrom)
171 {
172  ReverseValue(pTo, pFrom);
173 }
174 template <>
175 inline void ReverseSerializePolicy<uint64_t>::Reverse(Type* pTo, const Type* pFrom)
176 {
177  ReverseValue(pTo, pFrom);
178 }
179 template <>
180 inline void ReverseSerializePolicy<int64_t>::Reverse(Type* pTo, const Type* pFrom)
181 {
182  ReverseValue(pTo, pFrom);
183 }
184 template <>
185 inline void ReverseSerializePolicy<float>::Reverse(Type* pTo, const Type* pFrom)
186 {
187  ReverseValue(pTo, pFrom);
188 }
189 template <>
190 inline void ReverseSerializePolicy<double>::Reverse(Type* pTo, const Type* pFrom)
191 {
192  ReverseValue(pTo, pFrom);
193 }
194 
195 //! @endcond
196 }
197 }
198 } // end of namespace nn::pia::clone
199 #endif