X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fbuilder%2Freplacement.cpp;h=49e73654548824791a32ea6fd8faa6a468cfc0dc;hp=657840fa911deed52796a4d310bcabca5c275343;hb=64cacc4d250a25eb19c27ed55741f3ae61266518;hpb=6bd46a2944d89638f1c1a1c609f72c9348db6abb diff --git a/dali-toolkit/internal/builder/replacement.cpp b/dali-toolkit/internal/builder/replacement.cpp index 657840f..49e7365 100644 --- a/dali-toolkit/internal/builder/replacement.cpp +++ b/dali-toolkit/internal/builder/replacement.cpp @@ -1,18 +1,19 @@ -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.0 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://floralicense.org/license/ -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an AS IS BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ // INTERNAL INCLUDES #include @@ -31,31 +32,16 @@ namespace Internal namespace // anon { -PropertyValueMap::const_iterator FindReplacement( const std::string &str, - const PropertyValueMap& overrideMap, const PropertyValueMap& defaultMap ) +Property::Value* FindReplacement( const std::string &str, const Property::Map& overrideMap, const Property::Map& defaultMap ) { - PropertyValueMap::const_iterator ret = defaultMap.end(); + Property::Value* ret = overrideMap.Find( str ); - PropertyValueMap::const_iterator iter = overrideMap.find( str ); - - if( iter != overrideMap.end() ) - { - ret = iter; - } - else + if ( !ret ) { - PropertyValueMap::const_iterator iter = defaultMap.find( str ); + ret = defaultMap.Find( str ); - if( iter != defaultMap.end() ) - { - ret = iter; - } - else - { - // @ todo - // try localized text ie dgettext. Look for colon {DOMAIN:TEXT} {LC_MESSAGE:ID_XXXX} - - } + // @ todo + // try localized text ie dgettext. Look for colon {DOMAIN:TEXT} {LC_MESSAGE:ID_XXXX} } return ret; @@ -113,7 +99,7 @@ bool GetSubstitutionPosition( const std::string &initialValue, std::size_t &star } bool ResolvePartialReplacement( const std::string &initialValue, Property::Value &out, - const PropertyValueMap& overrideMap, const PropertyValueMap& defaultMap ) + const Property::Map& overrideMap, const Property::Map& defaultMap ) { if( initialValue.size() >= 2 ) @@ -134,15 +120,15 @@ bool ResolvePartialReplacement( const std::string &initialValue, Property::Value { const std::string str( initialValue.substr( startPos, size ) ); - PropertyValueMap::const_iterator iter = FindReplacement( str, overrideMap, defaultMap ); + Property::Value* value = FindReplacement( str, overrideMap, defaultMap ); - if( iter == defaultMap.end() ) + if( !value ) { DALI_SCRIPT_WARNING( "Cannot find replacement for '%s'\n", str.c_str() ); } else { - if( Property::STRING != (*iter).second.GetType() ) + if( Property::STRING != value->GetType() ) { DALI_SCRIPT_WARNING( "Cannot replace substring in non string property type='%s'. Initial value '%s'\n", PropertyTypes::GetName( out.GetType() ), initialValue.c_str() ); @@ -151,7 +137,7 @@ bool ResolvePartialReplacement( const std::string &initialValue, Property::Value { std::string newString = \ initialValue.substr(0, startPos - 1) + - (*iter).second.Get() + + value->Get< std::string >() + initialValue.substr( startPos + size + 1 ); return ResolvePartialReplacement( newString, out, overrideMap, defaultMap ); @@ -167,7 +153,7 @@ bool ResolvePartialReplacement( const std::string &initialValue, Property::Value } // namespace anon -Replacement::Replacement( const PropertyValueMap& overrideMap, const PropertyValueMap& defaultMap ) +Replacement::Replacement( const Property::Map& overrideMap, const Property::Map& defaultMap ) : mOverrideMap( &overrideMap ), mDefaultMap( &defaultMap ) { @@ -175,10 +161,10 @@ Replacement::Replacement( const PropertyValueMap& overrideMap, const PropertyVal namespace { -PropertyValueMap noMap; +Property::Map noMap; } -Replacement::Replacement( const PropertyValueMap& defaultMap ) +Replacement::Replacement( const Property::Map& defaultMap ) : mOverrideMap( &noMap ), mDefaultMap( &defaultMap ) { @@ -194,7 +180,7 @@ OptionalString Replacement::HasFullReplacement( const TreeNode & node ) const { OptionalString ret; - if( node.HasSubstitution() && ((*mOverrideMap).size() || (*mDefaultMap).size()) ) + if( node.HasSubstitution() && ((*mOverrideMap).Count() || (*mDefaultMap).Count()) ) { OptionalString v = ::IsString( node ); if( v ) @@ -215,15 +201,15 @@ Property::Value Replacement::GetFullReplacement( const std::string& replacementS DALI_ASSERT_DEBUG( mOverrideMap && "missing map"); DALI_ASSERT_DEBUG( mDefaultMap && "missing map"); - PropertyValueMap::const_iterator iter = FindReplacement( replacementString, *mOverrideMap, *mDefaultMap ); + Property::Value* value = FindReplacement( replacementString, *mOverrideMap, *mDefaultMap ); - if( iter == (*mDefaultMap).end() ) + if( !value ) { DALI_SCRIPT_WARNING("Cannot find replacement for '%s'\n", replacementString.c_str()); } else { - out = (*iter).second; + out = *value; #if defined(DEBUG_ENABLED) DALI_SCRIPT_VERBOSE(" Full replacement for '%s' => to Type '%s'\n", replacementString.c_str(), @@ -264,45 +250,6 @@ OptionalBoolean Replacement::IsBoolean( OptionalChild child ) const } } -// template (*ISTYPE)( const TreeNode& node ), Property::Type TYPE> -// OptionalValue IsOfType( const TreeNode& node, const PropertyValueMap& overrideMap, const PropertyValueMap& defaultMap ) -// { -// OptionalValue ret; -// if( OptionalString replace = HasFullReplacement( node, overrideMap, defaultMap ) ) -// { -// Property::Value value = GetFullReplacement( *replace, overrideMap, defaultMap ); -// if( TYPE == value.GetType() ) -// { -// ret = value.Get(); -// } -// } -// else -// { -// ret = ISTYPE( node ); -// } -// return ret; - -// } - -// OptionalFloat Replacement::IsFloat( const TreeNode & node ) const -// { -// return IsOfType( node, *mOverrideMap, *mDefaultMap ); -// /* OptionalFloat ret; */ -// /* if( OptionalString replace = HasFullReplacement( node ) ) */ -// /* { */ -// /* Property::Value value = GetFullReplacement( replace ); */ -// /* if( Property::FLOAT == value.GetType() ) */ -// /* { */ -// /* ret = value.Get(); */ -// /* } */ -// /* } */ -// /* else */ -// /* { */ -// /* ret = IsFloat( node ); */ -// /* } */ -// /* return ret; */ -// } - OptionalFloat Replacement::IsFloat( const TreeNode & node ) const { OptionalFloat ret; @@ -328,7 +275,7 @@ OptionalString Replacement::IsString( const TreeNode& node ) const DALI_ASSERT_DEBUG( mOverrideMap && "missing map"); DALI_ASSERT_DEBUG( mDefaultMap && "missing map"); - if( node.HasSubstitution() && ((*mOverrideMap).size() || (*mDefaultMap).size()) ) + if( node.HasSubstitution() && ((*mOverrideMap).Count() || (*mDefaultMap).Count()) ) { if( OptionalString v = ::IsString( node ) ) { @@ -345,10 +292,7 @@ OptionalString Replacement::IsString( const TreeNode& node ) const } else { - if( Property::STRING == value.GetType() ) - { - ret = v; // sets the unexpanded. Expansion may occur later in processing with include files - } + ret = v; // sets the unexpanded. Expansion may occur later in processing with include files } } } @@ -377,6 +321,27 @@ OptionalInteger Replacement::IsInteger( const TreeNode & node ) const return ret; } +OptionalUnsignedInt Replacement::IsUnsignedInteger( const TreeNode & node ) const +{ + OptionalUnsignedInt ret; + if( OptionalString replace = HasFullReplacement( node ) ) + { + Property::Value value = GetFullReplacement( *replace ); + if( Property::UNSIGNED_INTEGER == value.GetType() ) + { + ret = value.Get(); + } + } + else + { + if ( OptionalInteger i = ::IsInteger( node ) ) + { + ret = OptionalUnsignedInt(static_cast(*i) ); + } + } + return ret; +} + OptionalVector2 Replacement::IsVector2( const TreeNode & node ) const { OptionalVector2 ret;