blob: 18d9ab03c81eac81b653b1eca7a573bd99e0f79d [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#ifndef ANNOTATION_H_
18
19#define ANNOTATION_H_
20
21#include <android-base/macros.h>
Steven Morelandd537ab02016-09-12 10:32:01 -070022#include <map>
Andreas Huber3599d922016-08-09 10:42:57 -070023#include <string>
Andreas Huber3599d922016-08-09 10:42:57 -070024
Yifan Hongf24fa852016-09-23 11:03:15 -070025#include "ConstantExpression.h"
26
Andreas Huber3599d922016-08-09 10:42:57 -070027namespace android {
28
29struct Formatter;
Steven Morelandd537ab02016-09-12 10:32:01 -070030
31struct AnnotationParam {
32 AnnotationParam(const std::string &name,
33 std::vector<std::string> *values);
Yifan Hongf24fa852016-09-23 11:03:15 -070034 AnnotationParam(const std::string &name,
35 std::vector<ConstantExpression *> *values);
Steven Morelandd537ab02016-09-12 10:32:01 -070036
37 const std::string &getName() const;
38 const std::vector<std::string> *getValues() const;
39
Steven Morelanddb1b1b62017-01-10 09:50:55 -080040 const std::string &getSingleValue() const;
41
42 /* Returns unquoted version of getSingleValue */
43 std::string getSingleString() const;
44
45 /* Returns value interpretted as a boolean */
46 bool getSingleBool() const;
47
Steven Morelandd537ab02016-09-12 10:32:01 -070048private:
49 const std::string mName;
50 std::vector<std::string> *mValues;
51};
52
53using AnnotationParamVector = std::vector<const AnnotationParam*>;
Andreas Huber3599d922016-08-09 10:42:57 -070054
55struct Annotation {
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070056 Annotation(const char *name, AnnotationParamVector *params);
Andreas Huber3599d922016-08-09 10:42:57 -070057
58 std::string name() const;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070059 const AnnotationParamVector &params() const;
Andreas Huber019d21d2016-10-03 12:59:47 -070060 const AnnotationParam *getParam(const std::string &name) const;
Andreas Huber3599d922016-08-09 10:42:57 -070061
62 void dump(Formatter &out) const;
63
64private:
65 std::string mName;
Steven Morelandd537ab02016-09-12 10:32:01 -070066 AnnotationParamVector *mParams;
Andreas Huber3599d922016-08-09 10:42:57 -070067
68 DISALLOW_COPY_AND_ASSIGN(Annotation);
69};
70
71} // namespace android
72
73#endif // ANNOTATION_H_