diff --git a/src/dobjtype.cpp b/src/dobjtype.cpp index fd856bca3..bcc68931f 100644 --- a/src/dobjtype.cpp +++ b/src/dobjtype.cpp @@ -568,6 +568,49 @@ IMPLEMENT_POINTY_CLASS(PEnum) DECLARE_POINTER(ValueType) END_POINTERS +//========================================================================== +// +// PEnum - Default Constructor +// +//========================================================================== + +PEnum::PEnum() +: ValueType(NULL) +{ +} + +//========================================================================== +// +// PEnum - Parameterized Constructor +// +//========================================================================== + +PEnum::PEnum(FName name, DObject *outer) +: PNamedType(name, outer), ValueType(NULL) +{ +} + +//========================================================================== +// +// NewEnum +// +// Returns a PEnum for the given name and container, making sure not to +// create duplicates. +// +//========================================================================== + +PEnum *NewEnum(FName name, DObject *outer) +{ + size_t bucket; + PType *etype = TypeTable.FindType(RUNTIME_CLASS(PEnum), (intptr_t)outer, (intptr_t)name, &bucket); + if (etype == NULL) + { + etype = new PEnum(name, outer); + TypeTable.AddType(etype, RUNTIME_CLASS(PEnum), (intptr_t)outer, (intptr_t)name, bucket); + } + return static_cast(etype); +} + /* PArray *****************************************************************/ IMPLEMENT_POINTY_CLASS(PArray) diff --git a/src/dobjtype.h b/src/dobjtype.h index 535b113ac..68ed6168d 100644 --- a/src/dobjtype.h +++ b/src/dobjtype.h @@ -224,6 +224,7 @@ public: FName TypeName; // this type's name PNamedType() : Outer(NULL) {} + PNamedType(FName name, DObject *outer) : Outer(outer), TypeName(name) {} virtual bool IsMatch(intptr_t id1, intptr_t id2) const; virtual void GetTypeIDs(intptr_t &id1, intptr_t &id2) const; @@ -341,8 +342,12 @@ class PEnum : public PNamedType DECLARE_CLASS(PEnum, PNamedType); HAS_OBJECT_POINTERS; public: + PEnum(FName name, DObject *outer); + PType *ValueType; TMap Values; +protected: + PEnum(); }; class PArray : public PCompoundType @@ -579,6 +584,7 @@ PDynArray *NewDynArray(PType *type); PPointer *NewPointer(PType *type); PClassPointer *NewClassPointer(PClass *restrict); PClassWaitingForParent *NewUnknownClass(FName myname, FName parentname); +PEnum *NewEnum(FName name, DObject *outer); // Built-in types -----------------------------------------------------------