Merge "Dont register accessibility and keyboard focus properties as scene graph prope...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / builder / replacement.cpp
index 701b7c8..49e7365 100644 (file)
@@ -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 <dali-toolkit/internal/builder/replacement.h>
@@ -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<std::string>() +
+            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 <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;
@@ -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 ) )
     {
@@ -343,6 +290,10 @@ OptionalString Replacement::IsString( const TreeNode& node ) const
 #endif
         }
       }
+      else
+      {
+        ret = v; // sets the unexpanded. Expansion may occur later in processing with include files
+      }
     }
   }
   else
@@ -370,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<unsigned int>();
+    }
+  }
+  else
+  {
+    if ( OptionalInteger i = ::IsInteger( node ) )
+    {
+      ret = OptionalUnsignedInt(static_cast<unsigned int>(*i) );
+    }
+  }
+  return ret;
+}
+
 OptionalVector2 Replacement::IsVector2( const TreeNode & node ) const
 {
   OptionalVector2 ret;