Merge "Dali-Text: Keyboard Shortcuts" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / image-loader / atlas-upload-observer.cpp
1 /*
2  * Copyright (c) 2020 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 "atlas-upload-observer.h"
20
21 // INTERNAL INCLUDES
22 #include <dali-toolkit/internal/image-loader/image-atlas-impl.h>
23
24 namespace Dali
25 {
26 namespace Toolkit
27 {
28 AtlasUploadObserver::AtlasUploadObserver()
29 {
30 }
31
32 AtlasUploadObserver::~AtlasUploadObserver()
33 {
34   // Notify the registerd ImageAtlas object about the destruction of observer.
35   const std::size_t size(mAtlasList.Count());
36   for(std::size_t i = 0; i < size; ++i)
37   {
38     if(mAtlasList[i])
39     {
40       mAtlasList[i]->ObserverDestroyed(this);
41     }
42   }
43   mAtlasList.Clear();
44 }
45
46 void AtlasUploadObserver::Register(Internal::ImageAtlas& imageAtlas)
47 {
48   // Add to the list so that the ImageAtlas could get notified in the destructor.
49   // If the same atlas is exist in the list already, we would still save the duplicated copy.
50   mAtlasList.PushBack(&imageAtlas);
51 }
52
53 void AtlasUploadObserver::Unregister(Internal::ImageAtlas& imageAtlas)
54 {
55   const std::size_t size(mAtlasList.Count());
56   for(std::size_t i = 0; i < size; i++)
57   {
58     if(mAtlasList[i] == &imageAtlas)
59     {
60       // Remove from list
61       mAtlasList.Erase(mAtlasList.Begin() + i);
62       // If there are duplicated copies of same pointer, only the first one is removed
63       return;
64     }
65   }
66 }
67
68 } // namespace Toolkit
69
70 } // namespace Dali