DALi Version 2.1.5
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / builder / builder-get-is.inl.h
index 61acd85..0a7f6d5 100644 (file)
@@ -1,33 +1,54 @@
-#ifndef __DALI_TOOLKIT_INTERNAL_BUILDER_GET_IS_INL__
-#define __DALI_TOOLKIT_INTERNAL_BUILDER_GET_IS_INL__
-
-//
-// 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.
-//
+#ifndef DALI_TOOLKIT_INTERNAL_BUILDER_GET_IS_INL
+#define DALI_TOOLKIT_INTERNAL_BUILDER_GET_IS_INL
+
+/*
+ * Copyright (c) 2021 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/builder-declarations.h>
 
 inline OptionalChild IsChild(const TreeNode* node, const std::string& childName)
 {
-  if( node )
+  if(node)
   {
     const TreeNode* c = node->GetChild(childName);
-    if( NULL != c )
+    if(NULL != c)
     {
-      return OptionalChild( *c );
+      return OptionalChild(*c);
+    }
+    else
+    {
+      return OptionalChild();
+    }
+  }
+  else
+  {
+    return OptionalChild();
+  }
+}
+
+inline OptionalChild IsChildIgnoreCase(const TreeNode* node, const std::string& childName)
+{
+  if(node)
+  {
+    const TreeNode* c = node->GetChildIgnoreCase(childName);
+    if(NULL != c)
+    {
+      return OptionalChild(*c);
     }
     else
     {
@@ -45,9 +66,14 @@ inline OptionalChild IsChild(const TreeNode& node, const std::string& childName)
   return IsChild(&node, childName);
 }
 
+inline OptionalChild IsChildIgnoreCase(const TreeNode& node, const std::string& childName)
+{
+  return IsChildIgnoreCase(&node, childName);
+}
+
 inline OptionalString IsString(const OptionalChild& node)
 {
-  if( node && (*node).GetType() == TreeNode::STRING )
+  if(node && (*node).GetType() == TreeNode::STRING)
   {
     return OptionalString((*node).GetString());
   }
@@ -56,40 +82,41 @@ inline OptionalString IsString(const OptionalChild& node)
     return OptionalString();
   }
 }
+
 inline OptionalFloat IsFloat(const OptionalChild& node)
 {
   OptionalFloat ret;
 
-  if( node )
+  if(node)
   {
-    if( (*node).GetType() == TreeNode::FLOAT )
+    if((*node).GetType() == TreeNode::FLOAT)
     {
       ret = (*node).GetFloat();
     }
-    else if( (*node).GetType() == TreeNode::INTEGER )
+    else if((*node).GetType() == TreeNode::INTEGER)
     {
       // JSON has number not float/int but JsonParser discriminates.
       // Here we don't care so we allow coercion
-      ret = static_cast<float>( (*node).GetInteger() );
+      ret = static_cast<float>((*node).GetInteger());
     }
   }
 
   return ret;
 }
 
-inline OptionalInteger IsInteger(const OptionalChild &node)
+inline OptionalInteger IsInteger(const OptionalChildnode)
 {
   OptionalInteger ret;
 
-  if( node )
+  if(node)
   {
-    if( (*node).GetType() == TreeNode::INTEGER )
+    if((*node).GetType() == TreeNode::INTEGER)
     {
       ret = (*node).GetInteger();
     }
-    else if( (*node).GetType() == TreeNode::FLOAT )
+    else if((*node).GetType() == TreeNode::FLOAT)
     {
-      ret = static_cast<int>(  (*node).GetFloat() );
+      ret = static_cast<int>((*node).GetFloat());
     }
   }
 
@@ -98,7 +125,7 @@ inline OptionalInteger IsInteger(const OptionalChild &node)
 
 inline OptionalBoolean IsBoolean(const OptionalChild& node)
 {
-  if( node && (*node).GetType() == TreeNode::BOOLEAN )
+  if(node && (*node).GetType() == TreeNode::BOOLEAN)
   {
     return OptionalBoolean(1 == (*node).GetInteger());
   }
@@ -109,16 +136,16 @@ inline OptionalBoolean IsBoolean(const OptionalChild& node)
 }
 
 // copy N Numbers
-template <typename T>
+template<typename T>
 inline bool CopyNumbers(TreeNode::ConstIterator iter, int N, T& vector)
 {
   for(int i = 0; i < N; ++i)
   {
-    if( (*iter).second.GetType() == TreeNode::FLOAT)
+    if((*iter).second.GetType() == TreeNode::FLOAT)
     {
       vector[i] = (*iter).second.GetFloat();
     }
-    else if( (*iter).second.GetType() == TreeNode::INTEGER )
+    else if((*iter).second.GetType() == TreeNode::INTEGER)
     {
       vector[i] = static_cast<float>((*iter).second.GetInteger());
     }
@@ -136,10 +163,10 @@ inline OptionalVector4 IsVector4(const OptionalChild& node)
 {
   OptionalVector4 ret;
 
-  if( node && (TreeNode::ARRAY == (*node).GetType()) && (*node).Size() >= 4 )
+  if(node && (TreeNode::ARRAY == (*node).GetType()) && (*node).Size() >= 4)
   {
     Dali::Vector4 v;
-    if( CopyNumbers((*node).CBegin(), 4, v) )
+    if(CopyNumbers((*node).CBegin(), 4, v))
     {
       ret = OptionalVector4(v);
     }
@@ -152,10 +179,10 @@ inline OptionalVector3 IsVector3(const OptionalChild& node)
 {
   OptionalVector3 ret;
 
-  if( node && (TreeNode::ARRAY == (*node).GetType()) && (*node).Size() >= 3 )
+  if(node && (TreeNode::ARRAY == (*node).GetType()) && (*node).Size() >= 3)
   {
     Dali::Vector3 v;
-    if( CopyNumbers((*node).CBegin(), 3, v) )
+    if(CopyNumbers((*node).CBegin(), 3, v))
     {
       ret = OptionalVector3(v);
     }
@@ -168,10 +195,10 @@ inline OptionalVector2 IsVector2(const OptionalChild& node)
 {
   OptionalVector2 ret;
 
-  if( node && (TreeNode::ARRAY == (*node).GetType()) && (*node).Size() >= 2 )
+  if(node && (TreeNode::ARRAY == (*node).GetType()) && (*node).Size() >= 2)
   {
     Dali::Vector2 v;
-    if( CopyNumbers((*node).CBegin(), 2, v) )
+    if(CopyNumbers((*node).CBegin(), 2, v))
     {
       ret = OptionalVector2(v);
     }
@@ -180,14 +207,14 @@ inline OptionalVector2 IsVector2(const OptionalChild& node)
   return ret;
 }
 
-inline OptionalMatrix IsMatrix(const OptionalChild &node)
+inline OptionalMatrix IsMatrix(const OptionalChildnode)
 {
   OptionalMatrix ret;
 
-  if( node && (TreeNode::ARRAY == (*node).GetType()) && (*node).Size() >= 16 )
+  if(node && (TreeNode::ARRAY == (*node).GetType()) && (*node).Size() >= 16)
   {
     float v[16];
-    if( CopyNumbers((*node).CBegin(), 16, v) )
+    if(CopyNumbers((*node).CBegin(), 16, v))
     {
       ret = OptionalMatrix(Dali::Matrix(v));
     }
@@ -200,14 +227,12 @@ inline OptionalMatrix3 IsMatrix3(const OptionalChild& node)
 {
   OptionalMatrix3 ret;
 
-  if( node && (TreeNode::ARRAY == (*node).GetType()) && (*node).Size() >= 9 )
+  if(node && (TreeNode::ARRAY == (*node).GetType()) && (*node).Size() >= 9)
   {
     float v[9];
-    if( CopyNumbers((*node).CBegin(), 9, v) )
+    if(CopyNumbers((*node).CBegin(), 9, v))
     {
-      ret = OptionalMatrix3(Dali::Matrix3(v[0], v[1], v[2],
-                                          v[3], v[4], v[5],
-                                          v[6], v[7], v[8] ));
+      ret = OptionalMatrix3(Dali::Matrix3(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8]));
     }
   }
 
@@ -222,8 +247,8 @@ inline OptionalRect IsRect(const OptionalChild& node)
     if((*node).Size() >= 4)
     {
       TreeNode::ConstIterator iter((*node).CBegin());
-      int v[4];
-      if( CopyNumbers((*node).CBegin(), 4, v) )
+      int                     v[4];
+      if(CopyNumbers((*node).CBegin(), 4, v))
       {
         ret = OptionalRect(Dali::Rect<int>(v[0], v[1], v[2], v[3]));
       }
@@ -232,157 +257,183 @@ inline OptionalRect IsRect(const OptionalChild& node)
   return ret;
 }
 
+inline OptionalExtents IsExtents(const OptionalChild& node)
+{
+  OptionalExtents extents;
+  if(node && (*node).Size())
+  {
+    if((*node).Size() >= 4)
+    {
+      TreeNode::ConstIterator iter((*node).CBegin());
+      int                     v[4];
+      if(CopyNumbers((*node).CBegin(), 4, v))
+      {
+        extents = OptionalExtents(Dali::Extents(v[0], v[1], v[2], v[3]));
+      }
+    }
+  }
+  return extents;
+}
+
 //
 //
 //
-inline OptionalString IsString( const TreeNode& parent, const std::string& childName)
+inline OptionalString IsString(const TreeNode& parent, const std::string& childName)
+{
+  return IsString(IsChild(&parent, childName));
+}
+
+inline OptionalFloat IsFloat(const TreeNode& parent, const std::string& childName)
 {
-  return IsString( IsChild(&parent, childName) );
+  return IsFloat(IsChild(&parent, childName));
 }
 
-inline OptionalFloat IsFloat( const TreeNode& parent, const std::string& childName)
+inline OptionalInteger IsInteger(const TreeNode& parent, const std::string& childName)
 {
-  return IsFloat( IsChild(&parent, childName) );
+  return IsInteger(IsChild(&parent, childName));
 }
 
-inline OptionalInteger IsInteger( const TreeNode& parent, const std::string& childName)
+inline OptionalBoolean IsBoolean(const TreeNode& parent, const std::string& childName)
 {
-  return IsInteger( IsChild(&parent, childName) );
+  return IsBoolean(IsChild(parent, childName));
 }
 
-inline OptionalBoolean IsBoolean( const TreeNode& parent, const std::string& childName)
+inline OptionalVector4 IsVector4(const TreeNode& parent, const std::string& childName)
 {
-  return IsBoolean( IsChild(parent, childName) );
+  return IsVector4(IsChild(parent, childName));
 }
 
-inline OptionalVector4 IsVector4(const TreeNode &parent, const std::string& childName)
+inline OptionalVector3 IsVector3(const TreeNode& parent, const std::string& childName)
 {
-  return IsVector4( IsChild(parent, childName) );
+  return IsVector3(IsChild(parent, childName));
 }
 
-inline OptionalVector3 IsVector3(const TreeNode &parent, const std::string& childName)
+inline OptionalVector2 IsVector2(const TreeNode& parent, const std::string& childName)
 {
-  return IsVector3( IsChild(parent, childName) );
+  return IsVector2(IsChild(parent, childName));
 }
 
-inline OptionalVector2 IsVector2(const TreeNode &parent, const std::string& childName)
+inline OptionalMatrix IsMatrix(const TreeNode& parent, const std::string& childName)
 {
-  return IsVector2( IsChild(parent, childName) );
+  return IsMatrix(IsChild(parent, childName));
 }
 
-inline OptionalMatrix IsMatrix(const TreeNode &parent, const std::string& childName)
+inline OptionalMatrix3 IsMatrix3(const TreeNode& parent, const std::string& childName)
 {
-  return IsMatrix( IsChild(parent, childName) );
+  return IsMatrix3(IsChild(&parent, childName));
 }
 
-inline OptionalMatrix3 IsMatrix3(const TreeNode &parent, const std::string& childName)
+inline OptionalRect IsRect(const TreeNode& parent, const std::string& childName)
 {
-  return IsMatrix3( IsChild(&parent, childName) );
+  return IsRect(IsChild(&parent, childName));
 }
 
-inline OptionalRect IsRect(const TreeNode &parent, const std::string& childName)
+inline OptionalExtents IsExtents(const TreeNode& parent, const std::string& childName)
 {
-  return IsRect( IsChild(&parent, childName) );
+  return IsExtents(IsChild(&parent, childName));
 }
 
 //
 //
 //
-inline OptionalString IsString( const TreeNode& node )
+inline OptionalString IsString(const TreeNode& node)
 {
-  return IsString( OptionalChild( node ) );
+  return IsString(OptionalChild(node));
 }
 
-inline OptionalFloat IsFloat( const TreeNode& node )
+inline OptionalFloat IsFloat(const TreeNode& node)
 {
-  return IsFloat( OptionalChild( node ) );
+  return IsFloat(OptionalChild(node));
 }
 
-inline OptionalInteger IsInteger( const TreeNode& node )
+inline OptionalInteger IsInteger(const TreeNode& node)
 {
-  return IsInteger( OptionalChild( node ) );
+  return IsInteger(OptionalChild(node));
 }
 
-inline OptionalBoolean IsBoolean( const TreeNode& node )
+inline OptionalBoolean IsBoolean(const TreeNode& node)
 {
-  return IsBoolean( OptionalChild( node ) );
+  return IsBoolean(OptionalChild(node));
 }
 
-inline OptionalVector4 IsVector4(const TreeNode &node )
+inline OptionalVector4 IsVector4(const TreeNode& node)
 {
-  return IsVector4( OptionalChild( node ) );
+  return IsVector4(OptionalChild(node));
 }
 
-inline OptionalVector3 IsVector3(const TreeNode &node )
+inline OptionalVector3 IsVector3(const TreeNode& node)
 {
-  return IsVector3( OptionalChild( node ) );
+  return IsVector3(OptionalChild(node));
 }
 
-inline OptionalVector2 IsVector2(const TreeNode &node )
+inline OptionalVector2 IsVector2(const TreeNode& node)
 {
-  return IsVector2( OptionalChild( node ) );
+  return IsVector2(OptionalChild(node));
 }
 
-inline OptionalMatrix IsMatrix(const TreeNode &node )
+inline OptionalMatrix IsMatrix(const TreeNode& node)
 {
-  return IsMatrix( OptionalChild( node ) );
+  return IsMatrix(OptionalChild(node));
 }
 
-inline OptionalMatrix3 IsMatrix3(const TreeNode &node )
+inline OptionalMatrix3 IsMatrix3(const TreeNode& node)
 {
-  return IsMatrix3( OptionalChild( node ) );
+  return IsMatrix3(OptionalChild(node));
 }
 
-inline OptionalRect IsRect(const TreeNode &node )
+inline OptionalRect IsRect(const TreeNode& node)
 {
-  return IsRect( OptionalChild( node ) );
+  return IsRect(OptionalChild(node));
+}
+
+inline OptionalExtents IsExtents(const TreeNode& node)
+{
+  return IsExtents(OptionalChild(node));
 }
 
 //
 //
 //
-inline Dali::Vector4 GetVector4(const TreeNode &child)
+inline Dali::Vector4 GetVector4(const TreeNodechild)
 {
-  OptionalVector4 v( IsVector4( OptionalChild( child ) ) );
+  OptionalVector4 v(IsVector4(OptionalChild(child)));
   DALI_ASSERT_ALWAYS(v);
   return *v;
 }
 
-inline Dali::Vector3 GetVector3(const TreeNode &child)
+inline Dali::Vector3 GetVector3(const TreeNodechild)
 {
-  OptionalVector3 v( IsVector3( OptionalChild( child ) ) );
+  OptionalVector3 v(IsVector3(OptionalChild(child)));
   DALI_ASSERT_ALWAYS(v);
   return *v;
 }
 
-inline Dali::Vector2 GetVector2(const TreeNode &child)
+inline Dali::Vector2 GetVector2(const TreeNodechild)
 {
-  OptionalVector2 v( IsVector2( OptionalChild( child ) ) );
+  OptionalVector2 v(IsVector2(OptionalChild(child)));
   DALI_ASSERT_ALWAYS(v);
   return *v;
 }
 
-inline float GetFloat(const TreeNode &child)
+inline float GetFloat(const TreeNodechild)
 {
-  OptionalFloat v( IsFloat( OptionalChild( child ) ) );
+  OptionalFloat v(IsFloat(OptionalChild(child)));
   DALI_ASSERT_ALWAYS(v);
   return *v;
 }
 
-inline bool GetBoolean(const TreeNode &child)
+inline bool GetBoolean(const TreeNodechild)
 {
-  OptionalBoolean v( IsBoolean( OptionalChild( child ) ) );
+  OptionalBoolean v(IsBoolean(OptionalChild(child)));
   DALI_ASSERT_ALWAYS(v);
   return *v;
 }
 
-inline int GetInteger(const TreeNode &child)
+inline int GetInteger(const TreeNodechild)
 {
-  OptionalInteger v( IsInteger( OptionalChild( child ) ) );
+  OptionalInteger v(IsInteger(OptionalChild(child)));
   DALI_ASSERT_ALWAYS(v);
   return *v;
 }
 
-
-
-#endif // __DALI_TOOLKIT_INTERNAL_BUILDER_GET_IS_INL__
+#endif // DALI_TOOLKIT_INTERNAL_BUILDER_GET_IS_INL