1 /*
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 
17 #ifndef ANNOTATION_H_
18 
19 #define ANNOTATION_H_
20 
21 #include <android-base/macros.h>
22 #include <map>
23 #include <string>
24 
25 #include "ConstantExpression.h"
26 
27 namespace android {
28 
29 struct Formatter;
30 
31 struct AnnotationParam {
32     AnnotationParam(const std::string &name,
33                     std::vector<std::string> *values);
34     AnnotationParam(const std::string &name,
35                     std::vector<ConstantExpression *> *values);
36 
37     const std::string &getName() const;
38     const std::vector<std::string> *getValues() const;
39 
40     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 
48 private:
49     const std::string mName;
50     std::vector<std::string> *mValues;
51 };
52 
53 using AnnotationParamVector = std::vector<const AnnotationParam*>;
54 
55 struct Annotation {
56     Annotation(const char *name, AnnotationParamVector *params);
57 
58     std::string name() const;
59     const AnnotationParamVector &params() const;
60     const AnnotationParam *getParam(const std::string &name) const;
61 
62     void dump(Formatter &out) const;
63 
64 private:
65     std::string mName;
66     AnnotationParamVector *mParams;
67 
68     DISALLOW_COPY_AND_ASSIGN(Annotation);
69 };
70 
71 }  // namespace android
72 
73 #endif  // ANNOTATION_H_
74