Use OrderedSet so remove useless iteration for some singletone
[platform/core/uifw/dali-core.git] / dali / internal / event / common / property-notification-manager.cpp
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
18 // CLASS HEADER
19 #include <dali/internal/event/common/property-notification-manager.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/common/message.h>
23 #include <dali/internal/event/common/property-notification-impl.h>
24
25 namespace Dali
26 {
27 namespace Internal
28 {
29 PropertyNotificationManager* PropertyNotificationManager::New()
30 {
31   return new PropertyNotificationManager;
32 }
33
34 PropertyNotificationManager::~PropertyNotificationManager() = default;
35
36 void PropertyNotificationManager::PropertyNotificationCreated(PropertyNotification& propertyNotification)
37 {
38   mPropertyNotifications.PushBack(&propertyNotification);
39 }
40
41 void PropertyNotificationManager::PropertyNotificationDestroyed(PropertyNotification& propertyNotification)
42 {
43   auto iter = mPropertyNotifications.Find(&propertyNotification);
44   DALI_ASSERT_ALWAYS(iter != mPropertyNotifications.End() && "PropertyNotification not found");
45
46   mPropertyNotifications.Erase(iter);
47 }
48
49 void PropertyNotificationManager::PropertyNotificationSceneObjectMapping(const SceneGraph::PropertyNotification* sceneGraphPropertyNotification, PropertyNotification& propertyNotification)
50 {
51   mSceneGraphObjectMap.insert({sceneGraphPropertyNotification, &propertyNotification});
52 }
53
54 void PropertyNotificationManager::PropertyNotificationSceneObjectUnmapping(const SceneGraph::PropertyNotification* sceneGraphPropertyNotification)
55 {
56   auto iter = mSceneGraphObjectMap.find(sceneGraphPropertyNotification);
57   DALI_ASSERT_DEBUG(iter != mSceneGraphObjectMap.end());
58
59   mSceneGraphObjectMap.erase(iter);
60 }
61
62 void PropertyNotificationManager::NotifyProperty(SceneGraph::PropertyNotification* sceneGraphPropertyNotification, bool validity)
63 {
64   const auto iter = mSceneGraphObjectMap.find(sceneGraphPropertyNotification);
65   if(iter != mSceneGraphObjectMap.end())
66   {
67     // Check if this notification hold inputed scenegraph property notification.
68     auto* propertyNotification = iter->second;
69     if(propertyNotification->CompareSceneObject(sceneGraphPropertyNotification))
70     {
71       // allow application to access the value that triggered this emit incase of NOTIFY_ON_CHANGED mode
72       propertyNotification->SetNotifyResult(validity);
73       // yes..emit signal
74       propertyNotification->EmitSignalNotify();
75     }
76   }
77 }
78
79 PropertyNotificationManager::PropertyNotificationManager() = default;
80
81 } // namespace Internal
82
83 } // namespace Dali