-//
-// 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) 2017 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 <dali-toolkit/internal/builder/replacement.h>
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() )
+ if ( !ret )
{
- ret = iter;
- }
- else
- {
- PropertyValueMap::const_iterator iter = 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}
+ ret = defaultMap.Find( str );
- }
+ // @ todo
+ // try localized text ie dgettext. Look for colon {DOMAIN:TEXT} {LC_MESSAGE:ID_XXXX}
}
return ret;
}
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 )
{
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() );
{
std::string newString = \
initialValue.substr(0, startPos - 1) +
- (*iter).second.Get<std::string>() +
+ value->Get< std::string >() +
initialValue.substr( startPos + size + 1 );
return ResolvePartialReplacement( newString, out, overrideMap, defaultMap );
} // namespace anon
-Replacement::Replacement( const PropertyValueMap& overrideMap, const PropertyValueMap& defaultMap )
+Replacement::Replacement( const Property::Map& overrideMap, const Property::Map& defaultMap )
: mOverrideMap( &overrideMap ), mDefaultMap( &defaultMap )
{
namespace
{
-PropertyValueMap noMap;
+Property::Map noMap;
}
-Replacement::Replacement( const PropertyValueMap& defaultMap )
+Replacement::Replacement( const Property::Map& defaultMap )
: mOverrideMap( &noMap ), mDefaultMap( &defaultMap )
{
{
OptionalString ret;
- if( node.HasSubstitution() && ((*mOverrideMap).size() || (*mDefaultMap).size()) )
+ if( node.HasSubstitution() && ((*mOverrideMap).Count() || (*mDefaultMap).Count()) )
{
OptionalString v = ::IsString( node );
if( v )
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(),
}
}
-// template <typename T, OptionalValue<T> (*ISTYPE)( const TreeNode& node ), Property::Type TYPE>
-// OptionalValue<T> IsOfType( const TreeNode& node, const PropertyValueMap& overrideMap, const PropertyValueMap& defaultMap )
-// {
-// OptionalValue<T> ret;
-// if( OptionalString replace = HasFullReplacement( node, overrideMap, defaultMap ) )
-// {
-// Property::Value value = GetFullReplacement( *replace, overrideMap, defaultMap );
-// if( TYPE == value.GetType() )
-// {
-// ret = value.Get<T>();
-// }
-// }
-// else
-// {
-// ret = ISTYPE( node );
-// }
-// return ret;
-
-// }
-
-// OptionalFloat Replacement::IsFloat( const TreeNode & node ) const
-// {
-// return IsOfType<float, ::IsFloat, Property::FLOAT>( node, *mOverrideMap, *mDefaultMap );
-// /* OptionalFloat ret; */
-// /* if( OptionalString replace = HasFullReplacement( node ) ) */
-// /* { */
-// /* Property::Value value = GetFullReplacement( replace ); */
-// /* if( Property::FLOAT == value.GetType() ) */
-// /* { */
-// /* ret = value.Get<float>(); */
-// /* } */
-// /* } */
-// /* else */
-// /* { */
-// /* ret = IsFloat( node ); */
-// /* } */
-// /* return ret; */
-// }
-
OptionalFloat Replacement::IsFloat( const TreeNode & node ) const
{
OptionalFloat ret;
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 ) )
{
#endif
}
}
+ else
+ {
+ ret = v; // sets the unexpanded. Expansion may occur later in processing with include files
+ }
}
}
else
return ret;
}
-
+OptionalExtents Replacement::IsExtents( const TreeNode & node ) const
+{
+ OptionalExtents extents;
+ if( OptionalString replace = HasFullReplacement( node ) )
+ {
+ Property::Value value = GetFullReplacement( *replace );
+ if( Property::EXTENTS == value.GetType() )
+ {
+ extents = value.Get<Extents>();
+ }
+ }
+ else
+ {
+ extents = ::IsExtents( node );
+ }
+ return extents;
+}
OptionalFloat Replacement::IsFloat( OptionalChild child ) const
{
return ret;
}
+OptionalExtents Replacement::IsExtents( OptionalChild child ) const
+{
+ if( child )
+ {
+ return IsExtents( *child );
+ }
+ else
+ {
+ return OptionalExtents();
+ }
+}
+
} // namespace Internal
} // namespace Toolkit
} // namespace Dali
-