1 // Copyright 2014 The Chromium OS 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 CHROMEOS_DBUS_BINDINGS_NAME_PARSER_H_ 6 #define CHROMEOS_DBUS_BINDINGS_NAME_PARSER_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include <base/macros.h> 12 13 namespace chromeos_dbus_bindings { 14 15 struct Interface; 16 class IndentedText; 17 18 // A helper class that allows to decompose D-Bus name strings such as 19 // "org.chromium.TestInterface" into components and be able to construct the 20 // corresponding C++ identifiers, namespaces, variable names, etc. 21 class NameParser { 22 public: 23 explicit NameParser(const std::string& name); 24 25 // Returns fully-qualified C++ type name for the current D-Bus name 26 // for example "org::chromium::TestInterface". 27 std::string MakeFullCppName() const; 28 29 // Returns a variable name suitable for object of this type. 30 // For example "test_interface". 31 std::string MakeVariableName() const; 32 33 // Returns a name of an interface for the given type, optionally qualifying 34 // it with the C++ namespaces. 35 std::string MakeInterfaceName(bool fully_qualified) const; 36 37 // Returns a name of a proxy class for the given type, optionally qualifying 38 // it with the C++ namespaces. 39 std::string MakeProxyName(bool fully_qualified) const; 40 41 // Returns a name of an adaptor class for the given type, optionally 42 // qualifying it with the C++ namespaces. 43 std::string MakeAdaptorName(bool fully_qualified) const; 44 45 // Adds opening "namespace ... {" statements to |text|. 46 // If |add_main_type| is true, adds the main type name as a namespace as well. 47 void AddOpenNamespaces(IndentedText *text, bool add_main_type) const; 48 49 // Adds closing "} // namespace ..." statements to |text|. 50 // If |add_main_type| is true, adds the main type name as a namespace as well. 51 void AddCloseNamespaces(IndentedText *text, bool add_main_type) const; 52 53 std::string type_name; // e.g. "TestInterface". 54 std::vector<std::string> namespaces; // e.g. {"org", "chromium"}. 55 56 private: 57 // Helper function to prepend the C++ namespaces to the |name|. 58 std::string MakeFullyQualified(const std::string& name) const; 59 }; 60 61 } // namespace chromeos_dbus_bindings 62 63 #endif // CHROMEOS_DBUS_BINDINGS_NAME_PARSER_H_ 64