1.3.1.2
Gameface
Map.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 #include "MapCommon.h"
38 
39 namespace cohtml
40 {
41 template <typename Key, typename Value, typename Comparator, typename Allocator>
43  std::map<Key, Value, Comparator, Allocator>& value)
44 {
45  binder->MapBegin(value.size());
46  typedef typename std::map
47  <Key, Value, Comparator, Allocator>::const_iterator Iterator;
48 
49  Iterator end = value.end();
50  for (Iterator i = value.begin(); i != end; ++i)
51  {
52  CoherentBindInternal(binder, i->first);
53  CoherentBindInternal(binder, i->second);
54  }
55 
56  binder->MapEnd();
57 }
58 
59 template <typename Key, typename Value, typename Comparator, typename Allocator>
61  const std::map
62  <Key, Value, Comparator, Allocator>& value)
63 {
64  binder->MapBegin(value.size());
65  typedef typename std::map
66  <Key, Value, Comparator, Allocator>::const_iterator Iterator;
67 
68  Iterator end = value.end();
69  for (Iterator i = value.begin(); i != end; ++i)
70  {
71  CoherentBindInternal(binder, i->first);
72  CoherentBindInternal(binder, i->second);
73  }
74 
75  binder->MapEnd();
76 }
77 
78 template <typename Key, typename Value, typename Comparator, typename Allocator>
80  std::map<Key, Value, Comparator, Allocator>& value)
81 {
82  size_t size = binder->ReadMapBegin();
83 
84  typedef typename std::map
85  <Key, Value, Comparator, Allocator>::value_type ValueType;
86 
87  for (size_t i = 0; i < size; ++i)
88  {
89  Key key;
90  Value mapValue;
91  binder->ReadKeyValuePair();
92  CoherentReadInternal(binder, key);
93  CoherentReadInternal(binder, mapValue);
94 
95  value.insert(ValueType(key, mapValue));
96  }
97 
98  binder->ReadMapEnd();
99 }
100 
101 template<typename Key, typename Value, typename Comparator, typename Allocator>
102 struct TypeToElementType<std::map<Key, Value, Comparator, Allocator>>
103 {
104  static const ElementType value = ElementType::ET_Map;
105 };
106 
107 template <typename MapType, typename T>
108 typename EnableIf<!cohtml::PointerTrait<T>::Value, void*>::Type CoherentMapNativeElementReader(void* data, char const* name)
109 {
110  return &(*(MapType*)data)[name];
111 }
112 
113 template <typename MapType, typename T>
114 typename EnableIf<cohtml::PointerTrait<T>::Value, void*>::Type CoherentMapNativeElementReader(void* data, char const* name)
115 {
116  return UnwrapPointer<T>::Unwrap(&(*(MapType*)data)[name]);
117 }
118 
119 template <typename Key, typename Value, typename Comparator, typename Allocator>
120 struct IsMap<std::map<Key, Value, Comparator, Allocator>> : TrueType
121 {
122 };
123 
124 template <typename Key, typename Value, typename Comparator, typename Allocator>
125 inline bool GetMapValueInvoke(Binder* binder, MapInfo* mapInfo, std::map<Key, Value, Comparator, Allocator>* pMap)
126 {
127  if (!pMap)
128  {
129  return false;
130  }
131  typedef std::map<Key, Value, Comparator, Allocator> MapType;
132  *mapInfo = MapInfo{
134  cohtml::CoherentMapNativeElementReader<MapType, Value>,
136  pMap
137  };
138  return true;
139 }
140 
141 }
virtual void ReadKeyValuePair()=0
Read next key-value pair from a map.
void CoherentReadInternal(Binder *binder, ArrayType(&array)[ArraySize])
Definition: Array.h:118
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 map of a type exposed to the scripting.
Definition: Property.h:338
ElementType
Definition: Property.h:299
EnableIf<!cohtml::PointerTrait< T >::Value, void * >::Type CoherentMapNativeElementReader(void *data, char const *name)
Definition: Map.h:108
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.
ValueType
The primitive types coming from JS.
Definition: Binder.h:43
Provides binding between C++ and the UI.
Definition: Binder.h:138
virtual void ReadMapEnd()=0
End reading a map.
Definition: TypeTraits.h:46
bool GetMapValueInvoke(Binder *binder, MapInfo *mapInfo, std::map< Key, Value, Comparator, Allocator > *pMap)
Definition: Map.h:125
Definition: Property.h:580
Definition: TypeTraits.h:385
static const ElementType value
Definition: Property.h:613
static TypeInfo * Get(Binder *binder)
Definition: Property.h:730
Definition: MapCommon.h:41