blob: 1a4ee1d379b9a0813a0383138faf4f468fea285c [file] [log] [blame]
Andreas Huber1aec3972016-08-26 09:26:32 -07001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Andreas Huber84f89de2016-07-28 15:39:51 -070017#ifndef FQNAME_H_
18
19#define FQNAME_H_
20
21#include <android-base/macros.h>
22#include <string>
Andreas Huber0e00de42016-08-03 09:56:02 -070023#include <vector>
Andreas Huber84f89de2016-07-28 15:39:51 -070024
25namespace android {
26
27struct FQName {
Andreas Huberda51b8e2016-07-28 16:00:57 -070028 explicit FQName();
Andreas Huber84f89de2016-07-28 15:39:51 -070029 explicit FQName(const std::string &s);
30
Andreas Huber68f24592016-07-29 14:53:48 -070031 FQName(const std::string &package,
32 const std::string &version,
Yifan Hongb44a6c82016-09-22 15:50:18 -070033 const std::string &name,
34 const std::string &valueName = "");
Andreas Huber68f24592016-07-29 14:53:48 -070035
Andreas Huber84f89de2016-07-28 15:39:51 -070036 bool isValid() const;
Yifan Hongb44a6c82016-09-22 15:50:18 -070037 bool isIdentifier() const;
Andreas Huber84f89de2016-07-28 15:39:51 -070038 bool setTo(const std::string &s);
39
40 void applyDefaults(
41 const std::string &defaultPackage,
42 const std::string &defaultVersion);
43
44 std::string package() const;
45 std::string version() const;
Iliyan Malchev800273d2016-09-02 15:25:07 -070046
47 // The next two methods return the name part of the FQName, that is, the
48 // part after the version field. For example:
49 //
50 // package android.hardware.tests.foo@1.0;
51 // interface IFoo {
52 // struct bar {
53 // struct baz {
54 // ...
55 // };
56 // };
57 // };
58 //
59 // package android.hardware.tests.bar@1.0;
60 // import android.hardware.tests.foo@1.0;
61 // interface {
62 // struct boo {
63 // IFoo.bar.baz base;
64 // };
65 // }
66 //
67 // The FQName for base is android.hardware.tests.foo@1.0::IFoo.bar.baz; so
68 // FQName::name() will return "IFoo.bar.baz". FQName::names() will return
69 // std::vector<std::string>{"IFoo","bar","baz"}
70
Andreas Huber84f89de2016-07-28 15:39:51 -070071 std::string name() const;
Iliyan Malchev800273d2016-09-02 15:25:07 -070072 std::vector<std::string> names() const;
Andreas Huber84f89de2016-07-28 15:39:51 -070073
Yifan Hongb44a6c82016-09-22 15:50:18 -070074 // The next two methods returns two parts of the FQName, that is,
75 // the first part package + version + name, the second part valueName.
76 FQName typeName() const;
77 std::string valueName() const;
78
Andreas Huber68f24592016-07-29 14:53:48 -070079 bool isFullyQualified() const;
80
Yifan Hongb44a6c82016-09-22 15:50:18 -070081 // true if:
82 // 1. (package)?(version)?(name):(valueName)
83 // 2. (valueName), aka a single identifier
84 bool isValidValueName() const;
85
Andreas Huberda51b8e2016-07-28 16:00:57 -070086 void print() const;
Andreas Huber68f24592016-07-29 14:53:48 -070087 std::string string() const;
88
89 bool operator<(const FQName &other) const;
Andreas Huberd2943e12016-08-05 11:59:31 -070090 bool operator==(const FQName &other) const;
Andreas Huber84f89de2016-07-28 15:39:51 -070091
Steven Moreland197d56c2016-09-09 10:03:58 -070092 // Must be called on an interface
93 // ::android::hardware::Foo::V1_0::IBar
94 // -> Bar
95 std::string getInterfaceBaseName() const;
96
Steven Moreland9c387612016-09-07 09:54:26 -070097 // the following comments all assume that the FQName
98 // is ::android::hardware::Foo::V1_0::IBar::Baz
99
100 // returns highest type in the hidl namespace, i.e.
101 // ::android::hardware::Foo::V1_0::IBar
102 const FQName getTopLevelType() const;
103
104 // returns an unambiguous fully qualified name which can be
105 // baked into a token, i.e.
106 // android_hardware_Foo_V1_0_IBar_Baz
107 std::string tokenName() const;
108
Andreas Huber0e00de42016-08-03 09:56:02 -0700109 // Returns an absolute C++ namespace prefix, i.e.
Andreas Huber2831d512016-08-15 09:33:47 -0700110 // ::android::hardware::Foo::V1_0.
Andreas Huber0e00de42016-08-03 09:56:02 -0700111 std::string cppNamespace() const;
112
Steven Moreland979e0992016-09-07 09:18:08 -0700113 // Returns a name qualified assuming we are in cppNamespace, i.e.
114 // IBar::Baz.
115 std::string cppLocalName() const;
116
Andreas Huber0e00de42016-08-03 09:56:02 -0700117 // Returns a fully qualified absolute C++ type name, i.e.
Steven Moreland9c387612016-09-07 09:54:26 -0700118 // ::android::hardware::Foo::V1_0::IBar::Baz.
Andreas Huber0e00de42016-08-03 09:56:02 -0700119 std::string cppName() const;
120
Andreas Huber2831d512016-08-15 09:33:47 -0700121 // Returns the java package name, i.e. "android.hardware.Foo.V1_0".
122 std::string javaPackage() const;
123
124 // Returns the fully qualified java type name,
Steven Moreland9c387612016-09-07 09:54:26 -0700125 // i.e. "android.hardware.Foo.V1_0.IBar.Baz"
Andreas Huber2831d512016-08-15 09:33:47 -0700126 std::string javaName() const;
127
Andreas Huber39fa7182016-08-19 14:27:33 -0700128 bool endsWith(const FQName &other) const;
129
Andreas Huber0e00de42016-08-03 09:56:02 -0700130 void getPackageComponents(std::vector<std::string> *components) const;
131
132 void getPackageAndVersionComponents(
133 std::vector<std::string> *components,
134 bool cpp_compatible) const;
135
Martijn Coenena21f1492016-09-08 15:55:14 +0200136 std::string getPackageMajorVersion() const;
137
138 std::string getPackageMinorVersion() const;
Steven Moreland197d56c2016-09-09 10:03:58 -0700139
Andreas Huber84f89de2016-07-28 15:39:51 -0700140private:
Yifan Hongb44a6c82016-09-22 15:50:18 -0700141 bool mValid, mIsIdentifier;
Andreas Huber84f89de2016-07-28 15:39:51 -0700142 std::string mPackage;
143 std::string mVersion;
144 std::string mName;
Yifan Hongb44a6c82016-09-22 15:50:18 -0700145 std::string mValueName;
Andreas Huber84f89de2016-07-28 15:39:51 -0700146};
147
148} // namespace android
149
150#endif // FQNAME_H_