2 * Copyright 2009-2012, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
5 #ifndef TYPE_COMPONENT_PATH_H
6 #define TYPE_COMPONENT_PATH_H
11 #include <ObjectList.h>
12 #include <Referenceable.h>
14 #include "ArrayIndexPath.h"
18 enum type_component_kind
{
19 TYPE_COMPONENT_UNDEFINED
,
20 TYPE_COMPONENT_BASE_TYPE
,
21 TYPE_COMPONENT_DATA_MEMBER
,
22 TYPE_COMPONENT_ARRAY_ELEMENT
26 struct TypeComponent
{
29 type_component_kind componentKind
;
34 componentKind(TYPE_COMPONENT_UNDEFINED
)
39 TypeComponent(const TypeComponent
& other
)
43 componentKind(other
.componentKind
),
44 typeKind(other
.typeKind
)
51 return componentKind
!= TYPE_COMPONENT_UNDEFINED
;
54 void SetToBaseType(type_kind typeKind
, uint64 index
= 0,
55 const BString
& name
= BString())
57 this->componentKind
= TYPE_COMPONENT_BASE_TYPE
;
58 this->typeKind
= typeKind
;
63 void SetToDataMember(type_kind typeKind
, uint64 index
,
66 this->componentKind
= TYPE_COMPONENT_DATA_MEMBER
;
67 this->typeKind
= typeKind
;
72 void SetToArrayElement(type_kind typeKind
, const BString
& indexPath
)
74 this->componentKind
= TYPE_COMPONENT_ARRAY_ELEMENT
;
75 this->typeKind
= typeKind
;
77 this->name
= indexPath
;
80 bool SetToArrayElement(type_kind typeKind
, const ArrayIndexPath
& indexPath
)
82 this->componentKind
= TYPE_COMPONENT_ARRAY_ELEMENT
;
83 this->typeKind
= typeKind
;
85 return indexPath
.GetPathString(this->name
);
88 bool HasPrefix(const TypeComponent
& other
) const;
90 uint32
HashValue() const;
94 TypeComponent
& operator=(const TypeComponent
& other
)
99 componentKind
= other
.componentKind
;
100 typeKind
= other
.typeKind
;
104 bool operator==(const TypeComponent
& other
) const;
106 bool operator!=(const TypeComponent
& other
) const
108 return !(*this == other
);
113 class TypeComponentPath
: public BReferenceable
{
117 const TypeComponentPath
& other
);
118 virtual ~TypeComponentPath();
120 int32
CountComponents() const;
121 TypeComponent
ComponentAt(int32 index
) const;
123 bool AddComponent(const TypeComponent
& component
);
126 TypeComponentPath
* CreateSubPath(int32 componentCount
) const;
127 // returns a new object (or NULL when out
130 uint32
HashValue() const;
134 TypeComponentPath
& operator=(const TypeComponentPath
& other
);
136 bool operator==(const TypeComponentPath
& other
) const;
137 bool operator!=(const TypeComponentPath
& other
) const
138 { return !(*this == other
); }
141 typedef BObjectList
<TypeComponent
> ComponentList
;
144 ComponentList fComponents
;
148 #endif // TYPE_COMPONENT_PATH_H