blob: 939cd3b05f2eda88ae2bd72f66dda5bc33d44bad [file] [log] [blame]
Andreas Huberc9410c72016-07-28 12:18:40 -07001#ifndef ENUM_TYPE_H_
2
3#define ENUM_TYPE_H_
4
5#include "NamedType.h"
6
Andreas Huber881227d2016-08-02 14:20:21 -07007#include <vector>
Andreas Huberc9410c72016-07-28 12:18:40 -07008
9namespace android {
10
Andreas Huber31629bc2016-08-03 09:06:40 -070011struct EnumValue;
Andreas Huberc9410c72016-07-28 12:18:40 -070012
13struct EnumType : public NamedType {
Andreas Huber31629bc2016-08-03 09:06:40 -070014 EnumType(std::vector<EnumValue *> *values,
Andreas Huberc9410c72016-07-28 12:18:40 -070015 Type *storageType = NULL);
16
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070017 const Type *storageType() const;
18 const std::vector<EnumValue *> &values() const;
19
Andreas Huber737080b2016-08-02 15:38:04 -070020 const ScalarType *resolveToScalarType() const override;
21
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070022 bool isEnum() const override;
23
Andreas Huber881227d2016-08-02 14:20:21 -070024 std::string getCppType(StorageMode mode, std::string *extra) const override;
25
26 void emitReaderWriter(
27 Formatter &out,
28 const std::string &name,
29 const std::string &parcelObj,
30 bool parcelObjIsPointer,
31 bool isReader,
32 ErrorMode mode) const override;
33
34 status_t emitTypeDeclarations(Formatter &out) const override;
35
Andreas Huberc9410c72016-07-28 12:18:40 -070036private:
Andreas Huber881227d2016-08-02 14:20:21 -070037 std::vector<EnumValue *> *mValues;
Andreas Huberc9410c72016-07-28 12:18:40 -070038 Type *mStorageType;
39
40 DISALLOW_COPY_AND_ASSIGN(EnumType);
41};
42
Andreas Huber31629bc2016-08-03 09:06:40 -070043struct EnumValue {
44 EnumValue(const char *name, const char *value = NULL);
45
46 std::string name() const;
47 const char *value() const;
48
49private:
50 std::string mName;
51 const char *mValue;
52
53 DISALLOW_COPY_AND_ASSIGN(EnumValue);
54};
55
Andreas Huberc9410c72016-07-28 12:18:40 -070056} // namespace android
57
58#endif // ENUM_TYPE_H_
59