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 14class BString; 15 16 17class ArrayIndexPath { 18public: 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 35private: 36 typedef Array<int64> IndexArray; 37 38private: 39 IndexArray fIndices; 40}; 41 42 43int32 44ArrayIndexPath::CountIndices() const 45{ 46 return fIndices.Count(); 47} 48 49 50int64 51ArrayIndexPath::IndexAt(int32 index) const 52{ 53 return index >= 0 && index < fIndices.Count() 54 ? fIndices.ElementAt(index) : -1; 55} 56 57 58bool 59ArrayIndexPath::AddIndex(int64 index) 60{ 61 return fIndices.Add(index); 62} 63 64 65void 66ArrayIndexPath::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