blob: 40f3ae1874d202a16278cafc9260378c8d3c11a4 [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,
33 const std::string &name);
34
Andreas Huber84f89de2016-07-28 15:39:51 -070035 bool isValid() const;
36 bool setTo(const std::string &s);
37
38 void applyDefaults(
39 const std::string &defaultPackage,
40 const std::string &defaultVersion);
41
42 std::string package() const;
43 std::string version() const;
44 std::string name() const;
45
Andreas Huber68f24592016-07-29 14:53:48 -070046 bool isFullyQualified() const;
47
Andreas Huberda51b8e2016-07-28 16:00:57 -070048 void print() const;
Andreas Huber68f24592016-07-29 14:53:48 -070049 std::string string() const;
50
51 bool operator<(const FQName &other) const;
Andreas Huberd2943e12016-08-05 11:59:31 -070052 bool operator==(const FQName &other) const;
Andreas Huber84f89de2016-07-28 15:39:51 -070053
Andreas Huber0e00de42016-08-03 09:56:02 -070054 // Returns an absolute C++ namespace prefix, i.e.
Andreas Huber2831d512016-08-15 09:33:47 -070055 // ::android::hardware::Foo::V1_0.
Andreas Huber0e00de42016-08-03 09:56:02 -070056 std::string cppNamespace() const;
57
58 // Returns a fully qualified absolute C++ type name, i.e.
Andreas Huber2831d512016-08-15 09:33:47 -070059 // ::android::hardware::Foo::V1_0::bar::baz.
Andreas Huber0e00de42016-08-03 09:56:02 -070060 std::string cppName() const;
61
Andreas Huber2831d512016-08-15 09:33:47 -070062 // Returns the java package name, i.e. "android.hardware.Foo.V1_0".
63 std::string javaPackage() const;
64
65 // Returns the fully qualified java type name,
66 // i.e. "android.hardware.Foo.V1_0.IBar"
67 std::string javaName() const;
68
Andreas Huber39fa7182016-08-19 14:27:33 -070069 bool endsWith(const FQName &other) const;
70
Andreas Huber0e00de42016-08-03 09:56:02 -070071 void getPackageComponents(std::vector<std::string> *components) const;
72
73 void getPackageAndVersionComponents(
74 std::vector<std::string> *components,
75 bool cpp_compatible) const;
76
Andreas Huberd2943e12016-08-05 11:59:31 -070077 static std::string JoinStrings(
78 const std::vector<std::string> &components,
79 const std::string &separator);
80
Andreas Huber84f89de2016-07-28 15:39:51 -070081private:
82 bool mValid;
83 std::string mPackage;
84 std::string mVersion;
85 std::string mName;
Andreas Huber84f89de2016-07-28 15:39:51 -070086};
87
88} // namespace android
89
90#endif // FQNAME_H_