EnumType.h revision 80b217fa80694377cc0ad043e2385467dae2e179
1#ifndef ENUM_TYPE_H_
2
3#define ENUM_TYPE_H_
4
5#include "NamedType.h"
6
7#include <vector>
8
9namespace android {
10
11struct EnumValue;
12
13struct EnumType : public NamedType {
14    EnumType(const char *localName,
15             std::vector<EnumValue *> *values,
16             Type *storageType = NULL);
17
18    const Type *storageType() const;
19    const std::vector<EnumValue *> &values() const;
20
21    const ScalarType *resolveToScalarType() const override;
22
23    bool isEnum() const override;
24
25    std::string getCppType(StorageMode mode, std::string *extra) const override;
26
27    std::string getJavaType() const override;
28    std::string getJavaSuffix() const override;
29
30    void emitReaderWriter(
31            Formatter &out,
32            const std::string &name,
33            const std::string &parcelObj,
34            bool parcelObjIsPointer,
35            bool isReader,
36            ErrorMode mode) const override;
37
38    status_t emitTypeDeclarations(Formatter &out) const override;
39    status_t emitJavaTypeDeclarations(Formatter &out) const override;
40
41    status_t emitVtsTypeDeclarations(Formatter &out) const override;
42    status_t emitVtsAttributeType(Formatter &out) const override;
43
44private:
45    void getTypeChain(std::vector<const EnumType *> *out) const;
46    std::vector<EnumValue *> *mValues;
47    Type *mStorageType;
48
49    DISALLOW_COPY_AND_ASSIGN(EnumType);
50};
51
52struct EnumValue {
53    EnumValue(const char *name, const char *value = NULL);
54
55    std::string name() const;
56    const char *value() const;
57
58private:
59    std::string mName;
60    const char *mValue;
61
62    DISALLOW_COPY_AND_ASSIGN(EnumValue);
63};
64
65}  // namespace android
66
67#endif  // ENUM_TYPE_H_
68
69