Remove BaseHandle / BaseObject TypeTraits is trivialgit
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / spannable / spannable-string-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_SPANNABLE_STRING_IMPL_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_SPANNABLE_STRING_IMPL_H
3
4 /*
5  * Copyright (c) 2024 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali-toolkit/devel-api/text/spannable-string.h>
23 #include <memory>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/internal/text/spannable/span-ranges-container-impl.h>
27 #include <dali-toolkit/internal/text/spannable/spannable-impl.h>
28
29 namespace Dali
30 {
31 namespace Toolkit
32 {
33 namespace Text
34 {
35 namespace Internal
36 {
37 class SpannableString;
38
39 typedef IntrusivePtr<SpannableString> SpannableStringPtr;
40 typedef const SpannableString*        SpannableStringConstPtr;
41
42 /**
43  * @copydoc Dali::Toolkit::Text::SpannableString
44  */
45 class SpannableString : public Spannable
46 {
47 public:
48   /**
49    * @brief Creates a new SpannableString.
50    *
51    * @return A public handle to the newly allocated SpannableString.
52    */
53   static Dali::Toolkit::Text::SpannableString New(const std::string& text);
54
55   /**
56    * @brief Destructor
57    *
58    * A reference counted object may only be deleted by calling Unreference()
59    */
60   ~SpannableString() override;
61
62 protected:
63   /**
64    * @brief Constructs a new SpannableString.
65    */
66   SpannableString(const std::string& text);
67
68   // Removed constructors and assignment operators
69 public:
70   SpannableString(const SpannableString&) = delete;            ///< Deleted copy constructor
71   SpannableString(SpannableString&&)      = delete;            ///< Deleted move constructor
72   SpannableString& operator=(const SpannableString&) = delete; ///< Deleted copy assignment operator
73   SpannableString& operator=(SpannableString&&) = delete;      ///< Deleted move assignment operator
74
75 public:
76   //Methods from CharacterSequence
77   /**
78    * @copydoc Dali::Toolkit::Text::CharacterSequence::GetCharacters()
79    */
80   Vector<uint32_t> GetCharacters() const override;
81
82   /**
83    * @copydoc Dali::Toolkit::Text::CharacterSequence::GetNumberOfCharacters()
84    */
85   uint32_t GetNumberOfCharacters() const override;
86
87   /**
88    * @copydoc Dali::Toolkit::Text::CharacterSequence::ToString()
89    */
90   std::string ToString() const override;
91
92   //Methods from Spannable
93   /**
94    * @copydoc Dali::Toolkit::Text::Spannable::AttachSpan()
95    */
96   bool AttachSpan(const Dali::Toolkit::Text::BaseSpan& styleSpan, const Dali::Toolkit::Text::Range& range);
97
98   /**
99    * @copydoc Dali::Toolkit::Text::Spannable::DetachSpan()
100    */
101   bool DetachSpan(const Dali::Toolkit::Text::BaseSpan& styleSpan);
102
103   //Methods from Spanned
104   /**
105    * @copydoc Dali::Toolkit::Text::Spanned::GetAllSpans()
106    */
107   std::vector<Dali::Toolkit::Text::BaseSpan> GetAllSpans() const;
108
109   /**
110    * @copydoc Dali::Toolkit::Text::Spanned::RetrieveAllSpansAndRanges()
111    */
112   void RetrieveAllSpansAndRanges(std::vector<Dali::Toolkit::Text::BaseSpan>& spans, std::vector<Dali::Toolkit::Text::Range>& ranges) const;
113
114 private:
115   struct Impl;
116   std::unique_ptr<Impl> mImpl{nullptr};
117
118 }; // class SpannableString
119
120 } // namespace Internal
121
122 /**
123  * Helper methods for public API.
124  */
125 inline Internal::SpannableString& GetImplementation(Dali::Toolkit::Text::SpannableString& spannableString)
126 {
127   DALI_ASSERT_ALWAYS(spannableString && "spannableString handle is empty");
128
129   BaseObject& handle = spannableString.GetBaseObject();
130
131   return static_cast<Internal::SpannableString&>(handle);
132 }
133
134 inline const Internal::SpannableString& GetImplementation(const Dali::Toolkit::Text::SpannableString& spannableString)
135 {
136   DALI_ASSERT_ALWAYS(spannableString && "spannableString handle is empty");
137
138   const BaseObject& handle = spannableString.GetBaseObject();
139
140   return static_cast<const Internal::SpannableString&>(handle);
141 }
142
143 } // namespace Text
144
145 } // namespace Toolkit
146
147 } // namespace Dali
148
149 #endif // DALI_TOOLKIT_INTERNAL_TEXT_SPANNABLE_STRING_IMPL_H