Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-adaptor.git] / dali / internal / accessibility / bridge / bridge-collection.cpp
index 022a310..b2e0f06 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * 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.
@@ -29,16 +29,16 @@ using namespace Dali::Accessibility;
 void BridgeCollection::RegisterInterfaces()
 {
   DBus::DBusInterfaceDescription desc{AtspiDbusInterfaceCollection};
-  AddFunctionToInterface( desc, "GetMatches", &BridgeCollection::GetMatches );
-  dbusServer.addInterface( "/", desc, true );
+  AddFunctionToInterface(desc, "GetMatches", &BridgeCollection::GetMatches);
+  dbusServer.addInterface("/", desc, true);
 }
 
 Collection* BridgeCollection::FindSelf() const
 {
   auto s = BridgeBase::FindSelf();
-  assert( s );
-  auto s2 = dynamic_cast< Collection* >( s );
-  if( !s2 )
+  assert(s);
+  auto s2 = dynamic_cast<Collection*>(s);
+  if(!s2)
     throw std::domain_error{"object " + s->GetAddress().ToString() + " doesn't have Collection interface"};
   return s2;
 }
@@ -63,9 +63,9 @@ struct BridgeCollection::Comparer
     FIRST_NOT_FOUND
   };
 
-  static Mode ConvertToMatchType( int32_t mode )
+  static Mode ConvertToMatchType(int32_t mode)
   {
-    switch( mode )
+    switch(mode)
     {
       case ATSPI_Collection_MATCH_INVALID:
       {
@@ -93,31 +93,38 @@ struct BridgeCollection::Comparer
 
   struct ComparerInterfaces
   {
-    std::unordered_set< std::string > object;
-    std::vector< std::string > requested;
-    Mode mode = Mode::INVALID;
+    std::unordered_set<std::string> object;
+    std::vector<std::string>        requested;
+    Mode                            mode = Mode::INVALID;
 
-    ComparerInterfaces( MatchRule* rule ) : mode( ConvertToMatchType( std::get< Index::InterfacesMatchType >( *rule ) ) )
+    ComparerInterfaces(MatchRule* rule)
+    : mode(ConvertToMatchType(std::get<Index::InterfacesMatchType>(*rule)))
     {
-      requested = {std::get< Index::Interfaces >( *rule ).begin(), std::get< Index::Interfaces >( *rule ).end()};
+      requested = {std::get<Index::Interfaces>(*rule).begin(), std::get<Index::Interfaces>(*rule).end()};
     }
-    void Update( Accessible* obj )
+    void Update(Accessible* obj)
     {
       object.clear();
-      for( auto& q : obj->GetInterfaces() )
-        object.insert( std::move( q ) );
+      for(auto& q : obj->GetInterfaces())
+        object.insert(std::move(q));
     }
-    bool RequestEmpty() const { return requested.empty(); }
-    bool ObjectEmpty() const { return object.empty(); }
-    bool Compare( CompareFuncExit exit )
+    bool RequestEmpty() const
+    {
+      return requested.empty();
+    }
+    bool ObjectEmpty() const
+    {
+      return object.empty();
+    }
+    bool Compare(CompareFuncExit exit)
     {
       bool foundAny = false;
-      for( auto& iname : requested )
+      for(auto& iname : requested)
       {
-        bool found = ( object.find( iname ) != object.end() );
-        if( found )
+        bool found = (object.find(iname) != object.end());
+        if(found)
           foundAny = true;
-        if( found == ( exit == CompareFuncExit::FIRST_FOUND ) )
+        if(found == (exit == CompareFuncExit::FIRST_FOUND))
           return found;
       }
       return foundAny;
@@ -125,29 +132,36 @@ struct BridgeCollection::Comparer
   };
   struct ComparerAttributes
   {
-    std::unordered_map< std::string, std::string > requested, object;
-    Mode mode = Mode::INVALID;
+    std::unordered_map<std::string, std::string> requested, object;
+    Mode                                         mode = Mode::INVALID;
 
-    ComparerAttributes( MatchRule* rule ) : mode( ConvertToMatchType( std::get< Index::AttributesMatchType >( *rule ) ) )
+    ComparerAttributes(MatchRule* rule)
+    : mode(ConvertToMatchType(std::get<Index::AttributesMatchType>(*rule)))
     {
-      requested = std::get< Index::Attributes >( *rule );
+      requested = std::get<Index::Attributes>(*rule);
     }
-    void Update( Accessible* obj )
+    void Update(Accessible* obj)
     {
       object = obj->GetAttributes();
     }
-    bool RequestEmpty() const { return requested.empty(); }
-    bool ObjectEmpty() const { return object.empty(); }
-    bool Compare( CompareFuncExit exit )
+    bool RequestEmpty() const
+    {
+      return requested.empty();
+    }
+    bool ObjectEmpty() const
+    {
+      return object.empty();
+    }
+    bool Compare(CompareFuncExit exit)
     {
       bool foundAny = false;
-      for( auto& iname : requested )
+      for(auto& iname : requested)
       {
-        auto it = object.find( iname.first );
+        auto it    = object.find(iname.first);
         bool found = it != object.end() && iname.second == it->second;
-        if( found )
+        if(found)
           foundAny = true;
-        if( found == ( exit == CompareFuncExit::FIRST_FOUND ) )
+        if(found == (exit == CompareFuncExit::FIRST_FOUND))
         {
           return found;
         }
@@ -157,25 +171,32 @@ struct BridgeCollection::Comparer
   };
   struct ComparerRoles
   {
-    using Roles = BitSets< 4, Role >;
+    using Roles = BitSets<4, Role>;
     Roles requested, object;
-    Mode mode = Mode::INVALID;
+    Mode  mode = Mode::INVALID;
 
-    ComparerRoles( MatchRule* rule ) : mode( ConvertToMatchType( std::get< Index::RolesMatchType >( *rule ) ) )
+    ComparerRoles(MatchRule* rule)
+    : mode(ConvertToMatchType(std::get<Index::RolesMatchType>(*rule)))
     {
-      requested = Roles{std::get< Index::Roles >( *rule )};
+      requested = Roles{std::get<Index::Roles>(*rule)};
     }
-    void Update( Accessible* obj )
+    void Update(Accessible* obj)
     {
-      object = {};
+      object                 = {};
       object[obj->GetRole()] = true;
-      assert( object );
+      assert(object);
+    }
+    bool RequestEmpty() const
+    {
+      return !requested;
+    }
+    bool ObjectEmpty() const
+    {
+      return !object;
     }
-    bool RequestEmpty() const { return !requested; }
-    bool ObjectEmpty() const { return !object; }
-    bool Compare( CompareFuncExit exit )
+    bool Compare(CompareFuncExit exit)
     {
-      switch( mode )
+      switch(mode)
       {
         case Mode::INVALID:
         {
@@ -184,15 +205,15 @@ struct BridgeCollection::Comparer
         case Mode::EMPTY:
         case Mode::ALL:
         {
-          return requested == ( object & requested );
+          return requested == (object & requested);
         }
         case Mode::ANY:
         {
-          return bool( object & requested );
+          return bool(object & requested);
         }
         case Mode::NONE:
         {
-          return bool( object & requested );
+          return bool(object & requested);
         }
       }
       return false;
@@ -201,21 +222,28 @@ struct BridgeCollection::Comparer
   struct ComparerStates
   {
     States requested, object;
-    Mode mode = Mode::INVALID;
+    Mode   mode = Mode::INVALID;
 
-    ComparerStates( MatchRule* rule ) : mode( ConvertToMatchType( std::get< Index::StatesMatchType >( *rule ) ) )
+    ComparerStates(MatchRule* rule)
+    : mode(ConvertToMatchType(std::get<Index::StatesMatchType>(*rule)))
     {
-      requested = States{std::get< Index::States >( *rule )};
+      requested = States{std::get<Index::States>(*rule)};
     }
-    void Update( Accessible* obj )
+    void Update(Accessible* obj)
     {
       object = obj->GetStates();
     }
-    bool RequestEmpty() const { return !requested; }
-    bool ObjectEmpty() const { return !object; }
-    bool Compare( CompareFuncExit exit )
+    bool RequestEmpty() const
+    {
+      return !requested;
+    }
+    bool ObjectEmpty() const
     {
-      switch( mode )
+      return !object;
+    }
+    bool Compare(CompareFuncExit exit)
+    {
+      switch(mode)
       {
         case Mode::INVALID:
         {
@@ -224,54 +252,54 @@ struct BridgeCollection::Comparer
         case Mode::EMPTY:
         case Mode::ALL:
         {
-          return requested == ( object & requested );
+          return requested == (object & requested);
         }
         case Mode::ANY:
         {
-          return bool( object & requested );
+          return bool(object & requested);
         }
         case Mode::NONE:
         {
-          return bool( object & requested );
+          return bool(object & requested);
         }
       }
       return false;
     }
   };
 
-  template < typename T >
-  bool compareFunc( T& cmp, Accessible* obj )
+  template<typename T>
+  bool compareFunc(T& cmp, Accessible* obj)
   {
-    if( cmp.mode == Mode::INVALID )
+    if(cmp.mode == Mode::INVALID)
       return true;
-    cmp.Update( obj );
-    switch( cmp.mode )
+    cmp.Update(obj);
+    switch(cmp.mode)
     {
       case Mode::ANY:
       {
-        if( cmp.RequestEmpty() || cmp.ObjectEmpty() )
+        if(cmp.RequestEmpty() || cmp.ObjectEmpty())
           return false;
         break;
       }
       case Mode::ALL:
       {
-        if( cmp.RequestEmpty() )
+        if(cmp.RequestEmpty())
           return true;
-        if( cmp.ObjectEmpty() )
+        if(cmp.ObjectEmpty())
           return false;
         break;
       }
       case Mode::NONE:
       {
-        if( cmp.RequestEmpty() || cmp.ObjectEmpty() )
+        if(cmp.RequestEmpty() || cmp.ObjectEmpty())
           return true;
         break;
       }
       case Mode::EMPTY:
       {
-        if( cmp.RequestEmpty() && cmp.ObjectEmpty() )
+        if(cmp.RequestEmpty() && cmp.ObjectEmpty())
           return true;
-        if( cmp.RequestEmpty() || cmp.ObjectEmpty() )
+        if(cmp.RequestEmpty() || cmp.ObjectEmpty())
           return false;
         break;
       }
@@ -281,24 +309,24 @@ struct BridgeCollection::Comparer
       }
     }
 
-    switch( cmp.mode )
+    switch(cmp.mode)
     {
       case Mode::EMPTY:
       case Mode::ALL:
       {
-        if( !cmp.Compare( CompareFuncExit::FIRST_NOT_FOUND ) )
+        if(!cmp.Compare(CompareFuncExit::FIRST_NOT_FOUND))
           return false;
         break;
       }
       case Mode::ANY:
       {
-        if( cmp.Compare( CompareFuncExit::FIRST_FOUND ) )
+        if(cmp.Compare(CompareFuncExit::FIRST_FOUND))
           return true;
         break;
       }
       case Mode::NONE:
       {
-        if( cmp.Compare( CompareFuncExit::FIRST_FOUND ) )
+        if(cmp.Compare(CompareFuncExit::FIRST_FOUND))
           return false;
         break;
       }
@@ -307,7 +335,7 @@ struct BridgeCollection::Comparer
         return true;
       }
     }
-    switch( cmp.mode )
+    switch(cmp.mode)
     {
       case Mode::EMPTY:
       case Mode::ALL:
@@ -329,40 +357,46 @@ struct BridgeCollection::Comparer
 
   ComparerInterfaces ci;
   ComparerAttributes ca;
-  ComparerRoles cr;
-  ComparerStates cs;
+  ComparerRoles      cr;
+  ComparerStates     cs;
 
-  Comparer( MatchRule* mr ) : ci( mr ), ca( mr ), cr( mr ), cs( mr ) {}
+  Comparer(MatchRule* mr)
+  : ci(mr),
+    ca(mr),
+    cr(mr),
+    cs(mr)
+  {
+  }
 
-  bool operator()( Accessible* obj )
+  bool operator()(Accessible* obj)
   {
-    return compareFunc( ci, obj ) &&
-           compareFunc( ca, obj ) &&
-           compareFunc( cr, obj ) &&
-           compareFunc( cs, obj );
+    return compareFunc(ci, obj) &&
+           compareFunc(ca, obj) &&
+           compareFunc(cr, obj) &&
+           compareFunc(cs, obj);
   }
 };
 
-void BridgeCollection::VisitNodes( Accessible* obj, std::vector< Accessible* >& result, Comparer& cmp, size_t maxCount )
+void BridgeCollection::VisitNodes(Accessible* obj, std::vector<Accessible*>& result, Comparer& cmp, size_t maxCount)
 {
-  if( maxCount > 0 && result.size() >= maxCount )
+  if(maxCount > 0 && result.size() >= maxCount)
     return;
 
-  if( cmp( obj ) )
-    result.emplace_back( obj );
+  if(cmp(obj))
+    result.emplace_back(obj);
 
-  for( auto i = 0u; i < obj->GetChildCount(); ++i )
-    VisitNodes( obj->GetChildAtIndex( i ), result, cmp, maxCount );
+  for(auto i = 0u; i < obj->GetChildCount(); ++i)
+    VisitNodes(obj->GetChildAtIndex(i), result, cmp, maxCount);
 }
 
-DBus::ValueOrError< std::vector< Accessible* > > BridgeCollection::GetMatches( MatchRule rule, uint32_t sortBy, int32_t count, bool traverse )
+DBus::ValueOrError<std::vector<Accessible*> > BridgeCollection::GetMatches(MatchRule rule, uint32_t sortBy, int32_t count, bool traverse)
 {
-  std::vector< Accessible* > res;
-  auto self = BridgeBase::FindSelf();
-  auto matcher = Comparer{&rule};
-  VisitNodes( self, res, matcher, count );
+  std::vector<Accessible*> res;
+  auto                     self    = BridgeBase::FindSelf();
+  auto                     matcher = Comparer{&rule};
+  VisitNodes(self, res, matcher, count);
 
-  switch( static_cast< SortOrder >( sortBy ) )
+  switch(static_cast<SortOrder>(sortBy))
   {
     case SortOrder::CANONICAL:
     {
@@ -371,7 +405,7 @@ DBus::ValueOrError< std::vector< Accessible* > > BridgeCollection::GetMatches( M
 
     case SortOrder::REVERSE_CANONICAL:
     {
-      std::reverse( res.begin(), res.end() );
+      std::reverse(res.begin(), res.end());
       break;
     }