1.3.1.2
Gameface
Pair.h
1 /*
2 This file is part of Cohtml, Gameface and Prysm - modern user interface technologies.
3 
4 Copyright (c) 2012-2018 Coherent Labs AD and/or its licensors. All
5 rights reserved in all media.
6 
7 The coded instructions, statements, computer programs, and/or related
8 material (collectively the "Data") in these files contain confidential
9 and unpublished information proprietary Coherent Labs and/or its
10 licensors, which is protected by United States of America federal
11 copyright law and by international treaties.
12 
13 This software or source code is supplied under the terms of a license
14 agreement and nondisclosure agreement with Coherent Labs AD and may
15 not be copied, disclosed, or exploited except in accordance with the
16 terms of that agreement. The Data may not be disclosed or distributed to
17 third parties, in whole or in part, without the prior written consent of
18 Coherent Labs AD.
19 
20 COHERENT LABS MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS
21 SOURCE CODE FOR ANY PURPOSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
22 HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
23 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE
25 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER, ITS AFFILIATES,
26 PARENT COMPANIES, LICENSORS, SUPPLIERS, OR CONTRIBUTORS BE LIABLE FOR
27 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 ANY WAY OUT OF THE USE OR PERFORMANCE OF THIS SOFTWARE OR SOURCE CODE,
33 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35 #pragma once
36 
37 namespace cohtml
38 {
39 template <typename T1, typename T2>
40 void CoherentBindInternal(Binder* binder, std::pair<T1, T2>& value)
41 {
42  binder->MapBegin(2);
43 
44  CoherentBindInternal(binder, "first");
45  CoherentBindInternal(binder, value.first);
46  CoherentBindInternal(binder, "second");
47  CoherentBindInternal(binder, value.second);
48 
49  binder->MapEnd();
50 }
51 
52 template <typename T1, typename T2>
53 void CoherentBindInternal(Binder* binder, const std::pair<T1, T2>& value)
54 {
55  binder->MapBegin(2);
56 
57  CoherentBindInternal(binder, "first");
58  CoherentBindInternal(binder, value.first);
59  CoherentBindInternal(binder, "second");
60  CoherentBindInternal(binder, value.second);
61 
62  binder->MapEnd();
63 }
64 
65 template <typename T1, typename T2>
66 void CoherentReadInternal(Binder* binder, std::pair<T1, T2>& value)
67 {
68  size_t size = binder->ReadMapBegin();
69  (void)size;
70 
71  if (binder->ReadProperty("first"))
72  {
73  CoherentReadInternal(binder, value.first);
74  }
75 
76  if (binder->ReadProperty("second"))
77  {
78  CoherentReadInternal(binder, value.second);
79  }
80 
81  binder->ReadMapEnd();
82 }
83 
84 template<typename T1, typename T2>
85 struct TypeToElementType<std::pair<T1, T2>>
86 {
87  static const ElementType value = ElementType::ET_Pair;
88 };
89 
90 template <typename T>
91 struct IsPair : FalseType
92 {
93 };
94 
95 template <typename T1, typename T2>
96 struct IsPair<std::pair<T1, T2>> : TrueType
97 {
98 };
99 
100 template <typename T>
101 inline typename EnableIf<!IsPair<typename UnwrapPointerType<T, PointerTrait<T>::Value>::Type>::Value, bool>::Type
102 GetPairValueInvoke(Binder* binder, void* object, PairInfo* pairInfo, const TypedProperty<T&>* prop)
103 {
104  UNUSED_PARAM(binder);
105  UNUSED_PARAM(object);
106  UNUSED_PARAM(pairInfo);
107  UNUSED_PARAM(prop);
108  return false;
109 }
110 
111 template <typename T1, typename T2>
112 inline bool GetPairValueInvoke(Binder* binder, PairInfo* pairInfo, std::pair<T1, T2>* pPair)
113 {
114  if (!pPair)
115  {
116  return false;
117  }
118  typedef typename UnwrapPointerType<T1, PointerTrait<T1>::Value>::Type UnwrappedType1;
119  auto first = static_cast<UnwrappedType1*>(UnwrapPointer<T1>::Unwrap(const_cast<T1*>(&pPair->first)));
120  typedef typename UnwrapPointerType<T2, PointerTrait<T2>::Value>::Type UnwrappedType2;
121  auto second = static_cast<UnwrappedType2*>(UnwrapPointer<T2>::Unwrap(const_cast<T2*>(&pPair->second)));
122 
123  *pairInfo = PairInfo{
126  { first, second }
127  };
128 
129  return true;
130 }
131 
132 template <typename T>
133 typename EnableIf<IsPair<typename UnwrapPointerType<T, PointerTrait<T>::Value>::Type>::Value, bool>::Type
134 GetPairValueInvoke(Binder* binder, void* object, PairInfo* arrayInfo, const TypedProperty<T&>* prop)
135 {
136  typedef typename UnwrapPointerType<T, PointerTrait<T>::Value>::Type UnwrappedType;
137  auto pPair = (UnwrappedType*)UnwrapPointer<T>::Unwrap(const_cast<T*>(&prop->GetValue(object)));
138 
139  return GetPairValueInvoke(binder, arrayInfo, pPair);
140 }
141 
142 template<typename T>
143 struct GetPairValue<T&>
144 {
145  static bool Invoke(Binder* binder, void* object, PairInfo* pairInfo, const TypedProperty<T&>* prop)
146  {
147  return GetPairValueInvoke(binder, object, pairInfo, prop);
148  }
149 };
150 
151 }
virtual ValuePassType GetValue(void *object) const =0
void CoherentReadInternal(Binder *binder, ArrayType(&array)[ArraySize])
Definition: Array.h:118
Definition: TypeTraits.h:323
Definition: Property.h:525
void CoherentBindInternal(Binder *binder, ArrayType(&array)[ArraySize])
Definition: Array.h:80
static void * Unwrap(T *ptr)
Definition: TypeTraits.h:325
Contains almost all Coherent namespaces, classes and functions.
Definition: CursorTypes.h:37
Represents a pair of a type exposed to the scripting.
Definition: Property.h:322
Definition: Pair.h:91
ElementType
Definition: Property.h:299
virtual void MapBegin(size_t size)=0
Start exporting a map (object)
virtual size_t ReadMapBegin()=0
Start reading a map (object)
virtual void MapEnd()=0
End exporting a map.
virtual bool ReadProperty(const char *name)=0
Provides binding between C++ and the UI.
Definition: Binder.h:138
virtual void ReadMapEnd()=0
End reading a map.
Definition: TypeTraits.h:46
Definition: Property.h:580
Definition: TypeTraits.h:352
Definition: TypeTraits.h:385
EnableIf<!IsPair< typename UnwrapPointerType< T, PointerTrait< T >::Value >::Type >::Value, bool >::Type GetPairValueInvoke(Binder *binder, void *object, PairInfo *pairInfo, const TypedProperty< T &> *prop)
Definition: Pair.h:102
Definition: Property.h:528
static const ElementType value
Definition: Property.h:613
static TypeInfo * Get(Binder *binder)
Definition: Property.h:730
static bool Invoke(Binder *binder, void *object, PairInfo *pairInfo, const TypedProperty< T &> *prop)
Definition: Pair.h:145