Safir SDK Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BlobLayout.h
Go to the documentation of this file.
1 /******************************************************************************
2 *
3 * Copyright Saab AB, 2004-2013 (http://safir.sourceforge.net)
4 *
5 * Created by: Joel Ottosson / joot
6 *
7 *******************************************************************************
8 *
9 * This file is part of Safir SDK Core.
10 *
11 * Safir SDK Core is free software: you can redistribute it and/or modify
12 * it under the terms of version 3 of the GNU General Public License as
13 * published by the Free Software Foundation.
14 *
15 * Safir SDK Core is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more Internals.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Safir SDK Core. If not, see <http://www.gnu.org/licenses/>.
22 *
23 ******************************************************************************/
24 #ifndef __DOTS_INTERNAL_BLOB_LAYOUT_H__
25 #define __DOTS_INTERNAL_BLOB_LAYOUT_H__
26 
27 #include <Safir/Dob/Typesystem/ToolSupport/Internal/BlobLayoutImpl.h>
28 
29 namespace Safir
30 {
31 namespace Dob
32 {
33 namespace Typesystem
34 {
35 namespace ToolSupport
36 {
38 
42  template <class RepT>
43  class BlobLayout
44  {
45  public:
46  //ctor
47  BlobLayout(const RepT* repository)
48  :m_impl(repository)
49  {
50  }
51 
52  //---------------------
53  // Blob operations
54  //---------------------
55  //Create a blob
56  void CreateBlob(const DotsC_TypeId typeId, char * & blob) const
57  {
58  m_impl.CreateBlob(typeId, blob);
59  }
60 
61  //Delete a blob created with create blob
62  void DeleteBlob(char * & blob) const
63  {
64  m_impl.DeleteBlob(blob);
65 
66  }
67 
68  //format a piece of blank memory to be a blob of a desired type
69  //does not check that the size of the blob is correct.
70  void FormatBlob(char * const blob,
71  const DotsC_Int32 blobSize,
72  const DotsC_TypeId typeId,
73  char * & beginningOfUnused) const
74  {
75  m_impl.FormatBlob(blob, blobSize, typeId, beginningOfUnused);
76  }
77 
78  DotsC_Int32 GetSize(const char * const blob) const
79  {
80  return m_impl.GetSize(blob);
81  }
82 
83  DotsC_TypeId GetTypeId(const char * const blob) const
84  {
85  return m_impl.GetTypeId(blob);
86  }
87 
88  bool IsAnythingChanged(const char * const blob) const
89  {
90  return m_impl.IsAnythingChanged(blob);
91  }
92 
93  void SetChanged(char * const blob, const bool changed) const
94  {
95  m_impl.SetChanged(blob, changed);
96  }
97 
98  void ResetChanged(char * const blob) const
99  {
100  m_impl.ResetChanged(blob);
101  }
102 
103  void MergeChanges(const char * const val, char * & blob) const
104  {
105  m_impl.MergeChanges(val, blob);
106  }
107 
108  bool SetChangedSinceLastRead(const char * const lastRead, char * const current) const
109  {
110  return m_impl.SetChangedSinceLastRead(lastRead, current);
111  }
112 
113  //---------------------
114  // Get members
115  //---------------------
116  MemberStatus GetMemberStatus(const char * const blob,
117  const DotsC_MemberIndex member,
118  const DotsC_ArrayIndex index) const
119  {
120  return m_impl.GetStatus(blob, member, index);
121  }
122 
123  MemberStatus GetBoolMember(const char * const blob,
124  const DotsC_MemberIndex member,
125  const DotsC_ArrayIndex index,
126  bool & val) const
127  {
128  return m_impl.template GetMember<bool>(blob, member, index, val);
129  }
130 
131  MemberStatus GetEnumMember(const char * const blob,
132  const DotsC_MemberIndex member,
133  const DotsC_ArrayIndex index,
134  DotsC_EnumerationValue& val) const
135  {
136  return m_impl.template GetMember<DotsC_EnumerationValue>(blob, member, index, val);
137  }
138 
139  MemberStatus GetInt32Member(const char * const blob,
140  const DotsC_MemberIndex member,
141  const DotsC_ArrayIndex index,
142  DotsC_Int32& val) const
143  {
144  return m_impl.template GetMember<DotsC_Int32>(blob, member, index, val);
145  }
146 
147  MemberStatus GetInt64Member(const char * const blob,
148  const DotsC_MemberIndex member,
149  const DotsC_ArrayIndex index,
150  DotsC_Int64& val) const
151  {
152  return m_impl.template GetMember<DotsC_Int64>(blob, member, index, val);
153  }
154 
155  MemberStatus GetFloat32Member(const char * const blob,
156  const DotsC_MemberIndex member,
157  const DotsC_ArrayIndex index,
158  DotsC_Float32& val) const
159  {
160  return m_impl.template GetMember<DotsC_Float32>(blob, member, index, val);
161  }
162 
163  MemberStatus GetFloat64Member(const char * const blob,
164  const DotsC_MemberIndex member,
165  const DotsC_ArrayIndex index,
166  DotsC_Float64& val) const
167  {
168  return m_impl.template GetMember<DotsC_Float64>(blob, member, index, val);
169  }
170 
171  MemberStatus GetHashedMember(const char * const blob,
172  const DotsC_MemberIndex member,
173  const DotsC_ArrayIndex index,
174  DotsC_Int64 & hashVal,
175  const char * & strVal) const
176  {
177  return m_impl.template GetMemberWithOptionalString<DotsC_Int64>(blob, member, index, hashVal, strVal);
178  }
179 
180  MemberStatus GetEntityIdMember(const char * const blob,
181  const DotsC_MemberIndex member,
182  const DotsC_ArrayIndex index,
183  DotsC_EntityId & entityId,
184  const char * & strVal) const
185  {
186  return m_impl.template GetMemberWithOptionalString<DotsC_EntityId>(blob, member, index, entityId, strVal);
187  }
188 
189  MemberStatus GetDynamicMember(const char * const blob,
190  const DotsC_MemberIndex member,
191  const DotsC_ArrayIndex index,
192  const char * & val, //out
193  DotsC_Int32 & binarySize) const
194  {
195  return m_impl.GetDynamicMember(blob, member, index, val, binarySize);
196  }
197 
199  const DotsC_MemberIndex member,
200  const DotsC_ArrayIndex index,
201  char*& val, //out
202  DotsC_Int32& binarySize) const
203  {
204  return m_impl.GetDynamicMember(blob, member, index, val, binarySize);
205  }
206 
207 
209  // Set members
210  //----------------------
211  void SetMemberStatus(const bool isNull,
212  const bool isChanged,
213  char * const blob,
214  const DotsC_MemberIndex member,
215  const DotsC_ArrayIndex index) const
216  {
217  m_impl.SetStatus(isNull, isChanged, blob, member, index);
218  }
219 
220  void SetBoolMember(const bool val,
221  char * blob,
222  const DotsC_MemberIndex member,
223  const DotsC_ArrayIndex index) const
224  {
225  m_impl.template SetMember<bool>(val, blob, member, index);
226  }
227 
228  void SetEnumMember(const DotsC_EnumerationValue val,
229  char * blob,
230  const DotsC_MemberIndex member,
231  const DotsC_ArrayIndex index) const
232  {
233  m_impl.template SetMember<DotsC_EnumerationValue>(val, blob, member, index);
234  }
235 
236  void SetInt32Member(const DotsC_Int32 val,
237  char * blob,
238  const DotsC_MemberIndex member,
239  const DotsC_ArrayIndex index) const
240  {
241  m_impl.template SetMember<DotsC_Int32>(val, blob, member, index);
242  }
243 
244  void SetInt64Member(const DotsC_Int64 val,
245  char * blob,
246  const DotsC_MemberIndex member,
247  const DotsC_ArrayIndex index) const
248  {
249  m_impl.template SetMember<DotsC_Int64>(val, blob, member, index);
250  }
251 
252  void SetFloat32Member(const DotsC_Float32 val,
253  char * blob,
254  const DotsC_MemberIndex member,
255  const DotsC_ArrayIndex index) const
256  {
257  m_impl.template SetMember<DotsC_Float32>(val, blob, member, index);
258  }
259 
260  void SetFloat64Member(const DotsC_Float64 val,
261  char * blob,
262  const DotsC_MemberIndex member,
263  const DotsC_ArrayIndex index) const
264  {
265  m_impl.template SetMember<DotsC_Float64>(val, blob, member, index);
266  }
267 
268  void SetHashedMember(const DotsC_Int64 hashVal,
269  const char * const strVal,
270  char * & blob,
271  const DotsC_MemberIndex member,
272  const DotsC_ArrayIndex index) const
273  {
274  m_impl.SetMemberWithOptionalString(hashVal, strVal, blob, member, index);
275  }
276 
277  void SetEntityIdMember(const DotsC_EntityId entityId,
278  const char * const strVal,
279  char * & blob,
280  const DotsC_MemberIndex member,
281  const DotsC_ArrayIndex index) const
282  {
283  m_impl.SetMemberWithOptionalString(entityId, strVal, blob, member, index);
284  }
285 
286  void SetDynamicMember(const char * const val,
287  const DotsC_Int32 binarySize, //only used if type is Binary
288  char * & blob,
289  const DotsC_MemberIndex member,
290  const DotsC_ArrayIndex index) const
291  {
292  m_impl.SetDynamicMember(val, binarySize, blob, member, index);
293  }
294 
295  //-------------------------
296  // Create dynamic members
297  //-------------------------
298 
299  //the new blob will be placed at the position that beginningOfUnused points to _before_ the call
300  //after the call beginningOfUnused will be updated to point past the newly created object
301  void CreateObjectMember(char * const insideBlob,
302  const DotsC_Int32 size,
303  const DotsC_TypeId typeId,
304  const DotsC_MemberIndex member,
305  const DotsC_ArrayIndex index,
306  const bool isChanged,
307  char * & beginningOfUnused) const
308  {
309  m_impl.CreateObjectMember(insideBlob, size, typeId, member, index, isChanged, beginningOfUnused);
310  }
311 
312  //the new string will be placed at the position that beginningOfUnused points to _before_ the call
313  //after the call beginningOfUnused will be updated to point past the newly created string
314  void CreateStringMember(char * const insideBlob,
315  const DotsC_Int32 stringLength, //remember the null-termination!
316  const DotsC_MemberIndex member,
317  const DotsC_ArrayIndex index,
318  const bool isChanged,
319  char * & beginningOfUnused) const
320  {
321  m_impl.CreateStringMember(insideBlob, stringLength, member, index, isChanged, beginningOfUnused);
322  }
323 
324  //the new binary will be placed at the position that beginningOfUnused points to _before_ the call
325  //after the call beginningOfUnused will be updated to point past the newly created binary
326  void CreateBinaryMember(char * const insideBlob,
327  const DotsC_Int32 binarySize,
328  const DotsC_MemberIndex member,
329  const DotsC_ArrayIndex index,
330  const bool isChanged,
331  char * & beginningOfUnused) const
332  {
333  m_impl.CreateBinaryMember(insideBlob, binarySize, member, index, isChanged, beginningOfUnused);
334  }
335 
336  //if the string is non-null the new hash and string will be placed at the position that beginningOfUnused
337  //if the string is null the dynamic part of the blob will be untouched.
338  //points to _before_ the call. After the call beginningOfUnused will be updated to point past the newly set data.
339  template <class T>
340  void CreateAndSetMemberWithOptionalString(char * const blob,
341  const T hashVal,
342  const char * const strVal,
343  const DotsC_Int32 stringLength,
344  const DotsC_MemberIndex member,
345  const DotsC_ArrayIndex index,
346  const bool isChanged,
347  char * & beginningOfUnused) const
348  {
349  m_impl.template CreateAndSetMemberWithOptionalString<T>(blob, hashVal, strVal, stringLength, member, index, isChanged, beginningOfUnused);
350  }
351 
352  private:
353  const Internal::BlobLayoutImpl<RepT> m_impl;
354  };
355 }
356 }
357 }
358 } //end namespace Safir::Dob::Typesystem::Internal
359 
360 #endif
void FormatBlob(char *const blob, const DotsC_Int32 blobSize, const DotsC_TypeId typeId, char *&beginningOfUnused) const
Definition: BlobLayout.h:70
MemberStatus GetFloat64Member(const char *const blob, const DotsC_MemberIndex member, const DotsC_ArrayIndex index, DotsC_Float64 &val) const
Definition: BlobLayout.h:163
void CreateBlob(const DotsC_TypeId typeId, char *&blob) const
Definition: BlobLayout.h:56
MemberStatus GetHashedMember(const char *const blob, const DotsC_MemberIndex member, const DotsC_ArrayIndex index, DotsC_Int64 &hashVal, const char *&strVal) const
Definition: BlobLayout.h:171
void SetFloat64Member(const DotsC_Float64 val, char *blob, const DotsC_MemberIndex member, const DotsC_ArrayIndex index) const
Definition: BlobLayout.h:260
Operations on blobs.
Definition: BlobLayout.h:43
void MergeChanges(const char *const val, char *&blob) const
Definition: BlobLayout.h:103
void CreateAndSetMemberWithOptionalString(char *const blob, const T hashVal, const char *const strVal, const DotsC_Int32 stringLength, const DotsC_MemberIndex member, const DotsC_ArrayIndex index, const bool isChanged, char *&beginningOfUnused) const
Definition: BlobLayout.h:340
BlobLayout(const RepT *repository)
Definition: BlobLayout.h:47
void SetHashedMember(const DotsC_Int64 hashVal, const char *const strVal, char *&blob, const DotsC_MemberIndex member, const DotsC_ArrayIndex index) const
Definition: BlobLayout.h:268
bool IsAnythingChanged(const char *const blob) const
Definition: BlobLayout.h:88
MemberStatus GetEnumMember(const char *const blob, const DotsC_MemberIndex member, const DotsC_ArrayIndex index, DotsC_EnumerationValue &val) const
Definition: BlobLayout.h:131
void SetEnumMember(const DotsC_EnumerationValue val, char *blob, const DotsC_MemberIndex member, const DotsC_ArrayIndex index) const
Definition: BlobLayout.h:228
MemberStatus GetInt64Member(const char *const blob, const DotsC_MemberIndex member, const DotsC_ArrayIndex index, DotsC_Int64 &val) const
Definition: BlobLayout.h:147
DotsC_Int32 GetSize(const char *const blob) const
Definition: BlobLayout.h:78
DotsC_TypeId GetTypeId(const char *const blob) const
Definition: BlobLayout.h:83
void SetChanged(char *const blob, const bool changed) const
Definition: BlobLayout.h:93
void SetDynamicMember(const char *const val, const DotsC_Int32 binarySize, char *&blob, const DotsC_MemberIndex member, const DotsC_ArrayIndex index) const
Definition: BlobLayout.h:286
void SetFloat32Member(const DotsC_Float32 val, char *blob, const DotsC_MemberIndex member, const DotsC_ArrayIndex index) const
Definition: BlobLayout.h:252
MemberStatus GetInt32Member(const char *const blob, const DotsC_MemberIndex member, const DotsC_ArrayIndex index, DotsC_Int32 &val) const
Definition: BlobLayout.h:139
void SetInt32Member(const DotsC_Int32 val, char *blob, const DotsC_MemberIndex member, const DotsC_ArrayIndex index) const
Definition: BlobLayout.h:236
void DeleteBlob(char *&blob) const
Definition: BlobLayout.h:62
MemberStatus GetMemberStatus(const char *const blob, const DotsC_MemberIndex member, const DotsC_ArrayIndex index) const
Definition: BlobLayout.h:116
void CreateObjectMember(char *const insideBlob, const DotsC_Int32 size, const DotsC_TypeId typeId, const DotsC_MemberIndex member, const DotsC_ArrayIndex index, const bool isChanged, char *&beginningOfUnused) const
Definition: BlobLayout.h:301
MemberStatus GetDynamicMember(const char *const blob, const DotsC_MemberIndex member, const DotsC_ArrayIndex index, const char *&val, DotsC_Int32 &binarySize) const
Definition: BlobLayout.h:189
MemberStatus GetWritableDynamicMember(char *blob, const DotsC_MemberIndex member, const DotsC_ArrayIndex index, char *&val, DotsC_Int32 &binarySize) const
Definition: BlobLayout.h:198
void SetMemberStatus(const bool isNull, const bool isChanged, char *const blob, const DotsC_MemberIndex member, const DotsC_ArrayIndex index) const
Definition: BlobLayout.h:211
void SetInt64Member(const DotsC_Int64 val, char *blob, const DotsC_MemberIndex member, const DotsC_ArrayIndex index) const
Definition: BlobLayout.h:244
void SetEntityIdMember(const DotsC_EntityId entityId, const char *const strVal, char *&blob, const DotsC_MemberIndex member, const DotsC_ArrayIndex index) const
Definition: BlobLayout.h:277
MemberStatus GetEntityIdMember(const char *const blob, const DotsC_MemberIndex member, const DotsC_ArrayIndex index, DotsC_EntityId &entityId, const char *&strVal) const
Definition: BlobLayout.h:180
void ResetChanged(char *const blob) const
Definition: BlobLayout.h:98
MemberStatus GetFloat32Member(const char *const blob, const DotsC_MemberIndex member, const DotsC_ArrayIndex index, DotsC_Float32 &val) const
Definition: BlobLayout.h:155
bool SetChangedSinceLastRead(const char *const lastRead, char *const current) const
Definition: BlobLayout.h:108
Safir::Dob::Typesystem::ToolSupport::Internal::MemberStatus MemberStatus
Definition: BlobLayout.h:37
MemberStatus GetBoolMember(const char *const blob, const DotsC_MemberIndex member, const DotsC_ArrayIndex index, bool &val) const
Definition: BlobLayout.h:123
void SetBoolMember(const bool val, char *blob, const DotsC_MemberIndex member, const DotsC_ArrayIndex index) const
Definition: BlobLayout.h:220
void CreateStringMember(char *const insideBlob, const DotsC_Int32 stringLength, const DotsC_MemberIndex member, const DotsC_ArrayIndex index, const bool isChanged, char *&beginningOfUnused) const
Definition: BlobLayout.h:314
void CreateBinaryMember(char *const insideBlob, const DotsC_Int32 binarySize, const DotsC_MemberIndex member, const DotsC_ArrayIndex index, const bool isChanged, char *&beginningOfUnused) const
Definition: BlobLayout.h:326