2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef HERE_GRAPHIC_UTILTYPE_H
18 #define HERE_GRAPHIC_UTILTYPE_H
20 #include "common/HereMaps_global.h"
22 TIZEN_MAPS_BEGIN_NAMESPACE
27 template <unsigned int preFixed, unsigned int postFixed>
35 FixedPoint(const FixedPoint& rhs)
36 : __fixedPoint(rhs.__fixedPoint)
40 explicit FixedPoint(int value)
41 : __fixedPoint(value << SHIFT)
45 explicit FixedPoint(long value)
46 : __fixedPoint(value << SHIFT)
50 explicit FixedPoint(float value)
51 : __fixedPoint(value * ((1 << SHIFT) * 1.0f))
55 explicit FixedPoint(double value)
56 : __fixedPoint(value * ((1 << SHIFT) * 1.0))
63 return (__fixedPoint >> SHIFT);
69 return (__fixedPoint / ((1 << SHIFT) * 1.0f));
75 return (__fixedPoint / ((1 << SHIFT) * 1.0));
79 Reset(int fixedPointValue)
81 __fixedPoint = fixedPointValue;
84 inline operator const int(void)
91 operator +(const FixedPoint& rhs) const
93 FixedPoint<preFixed, SHIFT> tempFixed(0);
95 tempFixed.__fixedPoint = __fixedPoint + rhs.__fixedPoint;
102 operator -(const FixedPoint& rhs) const
104 FixedPoint<preFixed, SHIFT> tempFixed(0);
106 tempFixed.__fixedPoint = __fixedPoint - rhs.__fixedPoint;
112 template <typename T>
114 operator ==(const T& rhs) const
116 return (ToFloat() == rhs);
120 operator ==(const FixedPoint& rhs) const
122 return (ToFloat() == rhs.ToFloat);
126 template <typename T>
128 operator !=(const T& rhs) const
130 return (ToFloat() != rhs);
134 operator !=(const FixedPoint& rhs) const
136 return (ToFloat() != rhs.ToFloat());
140 template <typename T>
142 operator <=(const T& rhs) const
144 return (ToFloat() <= rhs);
148 operator <=(const FixedPoint& rhs) const
150 return (ToFloat() <= rhs.ToFloat());
154 template <typename T>
156 operator >=(const T& rhs) const
158 return (ToFloat() >= rhs);
162 operator >=(const FixedPoint& rhs) const
164 return (ToFloat() >= rhs.ToFloat());
168 template <typename T>
170 operator >(const T& rhs) const
172 return (ToFloat() > rhs);
176 operator >(const FixedPoint& rhs) const
178 return (ToFloat() > rhs.ToFloat());
182 template <typename T>
184 operator <(const T& rhs) const
186 return (ToFloat() < rhs);
190 operator <(const FixedPoint& rhs) const
192 return (ToFloat() < rhs.ToFloat());
196 enum { SHIFT = postFixed };
199 typedef FixedPoint<26, 6> FixedPoint26_6;
200 typedef FixedPoint<22, 10> FixedPoint22_10;
203 template <typename T>
210 template <typename T>
217 template <typename T>
226 template <typename T>
228 operator ==(const Rectangle<T>& lhs, const Rectangle<T>& rhs)
230 return (lhs.x == rhs.x) && (lhs.y == rhs.y) && (lhs.w == rhs.w) && (lhs.h == rhs.h);
233 template <typename T>
235 operator !=(const Rectangle<T>& lhs, const Rectangle<T>& rhs)
237 return !(operator ==(lhs, rhs));
240 template <typename T>
248 bool IsInside(T x, T y)
250 return ((x >= x1) && (x < x2) && (y >= y1) && (y < y2));
255 return ((x >= x1) && (x < x2));
259 ////////////////////////////////////////////////////////////////////////////////
264 const wchar_t* pStart;
273 String(const wchar_t* pInputString, int inputStringLength)
274 : pStart(pInputString)
275 , length(inputStringLength)
279 String(const wchar_t* pInputString, int inputStringLength, int offset, int clippedLength)
281 const wchar_t* pInputStart = pInputString;
282 const wchar_t* pInputEnd = pInputStart + inputStringLength;
284 const wchar_t* pRevisedStart = pInputString + offset;
285 const wchar_t* pRevisedEnd = pRevisedStart + clippedLength;
287 const wchar_t* pClippedStart = (pInputStart > pRevisedStart) ? pInputStart : pRevisedStart;
288 const wchar_t* pClippedEnd = (pInputEnd < pRevisedEnd) ? pInputEnd : pRevisedEnd;
290 if (pClippedEnd - pClippedStart > 0)
292 this->pStart = pClippedStart;
293 this->length = pClippedEnd - pClippedStart;
297 this->pStart = (pClippedStart == pInputString) ? pClippedStart : L"";
302 operator const wchar_t*(void)
308 typedef std::wstring WString;
312 TIZEN_MAPS_END_NAMESPACE
314 #endif /* HERE_GRAPHIC_UTILTYPE_H */