xref: /haiku/headers/private/debugger/types/ArrayIndexPath.h (revision fce4895d1884da5ae6fb299d23c735c598e690b1)
1 /*
2  * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef ARRAY_INDEX_PATH_H
6 #define ARRAY_INDEX_PATH_H
7 
8 
9 #include <Array.h>
10 
11 #include "Types.h"
12 
13 
14 class BString;
15 
16 
17 class ArrayIndexPath {
18 public:
19 								ArrayIndexPath();
20 								ArrayIndexPath(const ArrayIndexPath& other);
21 								~ArrayIndexPath();
22 
23 			status_t			SetTo(const char* path);
24 			void				Clear();
25 
26 			bool				GetPathString(BString& path) const;
27 
28 	inline	int32				CountIndices() const;
29 	inline	int64				IndexAt(int32 index) const;
30 	inline	bool				AddIndex(int64 index);
31 	inline	void				SetIndexAt(int32 at, int64 newIndex);
32 
33 			ArrayIndexPath&		operator=(const ArrayIndexPath& other);
34 
35 private:
36 			typedef Array<int64> IndexArray;
37 
38 private:
39 			IndexArray			fIndices;
40 };
41 
42 
43 int32
CountIndices()44 ArrayIndexPath::CountIndices() const
45 {
46 	return fIndices.Count();
47 }
48 
49 
50 int64
IndexAt(int32 index)51 ArrayIndexPath::IndexAt(int32 index) const
52 {
53 	return index >= 0 && index < fIndices.Count()
54 		? fIndices.ElementAt(index) : -1;
55 }
56 
57 
58 bool
AddIndex(int64 index)59 ArrayIndexPath::AddIndex(int64 index)
60 {
61 	return fIndices.Add(index);
62 }
63 
64 
65 void
SetIndexAt(int32 at,int64 newIndex)66 ArrayIndexPath::SetIndexAt(int32 at, int64 newIndex)
67 {
68 	if (at >= 0 && at < fIndices.Count())
69 		fIndices[at] = newIndex;
70 }
71 
72 
73 #endif	// ARRAY_INDEX_PATH_H
74