vfs: check userland buffers before reading them.
[haiku.git] / headers / private / debugger / model / TypeComponentPath.h
blob0ded421df1d151bff321d182d1a6f0077bd1a562
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
9 #include <String.h>
11 #include <ObjectList.h>
12 #include <Referenceable.h>
14 #include "ArrayIndexPath.h"
15 #include "Type.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 {
27 uint64 index;
28 BString name;
29 type_component_kind componentKind;
30 type_kind typeKind;
32 TypeComponent()
34 componentKind(TYPE_COMPONENT_UNDEFINED)
39 TypeComponent(const TypeComponent& other)
41 index(other.index),
42 name(other.name),
43 componentKind(other.componentKind),
44 typeKind(other.typeKind)
49 bool IsValid() const
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;
59 this->index = index;
60 this->name = name;
63 void SetToDataMember(type_kind typeKind, uint64 index,
64 const BString& name)
66 this->componentKind = TYPE_COMPONENT_DATA_MEMBER;
67 this->typeKind = typeKind;
68 this->index = index;
69 this->name = name;
72 void SetToArrayElement(type_kind typeKind, const BString& indexPath)
74 this->componentKind = TYPE_COMPONENT_ARRAY_ELEMENT;
75 this->typeKind = typeKind;
76 this->index = 0;
77 this->name = indexPath;
80 bool SetToArrayElement(type_kind typeKind, const ArrayIndexPath& indexPath)
82 this->componentKind = TYPE_COMPONENT_ARRAY_ELEMENT;
83 this->typeKind = typeKind;
84 this->index = 0;
85 return indexPath.GetPathString(this->name);
88 bool HasPrefix(const TypeComponent& other) const;
90 uint32 HashValue() const;
92 void Dump() const;
94 TypeComponent& operator=(const TypeComponent& other)
97 index = other.index;
98 name = other.name;
99 componentKind = other.componentKind;
100 typeKind = other.typeKind;
101 return *this;
104 bool operator==(const TypeComponent& other) const;
106 bool operator!=(const TypeComponent& other) const
108 return !(*this == other);
113 class TypeComponentPath : public BReferenceable {
114 public:
115 TypeComponentPath();
116 TypeComponentPath(
117 const TypeComponentPath& other);
118 virtual ~TypeComponentPath();
120 int32 CountComponents() const;
121 TypeComponent ComponentAt(int32 index) const;
123 bool AddComponent(const TypeComponent& component);
124 void Clear();
126 TypeComponentPath* CreateSubPath(int32 componentCount) const;
127 // returns a new object (or NULL when out
128 // of memory)
130 uint32 HashValue() const;
132 void Dump() 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); }
140 private:
141 typedef BObjectList<TypeComponent> ComponentList;
143 private:
144 ComponentList fComponents;
148 #endif // TYPE_COMPONENT_PATH_H