blob: b1d496fe6a3da21b41d4dd711c6841767cc666c4 [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 Huber3599d922016-08-09 10:42:57 -070017#include "Annotation.h"
18
Iliyan Malcheva72e0d22016-09-09 11:03:08 -070019#include <hidl-util/Formatter.h>
Andreas Huber3599d922016-08-09 10:42:57 -070020#include <vector>
21
22namespace android {
23
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070024Annotation::Annotation(const char *name,AnnotationParamVector *params)
25 : mName(name),
26 mParamsByName(params) {
Andreas Huber3599d922016-08-09 10:42:57 -070027}
28
29std::string Annotation::name() const {
30 return mName;
31}
32
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070033const AnnotationParamVector &Annotation::params() const {
34 return *mParamsByName;
35}
36
Andreas Huber3599d922016-08-09 10:42:57 -070037void Annotation::dump(Formatter &out) const {
38 out << "@" << mName;
39
40 if (mParamsByName->size() == 0) {
41 return;
42 }
43
44 out << "(";
45
46 for (size_t i = 0; i < mParamsByName->size(); ++i) {
47 if (i > 0) {
48 out << ", ";
49 }
50
51 out << mParamsByName->keyAt(i) << "=";
52
53 const std::vector<std::string> *param = mParamsByName->valueAt(i);
54 if (param->size() > 1) {
55 out << "{";
56 }
57
58 bool first = true;
59 for (const auto &value : *param) {
60 if (!first) {
61 out << ", ";
62 }
63
64 out << value;
65
66 first = false;
67 }
68
69 if (param->size() > 1) {
70 out << "}";
71 }
72 }
73
74 out << ")";
75}
76
77} // namespace android
78