mukesh agrawal | ddc378f | 2012-02-17 18:26:20 -0800 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef SERVICE_SORTER_ |
| 6 | #define SERVICE_SORTER_ |
| 7 | |
| 8 | #include <vector> |
| 9 | |
| 10 | #include "shill/refptr_types.h" |
| 11 | #include "shill/service.h" |
| 12 | |
| 13 | namespace shill { |
| 14 | |
| 15 | class Manager; |
| 16 | |
| 17 | // This is a closure used by the Manager for STL sorting of the |
| 18 | // Service array. We pass instances of this object to STL sort(), |
| 19 | // which in turn will call the selected function in the Manager to |
| 20 | // compare two Service objects at a time. |
| 21 | class ServiceSorter { |
| 22 | public: |
| 23 | explicit ServiceSorter(const std::vector<Technology::Identifier> &tech_order) |
| 24 | : technology_order_(tech_order) {} |
| 25 | bool operator() (ServiceRefPtr a, ServiceRefPtr b) { |
mukesh agrawal | ddc378f | 2012-02-17 18:26:20 -0800 | [diff] [blame] | 26 | const char *reason; |
| 27 | return Service::Compare(a, b, technology_order_, &reason); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | private: |
| 31 | const std::vector<Technology::Identifier> &technology_order_; |
| 32 | // We can't DISALLOW_COPY_AND_ASSIGN since this is passed by value to STL sort |
| 33 | }; |
| 34 | |
| 35 | } // namespace shill |
| 36 | |
| 37 | #endif // SERVICE_SORTER_ |