Dali 3D User Interface Engine
toolkit-singleton-service.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 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 
19 
24 
25 namespace Dali
26 {
27 
28 
29 namespace Internal
30 {
31 namespace Adaptor
32 {
33 
37 class SingletonService : public Dali::BaseObject
38 {
39 public:
40  static Dali::SingletonService New();
41  static Dali::SingletonService Get();
42  void Register( const std::type_info& info, BaseHandle singleton );
43  void UnregisterAll();
44  BaseHandle GetSingleton( const std::type_info& info ) const;
45 
46 private:
48  virtual ~SingletonService();
49 
50  // Undefined
53 
54 private:
55 
56  typedef std::pair<std::string, BaseHandle> SingletonPair;
57  typedef std::map<std::string, BaseHandle> SingletonContainer;
58  typedef SingletonContainer::const_iterator SingletonConstIter;
59 
61 
63 };
64 
66 
68 {
69  return Get();
70 }
71 
73 {
75  {
77  }
79 }
80 
81 void SingletonService::Register( const std::type_info& info, BaseHandle singleton )
82 {
83  if( singleton )
84  {
85  mSingletonContainer.insert( SingletonPair( info.name(), singleton ) );
86  }
87 }
88 
90 {
91  mSingletonContainer.clear();
92 }
93 
94 BaseHandle SingletonService::GetSingleton( const std::type_info& info ) const
95 {
96  BaseHandle object;
97 
98  SingletonConstIter iter = mSingletonContainer.find(info.name());
99  if( iter != mSingletonContainer.end() )
100  {
101  object = ( *iter ).second;
102  }
103 
104  return object;
105 }
106 
108 : mSingletonContainer()
109 {
110 }
111 
113 {
114 }
115 
116 } // namespace Adaptor
117 } // namespace Internal
118 
120 
121 Internal::Adaptor::SingletonService& GetImplementation(Dali::SingletonService& player)
122 {
123  DALI_ASSERT_ALWAYS( player && "SingletonService handle is empty" );
124 
125  BaseObject& handle = player.GetBaseObject();
126 
127  return static_cast<Internal::Adaptor::SingletonService&>(handle);
128 }
129 
130 const Internal::Adaptor::SingletonService& GetImplementation(const Dali::SingletonService& player)
131 {
132  DALI_ASSERT_ALWAYS( player && "SingletonService handle is empty" );
133 
134  const BaseObject& handle = player.GetBaseObject();
135 
136  return static_cast<const Internal::Adaptor::SingletonService&>(handle);
137 }
138 
140 {
141 }
142 
144 {
146 }
147 
149 {
151 }
152 
154 {
155 }
156 
157 void SingletonService::Register( const std::type_info& info, BaseHandle singleton )
158 {
159  GetImplementation( *this ).Register( info, singleton );
160 }
161 
163 {
164  GetImplementation( *this ).UnregisterAll();
165 }
166 
167 BaseHandle SingletonService::GetSingleton( const std::type_info& info ) const
168 {
169  return GetImplementation( *this ).GetSingleton( info );
170 }
171 
173 : BaseHandle( singletonService )
174 {
175 }
176 
177 } // namespace Dali
Dali Docs Home
Read more about Dali