xref: /haiku/headers/private/debugger/model/TypeComponentPath.h (revision fce4895d1884da5ae6fb299d23c735c598e690b1)
1 /*
2  * Copyright 2009-2012, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef TYPE_COMPONENT_PATH_H
6 #define TYPE_COMPONENT_PATH_H
7 
8 
9 #include <String.h>
10 
11 #include <ObjectList.h>
12 #include <Referenceable.h>
13 
14 #include "ArrayIndexPath.h"
15 #include "Type.h"
16 
17 
18 enum type_component_kind {
19 	TYPE_COMPONENT_UNDEFINED,
20 	TYPE_COMPONENT_BASE_TYPE,
21 	TYPE_COMPONENT_DATA_MEMBER,
22 	TYPE_COMPONENT_ARRAY_ELEMENT
23 };
24 
25 
26 struct TypeComponent {
27 	uint64				index;
28 	BString				name;
29 	type_component_kind	componentKind;
30 	type_kind			typeKind;
31 
TypeComponentTypeComponent32 	TypeComponent()
33 		:
34 		componentKind(TYPE_COMPONENT_UNDEFINED)
35 
36 	{
37 	}
38 
TypeComponentTypeComponent39 	TypeComponent(const TypeComponent& other)
40 		:
41 		index(other.index),
42 		name(other.name),
43 		componentKind(other.componentKind),
44 		typeKind(other.typeKind)
45 
46 	{
47 	}
48 
IsValidTypeComponent49 	bool IsValid() const
50 	{
51 		return componentKind != TYPE_COMPONENT_UNDEFINED;
52 	}
53 
54 	void SetToBaseType(type_kind typeKind, uint64 index = 0,
55 		const BString& name = BString())
56 	{
57 		this->componentKind = TYPE_COMPONENT_BASE_TYPE;
58 		this->typeKind = typeKind;
59 		this->index = index;
60 		this->name = name;
61 	}
62 
SetToDataMemberTypeComponent63 	void SetToDataMember(type_kind typeKind, uint64 index,
64 		const BString& name)
65 	{
66 		this->componentKind = TYPE_COMPONENT_DATA_MEMBER;
67 		this->typeKind = typeKind;
68 		this->index = index;
69 		this->name = name;
70 	}
71 
SetToArrayElementTypeComponent72 	void SetToArrayElement(type_kind typeKind, const BString& indexPath)
73 	{
74 		this->componentKind = TYPE_COMPONENT_ARRAY_ELEMENT;
75 		this->typeKind = typeKind;
76 		this->index = 0;
77 		this->name = indexPath;
78 	}
79 
SetToArrayElementTypeComponent80 	bool SetToArrayElement(type_kind typeKind, const ArrayIndexPath& indexPath)
81 	{
82 		this->componentKind = TYPE_COMPONENT_ARRAY_ELEMENT;
83 		this->typeKind = typeKind;
84 		this->index = 0;
85 		return indexPath.GetPathString(this->name);
86 	}
87 
88 	bool HasPrefix(const TypeComponent& other) const;
89 
90 	uint32 HashValue() const;
91 
92 	void Dump() const;
93 
94 	TypeComponent& operator=(const TypeComponent& other)
95 
96 	{
97 		index = other.index;
98 		name = other.name;
99 		componentKind = other.componentKind;
100 		typeKind = other.typeKind;
101 		return *this;
102 	}
103 
104 	bool operator==(const TypeComponent& other) const;
105 
106 	bool operator!=(const TypeComponent& other) const
107 	{
108 		return !(*this == other);
109 	}
110 };
111 
112 
113 class TypeComponentPath : public BReferenceable {
114 public:
115 								TypeComponentPath();
116 								TypeComponentPath(
117 									const TypeComponentPath& other);
118 	virtual						~TypeComponentPath();
119 
120 			int32				CountComponents() const;
121 			TypeComponent		ComponentAt(int32 index) const;
122 
123 			bool				AddComponent(const TypeComponent& component);
124 			void				Clear();
125 
126 			TypeComponentPath*	CreateSubPath(int32 componentCount) const;
127 									// returns a new object (or NULL when out
128 									// of memory)
129 
130 			uint32				HashValue() const;
131 
132 			void				Dump() const;
133 
134 			TypeComponentPath&	operator=(const TypeComponentPath& other);
135 
136 			bool operator==(const TypeComponentPath& other) const;
137 			bool operator!=(const TypeComponentPath& other) const
138 									{ return !(*this == other); }
139 
140 private:
141 			typedef BObjectList<TypeComponent> ComponentList;
142 
143 private:
144 			ComponentList		fComponents;
145 };
146 
147 
148 #endif	// TYPE_COMPONENT_PATH_H
149