• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <vector>
25 
26 namespace android {
27 
28 struct Formatter;
29 
30 struct AnnotationParam {
~AnnotationParamAnnotationParam31     virtual ~AnnotationParam() {}
32 
33     const std::string& getName() const;
34 
35     virtual std::vector<std::string> getValues() const = 0;
36     virtual std::string getSingleValue() const = 0;
37 
38     /* Returns unquoted version of getSingleValue */
39     std::string getSingleString() const;
40 
41     /* Returns value interpretted as a boolean */
42     bool getSingleBool() const;
43 
44    protected:
45     const std::string mName;
46 
47     AnnotationParam(const std::string& name);
48 };
49 
50 struct StringAnnotationParam : AnnotationParam {
51     StringAnnotationParam(const std::string& name, std::vector<std::string>* values);
52 
53     std::vector<std::string> getValues() const override;
54     std::string getSingleValue() const override;
55 
56    private:
57     std::vector<std::string>* const mValues;
58 };
59 
60 using AnnotationParamVector = std::vector<AnnotationParam*>;
61 
62 struct Annotation {
63     Annotation(const std::string& name, AnnotationParamVector* params);
64 
65     std::string name() const;
66     const AnnotationParamVector &params() const;
67     const AnnotationParam *getParam(const std::string &name) const;
68 
69     void dump(Formatter &out) const;
70 
71    private:
72     std::string mName;
73     AnnotationParamVector *mParams;
74 
75     DISALLOW_COPY_AND_ASSIGN(Annotation);
76 };
77 
78 }  // namespace android
79 
80 #endif  // ANNOTATION_H_
81