Tizen 2.1 base
[framework/osp/uifw.git] / src / graphics / util / FGrp_UtilType.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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  * @file        FGrp_UtilType.h
20  * @brief       This is the header file for internal _Util namespace.
21  *
22  */
23
24 #ifndef _FGRP_INTERNAL_UTIL_TYPE_H_
25 #define _FGRP_INTERNAL_UTIL_TYPE_H_
26
27
28 namespace Tizen { namespace Graphics
29 {
30
31 namespace _Util
32 {
33
34 template <typename T>
35 struct Point
36 {
37         T x;
38         T y;
39 };
40
41 template <typename T>
42 struct Dimension
43 {
44         T w;
45         T h;
46 };
47
48 template <typename T>
49 struct Rectangle
50 {
51         T x;
52         T y;
53         T w;
54         T h;
55 };
56
57 template <typename T>
58 inline bool
59 operator ==(const Rectangle<T>& lhs, const Rectangle<T>& rhs)
60 {
61         return (lhs.x == rhs.x) && (lhs.y == rhs.y) && (lhs.w == rhs.w) && (lhs.h == rhs.h);
62 }
63
64 template <typename T>
65 inline bool
66 operator !=(const Rectangle<T>& lhs, const Rectangle<T>& rhs)
67 {
68         return !(operator ==(lhs, rhs));
69 }
70
71 template <typename T>
72 struct Bounds
73 {
74         T x1;
75         T y1;
76         T x2;
77         T y2;
78
79         bool IsInside(T x, T y)
80         {
81                 return ((x >= x1) && (x < x2) && (y >= y1) && (y < y2));
82         }
83
84         bool IsInsideX(T x)
85         {
86                 return ((x >= x1) && (x < x2));
87         }
88 };
89
90 ////////////////////////////////////////////////////////////////////////////////
91 // String
92
93 struct String
94 {
95         const wchar_t* pStart;
96         int length;
97
98         String(void)
99                 : pStart(L"")
100                 , length(0)
101         {
102         }
103
104         String(const wchar_t* pInputString, int inputStringLength)
105                 : pStart(pInputString)
106                 , length(inputStringLength)
107         {
108         }
109
110         String(const wchar_t* pInputString, int inputStringLength, int offset, int clippedLength)
111         {
112                 const wchar_t* pInputStart = pInputString;
113                 const wchar_t* pInputEnd = pInputStart + inputStringLength;
114
115                 const wchar_t* pRevisedStart = pInputString + offset;
116                 const wchar_t* pRevisedEnd = pRevisedStart + clippedLength;
117
118                 const wchar_t* pClippedStart = (pInputStart > pRevisedStart) ? pInputStart : pRevisedStart;
119                 const wchar_t* pClippedEnd = (pInputEnd < pRevisedEnd) ? pInputEnd : pRevisedEnd;
120
121                 if (pClippedEnd - pClippedStart > 0)
122                 {
123                         this->pStart = pClippedStart;
124                         this->length = pClippedEnd - pClippedStart;
125                 }
126                 else
127                 {
128                         this->pStart = L"";
129                         this->length = 0;
130                 }
131         }
132
133         operator const wchar_t*(void)
134         {
135                 return pStart;
136         }
137 };
138
139 } // Tizen::Graphics::_Util
140
141 }} // Tizen::Graphics
142
143 #endif // _FGRP_INTERNAL_UTIL_TYPE_H_