libaurum: fix a potentional error from missing-return
[platform/core/uifw/aurum.git] / libaurum / src / Comparer.cc
1 #include "Comparer.h"
2
3 #include "loguru.hpp"
4
5 Comparer::Comparer(const UiDevice *device, const UiSelector *selector,
6                    const bool &earlyReturn)
7     : mDevice(device), mSelector(selector), mEarlyReturn(earlyReturn)
8 {
9 }
10
11 Comparer::~Comparer() {}
12
13 AccessibleNode *Comparer::findObject(const UiDevice *      device,
14                                      const UiSelector *    selector,
15                                      const AccessibleNode *root)
16 {
17     Comparer                      comparer(device, selector, true);
18     std::vector<AccessibleNode *> ret = comparer.findObjects(root);
19     if (ret.size() > 0)
20         return ret[0];
21     else
22         return nullptr;
23 }
24
25 std::vector<AccessibleNode *> Comparer::findObjects(const UiDevice *  device,
26                                                     const UiSelector *selector,
27                                                     const AccessibleNode *root)
28 {
29     Comparer                      comparer(device, selector, false);
30     std::vector<AccessibleNode *> ret = comparer.findObjects(root);
31     return std::move(ret);
32 }
33
34 std::vector<AccessibleNode *> Comparer::findObjects(const AccessibleNode *root)
35 {
36     std::list<std::shared_ptr<PartialMatch>> partialList{};
37     std::vector<AccessibleNode *> ret = findObjects(root, 0, 0, partialList);
38     return std::move(ret);
39 }
40
41 std::vector<AccessibleNode *> Comparer::findObjects(
42     const AccessibleNode *root, const int &index, const int &depth,
43     std::list<std::shared_ptr<PartialMatch>> &partialMatches)
44 {
45     std::vector<AccessibleNode *> ret;
46     root->refresh();
47
48     // LOG_F(INFO, "%p %s / i:%d d:%d", root, root->getText().c_str(), index,
49     // depth);
50
51     for (auto match : partialMatches)
52         match->update(root, index, depth, partialMatches);
53
54     std::shared_ptr<PartialMatch> currentMatch =
55         PartialMatch::accept(root, mSelector, index, depth);
56     if (currentMatch) partialMatches.push_front(currentMatch);
57
58     int childCnt = root->getChildCount();
59     for (int i = 0; i < childCnt; i++) {
60         AccessibleNode *              childNode = root->getChildAt(i);
61         std::vector<AccessibleNode *> childret =
62             findObjects(childNode, i, depth + 1, partialMatches);
63         ret.insert(ret.end(), childret.begin(), childret.end());
64
65         if (!ret.empty() && mEarlyReturn) return ret;
66     }
67
68     if (currentMatch && currentMatch->finalizeMatch())
69         ret.push_back(const_cast<AccessibleNode *>(root));
70
71     return ret;
72 }