2380347e0a9cc7e70c6be684af8b3728a74a83d6
[platform/core/uifw/dali-adaptor.git] / adaptors / emscripten / wrappers / type-info-wrapper.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include "type-info-wrapper.h"
19
20 // EXTERNAL INCLUDES
21
22 // INTERNAL INCLUDES
23 #include "property-value-wrapper.h"
24
25 namespace Dali
26 {
27 namespace Internal
28 {
29 namespace Emscripten
30 {
31
32 std::vector<std::string> GetAllProperties(Dali::TypeInfo self)
33 {
34   std::vector<std::string> names;
35
36   // get the other properties
37   if(Dali::Handle handle = Dali::Handle::DownCast( self.CreateInstance() ) )
38   {
39     typedef Dali::Property::IndexContainer IndexContainer;
40
41     Dali::Property::IndexContainer indices;
42     handle.GetPropertyIndices( indices );
43
44     for(IndexContainer::Iterator iter(indices.Begin()); iter != indices.End(); ++iter)
45     {
46       std::string name = handle.GetPropertyName( *iter );
47
48       names.push_back(name);
49     }
50   }
51   else
52   {
53     // all we can do is get the event side properties
54     // get the event side properties
55     Property::IndexContainer indices;
56     self.GetPropertyIndices( indices );
57     for(Property::IndexContainer::Iterator iter(indices.Begin()); iter != indices.End(); ++iter)
58     {
59       std::string name = self.GetPropertyName( *iter );
60       names.push_back(name);
61     }
62   }
63
64   return names;
65 }
66
67 std::vector<int> GetPropertyIndices(Dali::TypeInfo& self)
68 {
69   Dali::Property::IndexContainer indices;
70   self.GetPropertyIndices( indices );
71
72   std::vector<int> ret( indices.Begin(), indices.End() );
73   return ret;
74 }
75
76 std::vector<std::string> GetActions(Dali::TypeInfo& self)
77 {
78   std::vector<std::string> names;
79   std::size_t size = self.GetActionCount();
80   for(std::size_t i = 0; i < size; i++)
81   {
82     names.push_back(self.GetActionName(i));
83   }
84   return names;
85 }
86
87 std::vector<std::string> GetSignals(Dali::TypeInfo& self)
88 {
89   std::vector<std::string> names;
90   std::size_t size = self.GetSignalCount();
91   for(std::size_t i = 0; i < size; i++)
92   {
93     names.push_back(self.GetSignalName(i));
94   }
95   return names;
96 }
97
98 std::vector<std::string> GetBases(Dali::TypeInfo& self)
99 {
100   std::vector<std::string> names;
101
102   Dali::TypeRegistry registry = Dali::TypeRegistry::Get();
103
104   Dali::TypeInfo base = registry.GetTypeInfo( self.GetBaseName() );
105
106   while(base)
107   {
108     base = registry.GetTypeInfo( base.GetBaseName() );
109     names.push_back(base.GetName());
110   }
111
112   return names;
113 }
114
115 }; // namespace Emscripten
116 }; // namespace Internal
117 }; // namespace Dali