42 template <
typename VectorType>
43 void CoherentVectorElementReader(Binder* binder,
void* data,
size_t position)
45 auto castedData = (VectorType*)data;
46 CoherentReadInternal(binder, castedData[position]);
49 template <
typename VectorType>
50 void* CoherentVectorNativeElementReader(
void* data,
size_t position)
52 return &(*(VectorType*)data)[position];
55 template <
typename VectorType>
56 size_t CoherentVectorLength(
void* data)
58 return ((VectorType*)data)->size();
61 template <
typename VectorType,
typename T>
62 typename EnableIf<!cohtml::PointerTrait<T>::Value,
void>::Type CoherentVectorElementReader(Binder* binder,
void* data,
size_t position)
64 CoherentReadInternal(binder, (*(VectorType*)data)[position]);
67 template <
typename VectorType,
typename T>
68 typename EnableIf<cohtml::PointerTrait<T>::Value,
void>::Type CoherentVectorElementReader(Binder* binder,
void* data,
size_t position)
70 typedef typename UnwrapPointerType<T, PointerTrait<T>::Value>::Type UnwrappedType;
72 if (
auto unwrappedObjectPtr = (UnwrappedType*)UnwrapPointer<T>::Unwrap(&(*(VectorType*)data)[position]))
74 CoherentReadInternal(binder, *unwrappedObjectPtr);
78 template <
typename VectorType,
typename T>
79 typename EnableIf<!cohtml::PointerTrait<T>::Value,
void*>::Type CoherentVectorNativeElementReader(
void* data,
size_t position)
81 return &(*(VectorType*)data)[position];
84 template <
typename VectorType,
typename T>
85 typename EnableIf<cohtml::PointerTrait<T>::Value,
void*>::Type CoherentVectorNativeElementReader(
void* data,
size_t position)
87 return UnwrapPointer<T>::Unwrap(&(*(VectorType*)data)[position]);
90 typedef void(*Reader)(Binder*,
void*, size_t);
91 typedef void*(*NativeReader)(
void*, size_t);
92 typedef size_t(*VectorLengthFunc)(
void*);
95 class VectorReaderFactory
98 static Reader ElementReader()
100 return cohtml::CoherentVectorElementReader<T>;
103 static NativeReader NativeElementReader()
105 return cohtml::CoherentVectorNativeElementReader<T>;
108 static VectorLengthFunc VectorLength()
110 return CoherentVectorLength<T>;
114 template <
typename T,
typename A>
115 class VectorReaderFactory<std::vector<T, A>>
118 typedef std::vector<T, A> VectorType;
120 static Reader ElementReader()
122 return cohtml::CoherentVectorElementReader<VectorType, T>;
125 static NativeReader NativeElementReader()
127 return cohtml::CoherentVectorNativeElementReader<VectorType, T>;
130 static VectorLengthFunc VectorLength()
132 return CoherentVectorLength<VectorType>;
136 template <
typename VectorType>
137 void CoherentVectorElementBinder(Binder* binder,
void* arr,
size_t index)
139 auto castedArray = (VectorType*)arr;
142 CoherentBindInternal(binder, castedArray[index]);
150 template <
typename T,
typename A>
151 void CoherentBindInternal(Binder* binder, std::vector<T, A>& value)
153 if (!binder->TryBindArrayByRef(value.data(),
155 CoherentVectorElementBinder<T>,
156 VectorReaderFactory<std::vector<T, A>>::ElementReader()))
158 binder->ArrayBegin(value.size());
159 typedef typename std::vector<T, A>::const_iterator Iterator;
161 Iterator end = value.end();
162 for (Iterator i = value.begin(); i != end; ++i)
164 CoherentBindInternal(binder, *i);
171 template <
typename T,
typename A>
172 void CoherentBindInternal(Binder* binder,
const std::vector<T, A>& value)
174 if (!binder->TryBindArrayByRef(const_cast<T*>(value.data()),
176 CoherentVectorElementBinder<T>,
177 VectorReaderFactory<std::vector<T, A>>::ElementReader()))
179 binder->ArrayBegin(value.size());
180 typedef typename std::vector<T, A>::const_iterator Iterator;
182 Iterator end = value.end();
183 for (Iterator i = value.begin(); i != end; ++i)
185 CoherentBindInternal(binder, *i);
192 template <
typename A>
193 void CoherentBindInternal(Binder* binder, std::vector<float, A>& value)
195 if (!binder->TryBindArrayByRef(value.data(),
197 CoherentVectorElementBinder<float>,
198 VectorReaderFactory<float>::ElementReader()))
200 binder->BindArray(&value[0], value.size());
204 template <
typename A>
205 void CoherentBindInternal(Binder* binder,
const std::vector<float, A>& value)
207 if (!binder->TryBindArrayByRef(const_cast<float*>(value.data()),
209 CoherentVectorElementBinder<float>,
210 VectorReaderFactory<float>::ElementReader()))
212 binder->BindArray(&value[0], value.size());
216 template <
typename A>
217 void CoherentBindInternal(Binder* binder, std::vector<int, A>& value)
219 if (!binder->TryBindArrayByRef(value.data(),
221 CoherentVectorElementBinder<int>,
222 VectorReaderFactory<int>::ElementReader()))
224 binder->BindArray(&value[0], value.size());
228 template <
typename A>
229 void CoherentBindInternal(Binder* binder,
const std::vector<int, A>& value)
231 if (!binder->TryBindArrayByRef(const_cast<int*>(value.data()),
233 CoherentVectorElementBinder<int>,
234 VectorReaderFactory<int>::ElementReader()))
236 binder->BindArray(&value[0], value.size());
240 template <
typename T,
typename A>
241 void CoherentReadInternal(Binder* binder, std::vector<T, A>& value)
243 typedef typename std::vector<T, A>::iterator Iterator;
245 size_t size = binder->ReadArrayBegin();
249 Iterator end = value.end();
251 for (Iterator i = value.begin(); i != end; ++i)
253 binder->ReadArrayElement(index++);
254 CoherentReadInternal(binder, *i);
257 binder->ReadArrayEnd();
260 template<
typename T,
typename A>
261 struct TypeToElementType<const std::vector<T, A>>
263 static constexpr ElementType value = ElementType::ET_Array;
266 template<
typename T,
typename A>
267 struct TypeToElementType<std::vector<T, A>>
269 static constexpr ElementType value = ElementType::ET_Array;
272 template<
typename T,
typename A>
273 struct TypeToElementType<std::vector<T, A>&>
275 static constexpr ElementType value = ElementType::ET_Array;
278 template<
typename T,
typename A>
279 struct TypeToElementType<const std::vector<T, A>&>
281 static constexpr ElementType value = ElementType::ET_Array;
284 template <
typename T>
285 struct IsVector : FalseType
287 typedef T ElementType;
288 typedef T AllocatorType;
291 template <
typename T,
typename A>
292 struct IsVector<std::vector<T, A>> : TrueType
294 typedef T ElementType;
295 typedef A AllocatorType;
298 template <
typename T>
299 typename EnableIf<!IsVector<typename UnwrapPointerType<T, PointerTrait<T>::Value>::Type>::Value,
bool>::Type
300 GetArrayValueInvoke(Binder* binder,
void*
object, ArrayInfo* arrayInfo,
const TypedProperty<const T&>* prop)
302 UNUSED_PARAM(binder);
303 UNUSED_PARAM(
object);
304 UNUSED_PARAM(arrayInfo);
309 template <
typename T>
310 typename EnableIf<!IsVector<typename UnwrapPointerType<T, PointerTrait<T>::Value>::Type>::Value,
bool>::Type
311 GetArrayValueInvoke(Binder* binder,
void*
object, ArrayInfo* arrayInfo,
const TypedProperty<T&>* prop)
313 UNUSED_PARAM(binder);
314 UNUSED_PARAM(
object);
315 UNUSED_PARAM(arrayInfo);
320 template <
typename T,
typename A>
321 bool GetArrayValueInvoke(Binder* binder, ArrayInfo* arrayInfo, std::vector<T, A>* pVector)
328 *arrayInfo = ArrayInfo{
329 TypeToElementType<T>::value,
330 VectorReaderFactory<std::vector<T, A>>::VectorLength(),
331 VectorReaderFactory<std::vector<T, A>>::NativeElementReader(),
332 CoherentTypeInfo<T>::Get(binder),
339 template <
typename T>
340 typename EnableIf<IsVector<typename UnwrapPointerType<T, PointerTrait<T>::Value>::Type>::Value,
bool>::Type
341 GetArrayValueInvoke(Binder* binder,
void*
object, ArrayInfo* arrayInfo,
const TypedProperty<const T&>* prop)
343 typedef typename UnwrapPointerType<T, PointerTrait<T>::Value>::Type UnwrappedType;
344 auto pVector = (UnwrappedType*)UnwrapPointer<T>::Unwrap(const_cast<T*>(&prop->GetValue(
object)));
346 return GetArrayValueInvoke(binder, arrayInfo, pVector);
349 template <
typename T>
350 typename EnableIf<IsVector<typename UnwrapPointerType<T, PointerTrait<T>::Value>::Type>::Value,
bool>::Type
351 GetArrayValueInvoke(Binder* binder,
void*
object, ArrayInfo* arrayInfo,
const TypedProperty<T&>* prop)
353 typedef typename UnwrapPointerType<T, PointerTrait<T>::Value>::Type UnwrappedType;
354 auto pVector = (UnwrappedType*)UnwrapPointer<T>::Unwrap(const_cast<T*>(&prop->GetValue(
object)));
356 return GetArrayValueInvoke(binder, arrayInfo, pVector);
360 struct GetArrayValue<const T&>
362 static bool Invoke(Binder* binder,
void*
object, ArrayInfo* arrayInfo,
const TypedProperty<const T&>* prop)
364 return GetArrayValueInvoke(binder,
object, arrayInfo, prop);
369 struct GetArrayValue<T&>
371 static bool Invoke(Binder* binder,
void*
object, ArrayInfo* arrayInfo,
const TypedProperty<T&>* prop)
373 return GetArrayValueInvoke(binder,
object, arrayInfo, prop);
Contains almost all Coherent namespaces, classes and functions.
Definition: DataStorage.h:38