keybuk@google.com | bf4649a | 2012-02-15 06:29:06 +0900 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 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 DBUS_OBJECT_PATH_H_ |
| 6 | #define DBUS_OBJECT_PATH_H_ |
keybuk@google.com | bf4649a | 2012-02-15 06:29:06 +0900 | [diff] [blame] | 7 | |
pneubeck@chromium.org | d8ba24c | 2013-04-12 23:16:32 +0900 | [diff] [blame] | 8 | #include <iosfwd> |
keybuk@google.com | bf4649a | 2012-02-15 06:29:06 +0900 | [diff] [blame] | 9 | #include <string> |
| 10 | |
tfarina@chromium.org | 7928ea2 | 2012-11-05 10:56:14 +0900 | [diff] [blame] | 11 | #include "dbus/dbus_export.h" |
| 12 | |
keybuk@google.com | bf4649a | 2012-02-15 06:29:06 +0900 | [diff] [blame] | 13 | namespace dbus { |
| 14 | |
| 15 | // ObjectPath is a type used to distinguish D-Bus object paths from simple |
| 16 | // strings, especially since normal practice is that these should be only |
| 17 | // initialized from static constants or obtained from remote objects and no |
| 18 | // assumptions about their value made. |
tfarina@chromium.org | 7928ea2 | 2012-11-05 10:56:14 +0900 | [diff] [blame] | 19 | class CHROME_DBUS_EXPORT ObjectPath { |
keybuk@google.com | bf4649a | 2012-02-15 06:29:06 +0900 | [diff] [blame] | 20 | public: |
| 21 | // Permit initialization without a value for passing to |
| 22 | // dbus::MessageReader::PopObjectPath to fill in and from std::string |
| 23 | // objects. |
| 24 | // |
| 25 | // The compiler synthesised copy constructor and assignment operator are |
| 26 | // sufficient for our needs, as is implicit initialization of a std::string |
| 27 | // from a string constant. |
| 28 | ObjectPath() {} |
| 29 | explicit ObjectPath(const std::string& value) : value_(value) {} |
| 30 | |
| 31 | // Retrieves value as a std::string. |
| 32 | const std::string& value() const { return value_; } |
| 33 | |
hashimoto@chromium.org | 5fdbcf7 | 2012-06-05 13:15:50 +0900 | [diff] [blame] | 34 | // Returns true if the value is a valid object path. |
| 35 | bool IsValid() const; |
| 36 | |
keybuk@google.com | bf4649a | 2012-02-15 06:29:06 +0900 | [diff] [blame] | 37 | // Permit sufficient comparison to allow an ObjectPath to be used as a |
| 38 | // key in a std::map. |
| 39 | bool operator<(const ObjectPath&) const; |
| 40 | |
| 41 | // Permit testing for equality, required for mocks to work and useful for |
| 42 | // observers. |
| 43 | bool operator==(const ObjectPath&) const; |
| 44 | bool operator!=(const ObjectPath&) const; |
tfarina@chromium.org | 7928ea2 | 2012-11-05 10:56:14 +0900 | [diff] [blame] | 45 | |
keybuk@google.com | bf4649a | 2012-02-15 06:29:06 +0900 | [diff] [blame] | 46 | private: |
| 47 | std::string value_; |
| 48 | }; |
| 49 | |
pneubeck@chromium.org | d8ba24c | 2013-04-12 23:16:32 +0900 | [diff] [blame] | 50 | // This is required by gtest to print a readable output on test failures. |
| 51 | CHROME_DBUS_EXPORT void PrintTo(const ObjectPath& path, std::ostream* out); |
| 52 | |
keybuk@google.com | bf4649a | 2012-02-15 06:29:06 +0900 | [diff] [blame] | 53 | } // namespace dbus |
| 54 | |
| 55 | #endif // DBUS_OBJECT_PATH_H_ |