blob: 34887df3216f94f8c123e615fac7190999146840 [file] [log] [blame]
mukesh agrawalddc378f2012-02-17 18:26:20 -08001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Paul Stewart22aa71b2011-09-16 12:15:11 -07002// 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
13namespace shill {
14
15class 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.
21class 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 agrawalddc378f2012-02-17 18:26:20 -080026 const char *reason;
27 return Service::Compare(a, b, technology_order_, &reason);
Paul Stewart22aa71b2011-09-16 12:15:11 -070028 }
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_