Added ArrayIndexPath, a small class storing a index list for identifying an
element in a multi-dimensional array, featuring conversion from and to string. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33393 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
8ad4a2e971
commit
4fc4757d3d
@ -140,6 +140,7 @@ Application Debugger :
|
|||||||
X86AssemblyLanguage.cpp
|
X86AssemblyLanguage.cpp
|
||||||
|
|
||||||
# types
|
# types
|
||||||
|
ArrayIndexPath.cpp
|
||||||
TargetAddressRangeList.cpp
|
TargetAddressRangeList.cpp
|
||||||
ValueLocation.cpp
|
ValueLocation.cpp
|
||||||
|
|
||||||
|
100
src/apps/debugger/types/ArrayIndexPath.cpp
Normal file
100
src/apps/debugger/types/ArrayIndexPath.cpp
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "ArrayIndexPath.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
|
|
||||||
|
static const char kIndexSeparator = ';';
|
||||||
|
|
||||||
|
|
||||||
|
ArrayIndexPath::ArrayIndexPath()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ArrayIndexPath::ArrayIndexPath(const ArrayIndexPath& other)
|
||||||
|
:
|
||||||
|
fIndices(other.fIndices)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ArrayIndexPath::~ArrayIndexPath()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
ArrayIndexPath::SetTo(const char* path)
|
||||||
|
{
|
||||||
|
fIndices.Clear();
|
||||||
|
|
||||||
|
if (path == NULL)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
while (*path != '\0') {
|
||||||
|
char* numberEnd;
|
||||||
|
int64 index = strtoll(path, &numberEnd, 0);
|
||||||
|
if (numberEnd == path)
|
||||||
|
return false;
|
||||||
|
path = numberEnd;
|
||||||
|
|
||||||
|
if (!fIndices.Add(index))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (*path == '\0')
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (*path != kIndexSeparator)
|
||||||
|
return false;
|
||||||
|
path++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ArrayIndexPath::Clear()
|
||||||
|
{
|
||||||
|
fIndices.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
ArrayIndexPath::GetPathString(BString& path) const
|
||||||
|
{
|
||||||
|
path.Truncate(0);
|
||||||
|
|
||||||
|
int32 count = CountIndices();
|
||||||
|
for (int32 i = 0; i < count; i++) {
|
||||||
|
// append separator for all but the first index
|
||||||
|
if (i > 0) {
|
||||||
|
int32 oldLength = path.Length();
|
||||||
|
if (path.Append(kIndexSeparator, 1).Length() != oldLength + 1)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// append index
|
||||||
|
int32 oldLength = path.Length();
|
||||||
|
if ((path << IndexAt(i)).Length() == oldLength)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ArrayIndexPath&
|
||||||
|
ArrayIndexPath::operator=(const ArrayIndexPath& other)
|
||||||
|
{
|
||||||
|
fIndices = other.fIndices;
|
||||||
|
return *this;
|
||||||
|
}
|
64
src/apps/debugger/types/ArrayIndexPath.h
Normal file
64
src/apps/debugger/types/ArrayIndexPath.h
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef ARRAY_INDEX_PATH_H
|
||||||
|
#define ARRAY_INDEX_PATH_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "Array.h"
|
||||||
|
#include "Types.h"
|
||||||
|
|
||||||
|
|
||||||
|
class BString;
|
||||||
|
|
||||||
|
|
||||||
|
class ArrayIndexPath {
|
||||||
|
public:
|
||||||
|
ArrayIndexPath();
|
||||||
|
ArrayIndexPath(const ArrayIndexPath& other);
|
||||||
|
~ArrayIndexPath();
|
||||||
|
|
||||||
|
bool SetTo(const char* path);
|
||||||
|
void Clear();
|
||||||
|
|
||||||
|
bool GetPathString(BString& path) const;
|
||||||
|
|
||||||
|
inline int32 CountIndices() const;
|
||||||
|
inline int64 IndexAt(int32 index) const;
|
||||||
|
inline bool AddIndex(int64 index);
|
||||||
|
|
||||||
|
|
||||||
|
ArrayIndexPath& operator=(const ArrayIndexPath& other);
|
||||||
|
|
||||||
|
private:
|
||||||
|
typedef Array<int64> IndexArray;
|
||||||
|
|
||||||
|
private:
|
||||||
|
IndexArray fIndices;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
int32
|
||||||
|
ArrayIndexPath::CountIndices() const
|
||||||
|
{
|
||||||
|
return fIndices.Count();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int64
|
||||||
|
ArrayIndexPath::IndexAt(int32 index) const
|
||||||
|
{
|
||||||
|
return index >= 0 && index < fIndices.Count()
|
||||||
|
? fIndices.ElementAt(index) : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
ArrayIndexPath::AddIndex(int64 index)
|
||||||
|
{
|
||||||
|
return fIndices.Add(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // ARRAY_INDEX_PATH_H
|
Loading…
x
Reference in New Issue
Block a user