Aurum: Improve performance of findElements command
[platform/core/uifw/aurum.git] / libaurum / inc / Comparer.h
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *               http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  */
17
18 #ifndef _COMPARER_H_
19 #define _COMPARER_H_
20
21 #include "config.h"
22
23 #include "Accessible.h"
24 #include "UiDevice.h"
25 #include "UiSelector.h"
26
27 #include "PartialMatch.h"
28
29 #include <list>
30 #include <memory>
31 #include <vector>
32
33 namespace Aurum {
34
35 /**
36  * @class Comparer
37  *
38  * @ingroup aurum
39  *
40  * @brief Class that traverses the object tree and finds an object that match the given condition.
41  */
42 class Comparer {
43 private:
44     /**
45      * @brief Comparer constructor with device, selector, early return flag.
46      *
47      * @param[in] device @UiDevice
48      * @param[in] selector @UiSelector
49      * @param[in] earlyReturn flag for early return
50      *
51      * @since_tizen 6.5
52      */
53     Comparer(const std::shared_ptr<UiDevice>& device, const std::shared_ptr<UiSelector>& selector,
54              const bool &earlyReturn);
55
56     /**
57      * @brief Comparer destructor.
58      *
59      * @since_tizen 6.5
60      */
61     ~Comparer();
62
63 public:
64     /**
65      * @brief find object from device.
66      *        it finds focused window then start to find object as it root.
67      *
68      * @param[in] device @UiDevice
69      * @param[in] selector @UiSelector
70      * @param[in] root @AccessibleNode root object(focused window on current state)
71      *
72      * @return AccessibleNode if found, else nullptr
73      *
74      * @since_tizen 6.5
75      */
76     static std::shared_ptr<AccessibleNode> findObject(const std::shared_ptr<UiDevice>& device,
77                                                       const std::shared_ptr<UiSelector>& selector,
78                                                       const std::shared_ptr<AccessibleNode>& root);
79
80     /**
81      * @brief find object from device.
82      *        it finds focused window then start to find object as it root.
83      *        Finds all objects to the end of tree.
84      *
85      * @param[in] ret vector where found objects stored
86      * @param[in] device @UiDevice
87      * @param[in] selector @UiSelector
88      * @param[in] root @AccessibleNode root object(focused window on current state)
89      * @param[in] earlyReturn find all object or not (default = false)
90      *
91      *
92      * @since_tizen 6.5
93      */
94     static void findObjects(std::vector<std::shared_ptr<AccessibleNode>> &ret,
95         const std::shared_ptr<UiDevice>& device, const std::shared_ptr<UiSelector>& selector,
96         const std::shared_ptr<AccessibleNode>& root, bool earlyReturn = false);
97
98 private:
99     /**
100      * @internal
101      *
102      * @brief Starts find object from root.
103      *
104      * @param[in] ret vector where found objects stored
105      * @param[in] root @AccessibleNode
106      *
107      * @since_tizen 6.5
108      */
109     void findObjects(std::vector<std::shared_ptr<AccessibleNode>> &ret,
110         const std::shared_ptr<AccessibleNode>& root);
111
112     /**
113      * @internal
114      *
115      * @brief It updates all partialMatches and traverse tree till given depth to find objects
116      *
117      * @param[in] ret vector where found objects stored
118      * @param[in] root @AccessibleNode
119      * @param[in] index node index
120      * @param[in] depth tree depth
121      * @param[in] partialMatches @PartialMatch list
122      *
123      * @since_tizen 6.5
124      */
125     void findObjects(
126         std::vector<std::shared_ptr<AccessibleNode>> &ret,
127         const std::shared_ptr<AccessibleNode>& root, const int &index, const int &depth,
128         std::list<std::shared_ptr<PartialMatch>> &partialMatches);
129
130 private:
131     const std::shared_ptr<UiDevice>& mDevice;
132     const std::shared_ptr<UiSelector>& mSelector;
133     bool mEarlyReturn;
134 };
135
136 }
137
138 #endif