use string_view to avoid string copy
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / builder / tree-node.h
index c63bf1f..6246b16 100644 (file)
@@ -1,8 +1,8 @@
-#ifndef __DALI_SCRIPT_TREE_NODE_H__
-#define __DALI_SCRIPT_TREE_NODE_H__
+#ifndef DALI_SCRIPT_TREE_NODE_H
+#define DALI_SCRIPT_TREE_NODE_H
 
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
  */
 
 // EXTERNAL INCLUDES
-#include <utility> // pair
+#include <dali-toolkit/public-api/dali-toolkit-common.h>
 #include <iterator>
-#include <dali/public-api/common/dali-common.h>
+#include <string>
+#include <utility> // pair
 
 namespace Dali
 {
-
 namespace Toolkit
 {
-
 namespace Internal DALI_INTERNAL
 {
-
 class TreeNodeManipulator;
 
-} // namespace Internal
-
+} // namespace DALI_INTERNAL
 
 /*
  * TreeNode describes a tree of nodes.
  * TreeNode does not own its string data which is held by a container eg JsonParser
  * Modification operations should be done through a container.
  */
-class DALI_IMPORT_API TreeNode
+class DALI_TOOLKIT_API TreeNode
 {
 public:
   /*
@@ -69,16 +66,16 @@ public:
   /*
    * Iterator to iterate through children
    */
-  class ConstIterator
+  class DALI_TOOLKIT_API ConstIterator
   {
   public:
-    typedef KeyNodePair          value_type;
-    typedef KeyNodePair          *pointer;
-    typedef const KeyNodePair    *const_pointer;
-    typedef KeyNodePair          &reference;
-    typedef const KeyNodePair    &const_reference;
-    typedef size_t               size_type;
-    typedef std::ptrdiff_t       difference_type;
+    typedef KeyNodePair               value_type;
+    typedef KeyNodePair*              pointer;
+    typedef const KeyNodePair*        const_pointer;
+    typedef KeyNodePair&              reference;
+    typedef const KeyNodePair&        const_reference;
+    typedef size_t                    size_type;
+    typedef std::ptrdiff_t            difference_type;
     typedef std::forward_iterator_tag iterator_category;
 
     /*
@@ -89,22 +86,23 @@ public:
     /*
      * pre increment
      */
-    ConstIterator& operator ++();
+    ConstIterator& operator++();
 
     /*
      * post increment
      */
-    ConstIterator operator ++(int);
+    ConstIterator operator++(int);
 
     /*
      * != test
      */
-    bool operator!=( const ConstIterator& rhs ) const;
+    bool operator!=(const ConstIterator& rhs) const;
 
     /*
      * pointer semantics
      */
     KeyNodePair operator*();
+
   private:
     TreeNode* mNode;
   };
@@ -132,7 +130,7 @@ public:
    * @param childName The name of the child to find
    * @return the number of children in the found child
    */
-  size_t Count(const std::string& childName) const;
+  size_t Count(std::string_view childName) const;
 
   /*
    * Get the nodes name
@@ -186,21 +184,21 @@ public:
    * @param name The name of the child.
    * @return The child if found, else NULL
    */
-  const TreeNode* GetChild(const std::string& name) const;
+  const TreeNode* GetChild(std::string_view name) const;
 
   /*
    * Gets a child of the node (using case insensitive matching)
    * @param name The name of the child in lower case
    * @return The child if found, else NULL
    */
-  const TreeNode* GetChildIgnoreCase(const std::string& name) const;
+  const TreeNode* GetChildIgnoreCase(std::string_view name) const;
 
   /*
    * Recursively search for a child of the node
    * @param name The name of the child
    * @return The child if found, else NULL
    */
-  const TreeNode* Find(const std::string& name) const;
+  const TreeNode* Find(std::string_view name) const;
 
 private:
   friend class Internal::TreeNodeManipulator;
@@ -211,30 +209,29 @@ private:
   DALI_INTERNAL TreeNode();
 
   // non copyable or assignable
-  DALI_INTERNAL TreeNode(TreeNode &);
+  DALI_INTERNAL TreeNode(TreeNode&);
   DALI_INTERNAL TreeNode& operator=(const TreeNode&);
 
-  const char* mName;                   ///< The nodes name (if any)
+  const char* mName; ///< The nodes name (if any)
 
-  TreeNode* mParent;                   ///< The nodes parent
-  TreeNode* mNextSibling;              ///< The nodes next sibling
-  TreeNode* mFirstChild;               ///< The nodes first child
-  TreeNode* mLastChild;                ///< The nodes last child
+  TreeNode* mParent;      ///< The nodes parent
+  TreeNode* mNextSibling; ///< The nodes next sibling
+  TreeNode* mFirstChild;  ///< The nodes first child
+  TreeNode* mLastChild;   ///< The nodes last child
 
   union
   {
-    const char* mStringValue;          ///< The node string value
-    int mIntValue;                     ///< The node integer value
-    float mFloatValue;                 ///< The node float value
+    const char* mStringValue; ///< The node string value
+    int         mIntValue;    ///< The node integer value
+    float       mFloatValue;  ///< The node float value
   };
 
-  NodeType mType;                      ///< The nodes type
-  bool mSubstituion;                   ///< String substitution flag
-
+  NodeType mType;        ///< The nodes type
+  bool     mSubstituion; ///< String substitution flag
 };
 
 } // namespace Toolkit
 
 } // namespace Dali
 
-#endif // __DALI_SCRIPT_TREE_NODE_H__
+#endif // DALI_SCRIPT_TREE_NODE_H