1.7.2.9
Prysm
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 Key, typename Value, typename Comparator, typename Allocator>
108 struct IsMap<std::map<Key, Value, Comparator, Allocator>> : TrueType
109 {
110 };
111 
112 template <typename Key, typename Value, typename Comparator, typename Allocator>
113 inline bool GetMapValueInvoke(Binder* binder, MapInfo* mapInfo, std::map<Key, Value, Comparator, Allocator>* pMap)
114 {
115  if (!pMap)
116  {
117  return false;
118  }
119  typedef std::map<Key, Value, Comparator, Allocator> MapType;
120  *mapInfo = MapInfo{
122  cohtml::CoherentMapNativeElementReader<MapType, Value>,
124  pMap
125  };
126  return true;
127 }
128 
129 }
virtual void ReadKeyValuePair()=0
Read next key-value pair from a map.
EnableIf<!IsChar< ArrayType >::Value||IsSame< ArrayType, unsigned char >::Value >::Type CoherentBindInternal(Binder *binder, ArrayType(&array)[ArraySize])
Definition: Array.h:83
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:375
ElementType
Definition: Property.h:336
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:113
Definition: Property.h:617
EnableIf<!IsChar< ArrayType >::Value||IsSame< ArrayType, unsigned char >::Value >::Type CoherentReadInternal(Binder *binder, ArrayType(&array)[ArraySize])
Definition: Array.h:108
static const ElementType value
Definition: Property.h:650
static TypeInfo * Get(Binder *binder)
Definition: Property.h:767
Definition: MapCommon.h:41