EnumType.h revision 1aec397b1fdea7db4120dbe55b6995bb2a9d9138
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 ENUM_TYPE_H_
18
19#define ENUM_TYPE_H_
20
21#include "NamedType.h"
22
23#include <vector>
24
25namespace android {
26
27struct EnumValue;
28
29struct EnumType : public NamedType {
30    EnumType(const char *localName,
31             std::vector<EnumValue *> *values,
32             Type *storageType = NULL);
33
34    const Type *storageType() const;
35    const std::vector<EnumValue *> &values() const;
36
37    const ScalarType *resolveToScalarType() const override;
38
39    bool isEnum() const override;
40
41    std::string getCppType(StorageMode mode, std::string *extra) const override;
42
43    std::string getJavaType() const override;
44    std::string getJavaSuffix() const override;
45
46    void emitReaderWriter(
47            Formatter &out,
48            const std::string &name,
49            const std::string &parcelObj,
50            bool parcelObjIsPointer,
51            bool isReader,
52            ErrorMode mode) const override;
53
54    void emitJavaFieldReaderWriter(
55            Formatter &out,
56            const std::string &blobName,
57            const std::string &fieldName,
58            const std::string &offset,
59            bool isReader) const override;
60
61    status_t emitTypeDeclarations(Formatter &out) const override;
62
63    status_t emitJavaTypeDeclarations(
64            Formatter &out, bool atTopLevel) const override;
65
66    status_t emitVtsTypeDeclarations(Formatter &out) const override;
67    status_t emitVtsAttributeType(Formatter &out) const override;
68
69    void getAlignmentAndSize(size_t *align, size_t *size) const override;
70
71private:
72    void getTypeChain(std::vector<const EnumType *> *out) const;
73    std::vector<EnumValue *> *mValues;
74    Type *mStorageType;
75
76    DISALLOW_COPY_AND_ASSIGN(EnumType);
77};
78
79struct EnumValue {
80    EnumValue(const char *name, const char *value = NULL);
81
82    std::string name() const;
83    const char *value() const;
84
85private:
86    std::string mName;
87    const char *mValue;
88
89    DISALLOW_COPY_AND_ASSIGN(EnumValue);
90};
91
92}  // namespace android
93
94#endif  // ENUM_TYPE_H_
95
96