2 * Copyright (c) 2014 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.
19 #include <dali/internal/event/resources/resource-type-path.h>
21 using namespace Dali::Integration;
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
38 int ResourceTypeCompare(const ResourceType& lhs, const ResourceType& rhs)
44 result = lhs.id > rhs.id ? 1 : -1;
46 else // lhs.id == rhs.id
48 // Cast to a derived resource type and compare...
54 // compare bitmap widths & heights
55 const BitmapResourceType& lhsBitmap = static_cast<const BitmapResourceType&>(lhs);
56 const BitmapResourceType& rhsBitmap = static_cast<const BitmapResourceType&>(rhs);
58 if (lhsBitmap.imageAttributes != rhsBitmap.imageAttributes)
60 result = lhsBitmap.imageAttributes < rhsBitmap.imageAttributes ? -1 : 1;
66 case ResourceNativeImage:
68 // compare native image widths & heights
70 const NativeImageResourceType& lhsNativeImage = static_cast<const NativeImageResourceType&>(lhs);
71 const NativeImageResourceType& rhsNativeImage = static_cast<const NativeImageResourceType&>(rhs);
73 if (lhsNativeImage.imageAttributes != rhsNativeImage.imageAttributes)
75 result = lhsNativeImage.imageAttributes < rhsNativeImage.imageAttributes ? -1 : 1;
81 case ResourceTargetImage:
83 // compare bitmap widths & heights
84 const RenderTargetResourceType& lhsImage = static_cast<const RenderTargetResourceType&>(lhs);
85 const RenderTargetResourceType& rhsImage = static_cast<const RenderTargetResourceType&>(rhs);
87 if (lhsImage.imageAttributes != rhsImage.imageAttributes)
89 result = lhsImage.imageAttributes < rhsImage.imageAttributes ? -1 : 1;
97 // compare shader source hashes
98 const ShaderResourceType& lhsShader = static_cast<const ShaderResourceType&>(lhs);
99 const ShaderResourceType& rhsShader = static_cast<const ShaderResourceType&>(rhs);
101 if (lhsShader.hash != rhsShader.hash)
103 result = lhsShader.hash < rhsShader.hash ? -1 : 1;
116 // compare text requests
117 const TextResourceType& lhsText = static_cast<const TextResourceType&>(lhs);
118 const TextResourceType& rhsText = static_cast<const TextResourceType&>(rhs);
120 if( lhsText.mStyle != rhsText.mStyle )
122 result = lhsText.mStyle < rhsText.mStyle ? -1 : 1;
124 else if (lhsText.mCharacterList.size() != rhsText.mCharacterList.size())
126 result = lhsText.mCharacterList.size() < rhsText.mCharacterList.size() ? -1 : 1;
128 else if (!std::equal(lhsText.mCharacterList.begin(), lhsText.mCharacterList.end(), rhsText.mCharacterList.begin()))
130 for (unsigned int i = 0; i < lhsText.mCharacterList.size(); ++i)
132 if (lhsText.mCharacterList[i].character != rhsText.mCharacterList[i].character)
134 result = lhsText.mCharacterList[i].character <= rhsText.mCharacterList[i].character ? -1 : 1;
139 else if (lhsText.mFontHash != rhsText.mFontHash)
141 result = lhsText.mFontHash < rhsText.mFontHash ? -1 : 1;
143 else if (lhsText.mQuality != rhsText.mQuality)
145 result = lhsText.mQuality < rhsText.mQuality ? -1 : 1;
161 bool ResourceTypePath::operator<(const ResourceTypePath& rhs) const
163 int typeComparison = ResourceTypeCompare(*type, *(rhs.type));
165 if (typeComparison != 0)
167 return (typeComparison < 0);
171 return path < rhs.path;
175 } // namespace Internal