License conversion from Flora to Apache 2.0
[platform/core/uifw/dali-core.git] / dali / internal / event / resources / resource-type-path.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/event/resources/resource-type-path.h>
20
21 using namespace Dali::Integration;
22
23 namespace Dali
24 {
25
26 namespace Internal
27 {
28
29 namespace
30 {
31
32 /**
33  * Compare two resource types.
34  * @return zero if the types are equal,
35  *         less than zero if lhs < rhs or
36  *         greater than zero if lhs > rhs
37  */
38 int ResourceTypeCompare(const ResourceType& lhs, const ResourceType& rhs)
39 {
40   int result = 0;
41
42   if (lhs.id != rhs.id)
43   {
44     result = lhs.id > rhs.id ? 1 : -1;
45   }
46   else // lhs.id == rhs.id
47   {
48     // Cast to a derived resource type and compare...
49
50     switch (lhs.id)
51     {
52       case ResourceBitmap:
53       {
54         // compare bitmap widths & heights
55         const BitmapResourceType& lhsBitmap = static_cast<const BitmapResourceType&>(lhs);
56         const BitmapResourceType& rhsBitmap = static_cast<const BitmapResourceType&>(rhs);
57
58         if (lhsBitmap.imageAttributes != rhsBitmap.imageAttributes)
59         {
60           result = lhsBitmap.imageAttributes < rhsBitmap.imageAttributes ? -1 : 1;
61         }
62         // else result = 0
63         break;
64       }
65
66       case ResourceNativeImage:
67       {
68         // compare native image widths & heights
69
70         const NativeImageResourceType& lhsNativeImage = static_cast<const NativeImageResourceType&>(lhs);
71         const NativeImageResourceType& rhsNativeImage = static_cast<const NativeImageResourceType&>(rhs);
72
73         if (lhsNativeImage.imageAttributes != rhsNativeImage.imageAttributes)
74         {
75           result = lhsNativeImage.imageAttributes < rhsNativeImage.imageAttributes ? -1 : 1;
76         }
77         // else result = 0
78         break;
79       }
80
81       case ResourceTargetImage:
82       {
83         // compare bitmap widths & heights
84         const RenderTargetResourceType& lhsImage = static_cast<const RenderTargetResourceType&>(lhs);
85         const RenderTargetResourceType& rhsImage = static_cast<const RenderTargetResourceType&>(rhs);
86
87         if (lhsImage.imageAttributes != rhsImage.imageAttributes)
88         {
89           result = lhsImage.imageAttributes < rhsImage.imageAttributes ? -1 : 1;
90         }
91         // else result = 0
92         break;
93       }
94
95       case ResourceShader:
96       {
97         // compare shader source hashes
98         const ShaderResourceType& lhsShader = static_cast<const ShaderResourceType&>(lhs);
99         const ShaderResourceType& rhsShader = static_cast<const ShaderResourceType&>(rhs);
100
101         if (lhsShader.hash != rhsShader.hash)
102         {
103           result = lhsShader.hash < rhsShader.hash ? -1 : 1;
104         }
105         // else result = 0
106         break;
107       }
108
109       case ResourceModel:
110       {
111         break; // result = 0
112       }
113
114       case ResourceText:
115       {
116         // compare text requests
117         const TextResourceType& lhsText = static_cast<const TextResourceType&>(lhs);
118         const TextResourceType& rhsText = static_cast<const TextResourceType&>(rhs);
119
120         if( lhsText.mStyle != rhsText.mStyle )
121         {
122           result = lhsText.mStyle < rhsText.mStyle ? -1 : 1;
123         }
124         else if (lhsText.mCharacterList.size() != rhsText.mCharacterList.size())
125         {
126           result = lhsText.mCharacterList.size() < rhsText.mCharacterList.size() ? -1 : 1;
127         }
128         else if (!std::equal(lhsText.mCharacterList.begin(), lhsText.mCharacterList.end(), rhsText.mCharacterList.begin()))
129         {
130           for (unsigned int i = 0; i < lhsText.mCharacterList.size(); ++i)
131           {
132             if (lhsText.mCharacterList[i].character != rhsText.mCharacterList[i].character)
133             {
134               result = lhsText.mCharacterList[i].character <= rhsText.mCharacterList[i].character ? -1 : 1;
135               break;
136             }
137           }
138         }
139         else if (lhsText.mFontHash != rhsText.mFontHash)
140         {
141           result = lhsText.mFontHash < rhsText.mFontHash ? -1 : 1;
142         }
143         else if (lhsText.mQuality != rhsText.mQuality)
144         {
145           result = lhsText.mQuality < rhsText.mQuality ? -1 : 1;
146         }
147         break;
148       }
149
150       case ResourceMesh:
151       {
152         break; // result = 0
153       }
154
155     }
156   }
157   return result;
158 }
159 }
160
161 bool ResourceTypePath::operator<(const ResourceTypePath& rhs) const
162 {
163   int typeComparison = ResourceTypeCompare(*type, *(rhs.type));
164
165   if (typeComparison != 0)
166   {
167     return (typeComparison < 0);
168   }
169   else
170   {
171     return path < rhs.path;
172   }
173 }
174
175 } // namespace Internal
176
177 } // namespace Dali