Fix coverity issue (copy data during iteration)
[platform/core/uifw/dali-adaptor.git] / dali / internal / text-clipboard / common / text-clipboard-event-notifier-impl.cpp
1 /*
2  * Copyright (c) 2023 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/text-clipboard/common/text-clipboard-event-notifier-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/common/singleton-service.h>
23 #include <dali/public-api/object/type-registry.h>
24
25 namespace Dali
26 {
27 namespace Internal
28 {
29 namespace Adaptor
30 {
31 Dali::TextClipboardEventNotifier TextClipboardEventNotifier::New()
32 {
33   Dali::TextClipboardEventNotifier notifier = Dali::TextClipboardEventNotifier(new TextClipboardEventNotifier());
34
35   return notifier;
36 }
37
38 Dali::TextClipboardEventNotifier TextClipboardEventNotifier::Get()
39 {
40   Dali::TextClipboardEventNotifier notifier;
41
42   Dali::SingletonService service(SingletonService::Get());
43   if(service)
44   {
45     // Check whether the singleton is already created
46     Dali::BaseHandle handle = service.GetSingleton(typeid(Dali::TextClipboardEventNotifier));
47     if(handle)
48     {
49       // If so, downcast the handle
50       notifier = Dali::TextClipboardEventNotifier(dynamic_cast<TextClipboardEventNotifier*>(handle.GetObjectPtr()));
51     }
52     else
53     {
54       notifier = Dali::TextClipboardEventNotifier(TextClipboardEventNotifier::New());
55       service.Register(typeid(notifier), notifier);
56     }
57   }
58
59   return notifier;
60 }
61
62 const std::string& TextClipboardEventNotifier::GetContent() const
63 {
64   return mContent;
65 }
66
67 void TextClipboardEventNotifier::SetContent(const std::string& content)
68 {
69   mContent = content;
70 }
71
72 void TextClipboardEventNotifier::ClearContent()
73 {
74   mContent.clear();
75 }
76
77 void TextClipboardEventNotifier::EmitContentSelectedSignal()
78 {
79   if(!mContentSelectedSignal.Empty())
80   {
81     Dali::TextClipboardEventNotifier handle(this);
82     mContentSelectedSignal.Emit(handle);
83   }
84 }
85
86 TextClipboardEventNotifier::TextClipboardEventNotifier()
87 : mContent()
88 {
89 }
90
91 TextClipboardEventNotifier::~TextClipboardEventNotifier()
92 {
93 }
94
95 } // namespace Adaptor
96
97 } // namespace Internal
98
99 } // namespace Dali