DALi Version 2.2.11
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / spannable / span-ranges-container-impl.cpp
1
2 /*
3  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18
19 // EXTERNAL INCLUDES
20 #include <dali-toolkit/internal/text/spannable/span-ranges-container-impl.h>
21 #include <map>
22
23 namespace Dali
24 {
25 namespace Toolkit
26 {
27 namespace Text
28 {
29 namespace Internal
30 {
31 struct SpanRangesContainer::Impl
32 {
33   std::map<Dali::Toolkit::Text::BaseSpan, Dali::Toolkit::Text::Range> mSpanWithRanges; ///< The list of style-span
34 };
35
36 SpanRangesContainer::SpanRangesContainer()
37 {
38   mImpl = std::make_unique<Impl>();
39 }
40
41 SpanRangesContainer::~SpanRangesContainer()
42 {
43 }
44
45 void SpanRangesContainer::AddSpan(const Dali::Toolkit::Text::BaseSpan& span, const Dali::Toolkit::Text::Range& range)
46 {
47   mImpl->mSpanWithRanges.insert(std::make_pair(span, range));
48 }
49
50 void SpanRangesContainer::RemoveSpan(const Dali::Toolkit::Text::BaseSpan& span)
51 {
52   mImpl->mSpanWithRanges.erase(span);
53 }
54
55 bool SpanRangesContainer::Contains(const Dali::Toolkit::Text::BaseSpan& span) const
56 {
57   std::map<Dali::Toolkit::Text::BaseSpan, Dali::Toolkit::Text::Range>::iterator it = mImpl->mSpanWithRanges.find(span);
58
59   return it != mImpl->mSpanWithRanges.end();
60 }
61
62 void SpanRangesContainer::GetSpans(std::vector<Dali::Toolkit::Text::BaseSpan>& listOfSpans) const
63 {
64   for(std::map<Dali::Toolkit::Text::BaseSpan, Dali::Toolkit::Text::Range>::iterator it = mImpl->mSpanWithRanges.begin();
65       it != mImpl->mSpanWithRanges.end();
66       ++it)
67   {
68     listOfSpans.push_back(it->first);
69   }
70 }
71
72 void SpanRangesContainer::GetSpansAndRanges(std::vector<Dali::Toolkit::Text::BaseSpan>& spans, std::vector<Dali::Toolkit::Text::Range>& ranges) const
73 {
74   for(std::map<Dali::Toolkit::Text::BaseSpan, Dali::Toolkit::Text::Range>::iterator it = mImpl->mSpanWithRanges.begin();
75       it != mImpl->mSpanWithRanges.end();
76       ++it)
77   {
78     spans.push_back(it->first);
79     ranges.push_back(it->second);
80   }
81 }
82 } // namespace Internal
83
84 } // namespace Text
85
86 } // namespace Toolkit
87
88 } // namespace Dali