8b0f0d28f9ce5e92129a5ca3d744871cfbf09ef5
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / string-text / range-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_RANGE_IMPL_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_RANGE_IMPL_H
3
4 /*
5  * Copyright (c) 2022 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 <memory>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/devel-api/text/range.h>
26 #include <dali/public-api/object/base-object.h>
27
28 namespace Dali
29 {
30 namespace Toolkit
31 {
32 namespace Text
33 {
34 namespace Internal
35 {
36 class Range;
37
38 typedef IntrusivePtr<Range> RangePtr;
39
40 /**
41  * @copydoc Dali::Toolkit::Text::Range
42  */
43 class Range : public BaseObject
44 {
45 public:
46   /**
47    * @brief Creates a new Range.
48    *
49    * @param[in] startIndex the start index of range (included)
50    * @param[in] endIndex the end index of range (included)
51    *
52    * @return A public handle to the newly allocated Range.
53    */
54   static Dali::Toolkit::Text::Range New(u_int32_t startIndex, u_int32_t endIndex);
55
56   /**
57    * @brief Destructor
58    *
59    * A reference counted object may only be deleted by calling Unreference()
60    */
61   ~Range();
62
63 protected:
64   /**
65    * @brief Constructs a new Range.
66    *
67    * @param[in] startIndex the start index of range (included)
68    * @param[in] endIndex the end index of range (included)
69    *
70    */
71   Range(u_int32_t startIndex, u_int32_t endIndex);
72
73 public: //Methods
74   /**
75    * @copydoc Dali::Toolkit::Text::Range::GetStartIndex()
76    */
77   u_int32_t GetStartIndex() const;
78
79   /**
80    * @copydoc Dali::Toolkit::Text::Range::GetEndIndex()
81    */
82   u_int32_t GetEndIndex() const;
83
84   /**
85    * @copydoc Dali::Toolkit::Text::Range::GetNumberOfIndices()
86    */
87   u_int32_t GetNumberOfIndices() const;
88
89 public:
90   Range(const Range&) = delete;            ///< Deleted copy constructor
91   Range(Range&&)      = delete;            ///< Deleted move constructor
92   Range& operator=(const Range&) = delete; ///< Deleted copy assignment operator
93   Range& operator=(Range&&) = delete;      ///< Deleted move assignment operator
94
95 private:
96   // Data
97   struct Impl;
98   std::unique_ptr<Impl> mImpl{nullptr};
99
100 }; // class Range
101
102 } // namespace Internal
103
104 /**
105  * Helper methods for public API.
106  */
107 inline Internal::Range& GetImplementation(Dali::Toolkit::Text::Range& range)
108 {
109   DALI_ASSERT_ALWAYS(range && "range handle is empty");
110
111   BaseObject& handle = range.GetBaseObject();
112
113   return static_cast<Internal::Range&>(handle);
114 }
115
116 inline const Internal::Range& GetImplementation(const Dali::Toolkit::Text::Range& range)
117 {
118   DALI_ASSERT_ALWAYS(range && "range handle is empty");
119
120   const BaseObject& handle = range.GetBaseObject();
121
122   return static_cast<const Internal::Range&>(handle);
123 }
124
125 } // namespace Text
126
127 } // namespace Toolkit
128
129 // Allow Range to be treated as a POD type
130 template<>
131 struct TypeTraits<Dali::Toolkit::Text::Internal::Range> : public Dali::BasicTypes<Dali::Toolkit::Text::Internal::Range>
132 {
133   enum
134   {
135     IS_TRIVIAL_TYPE = true
136   };
137 };
138
139 } // namespace Dali
140
141 #endif // DALI_TOOLKIT_INTERNAL_TEXT_RANGE_IMPL_H