Chromium Code Reviews| Index: dbus/object_path.h |
| diff --git a/dbus/object_path.h b/dbus/object_path.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3c055a6ac636fa714cd313a5b851a47a42103904 |
| --- /dev/null |
| +++ b/dbus/object_path.h |
| @@ -0,0 +1,58 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef DBUS_OBJECT_PATH_H_ |
| +#define DBUS_OBJECT_PATH_H_ |
| +#pragma once |
| + |
| +#include <ostream> |
| +#include <string> |
| + |
| +namespace dbus { |
| + |
| +// ObjectPath is a type used to distinguish D-Bus object paths from simple |
| +// strings, especially since normal practice is that these should be only |
| +// initialized from static constants or obtained from remote objects and no |
| +// assumptions about their value made. |
| +// |
| +// An ObjectPath can be initialized from a std::string or from a character |
| +// array, may be copied and assigned new vlaues, and may be used as a key |
| +// in a std::map. |
| +// |
| +// To obtain the object path value as a std::string use value(), to obtain |
| +// as a C-string (e.g. to pass to libdbus functions) use c_str(). |
| +class ObjectPath { |
| + public: |
| + // Permit initialization, both implicit and explicit, without a value |
| + // (for passing to dbus::MessageReader::PopObjectPath), from std::string |
| + // objects, and from string constants. |
| + // |
| + // The compiler synthesised copy constructor and assignment operator are |
| + // sufficient for our needs. |
| + ObjectPath() {} |
| + 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
|
| + 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
|
| + |
| + // 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
|
| + const std::string& value() const { return value_; } |
| + 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
|
| + private: |
| + std::string value_; |
| +}; |
| + |
| +// Permit sufficient comparison to allow an ObjectPath to be used as a |
| +// key in a std::map. |
| +bool operator<(const ObjectPath&, const ObjectPath&); |
| + |
| +// Permit testing for equality, required for mocks to work and useful for |
| +// observers. |
| +bool operator==(const ObjectPath&, const ObjectPath&); |
| +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
|
| + |
| +// Permit direct outputting on streams, for logging and debugging. |
| +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
|
| + |
| +} // namespace dbus |
| + |
| +#endif // DBUS_OBJECT_PATH_H_ |