Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <ostream> | |
| 10 #include <string> | |
| 11 | |
| 12 namespace dbus { | |
| 13 | |
| 14 // ObjectPath is a type used to distinguish D-Bus object paths from simple | |
| 15 // strings, especially since normal practice is that these should be only | |
| 16 // initialized from static constants or obtained from remote objects and no | |
| 17 // assumptions about their value made. | |
| 18 // | |
| 19 // An ObjectPath can be initialized from a std::string or from a character | |
| 20 // array, may be copied and assigned new vlaues, and may be used as a key | |
| 21 // in a std::map. | |
| 22 // | |
| 23 // To obtain the object path value as a std::string use value(), to obtain | |
| 24 // as a C-string (e.g. to pass to libdbus functions) use c_str(). | |
| 25 class ObjectPath { | |
| 26 public: | |
| 27 // Permit initialization, both implicit and explicit, without a value | |
| 28 // (for passing to dbus::MessageReader::PopObjectPath), from std::string | |
| 29 // objects, and from string constants. | |
| 30 // | |
| 31 // The compiler synthesised copy constructor and assignment operator are | |
| 32 // sufficient for our needs. | |
| 33 ObjectPath() {} | |
| 34 ObjectPath(const std::string& value) : value_(value) {} | |
|
satorux1
2012/02/12 20:16:30
explicit is missing.
keybuk
2012/02/12 22:09:29
see the comment - allowing implicit construction i
satorux1
2012/02/13 19:07:36
On the contrary, I don't want to make it transpare
| |
| 35 ObjectPath(const char* c_str) : value_(c_str) {} | |
|
satorux1
2012/02/12 20:16:30
I think we don't need the const char* version. The
keybuk
2012/02/12 22:09:29
yeah, I was convinced of that, but it doesn't work
| |
| 36 | |
| 37 // Retrieve value as a std::string and as a C-style string. | |
|
satorux1
2012/02/12 20:16:30
Retrieve -> Retrieves
http://google-styleguide.go
| |
| 38 const std::string& value() const { return value_; } | |
| 39 const char* c_str() const { return value_.c_str(); } | |
|
satorux1
2012/02/12 20:16:30
I think we can drop c_str(). Clients can just go w
keybuk
2012/02/12 22:09:29
sure thing, only useful inside dbus:: anyway (whic
| |
| 40 private: | |
| 41 std::string value_; | |
| 42 }; | |
| 43 | |
| 44 // Permit sufficient comparison to allow an ObjectPath to be used as a | |
| 45 // key in a std::map. | |
| 46 bool operator<(const ObjectPath&, const ObjectPath&); | |
| 47 | |
| 48 // Permit testing for equality, required for mocks to work and useful for | |
| 49 // observers. | |
| 50 bool operator==(const ObjectPath&, const ObjectPath&); | |
| 51 bool operator!=(const ObjectPath&, const ObjectPath&); | |
|
satorux1
2012/02/12 20:16:30
Can we go with Equals() instead?
http://google-st
keybuk
2012/02/12 22:09:29
note the "required for mocks to work" in the comme
satorux1
2012/02/13 19:07:36
BTW, FilePath has these operators inside the class
keybuk
2012/02/13 20:04:42
yup, I missed out the "const" from them when I tri
| |
| 52 | |
| 53 // Permit direct outputting on streams, for logging and debugging. | |
| 54 std::ostream& operator<<(std::ostream&, const ObjectPath&); | |
|
satorux1
2012/02/12 20:16:30
Let's drop this. Per our C++ style guide, we rarel
keybuk
2012/02/12 22:09:29
my hope is that we can actually get rid of value()
satorux1
2012/02/13 19:07:36
For the same reason mentioned above, making it tra
keybuk
2012/02/13 20:04:42
meh meh meh :p
| |
| 55 | |
| 56 } // namespace dbus | |
| 57 | |
| 58 #endif // DBUS_OBJECT_PATH_H_ | |
| OLD | NEW |