From 9395c27062f50a51dc5e3c58a2557dcab17636fb Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sat, 2 Jul 2011 18:06:40 +0200 Subject: [PATCH] Move Debugger's Array class to headers/shared --- .../util => headers/private/shared}/Array.h | 73 +++++++++++-------- src/apps/debugger/arch/x86/ArchitectureX86.h | 3 +- src/apps/debugger/dwarf/CompilationUnit.h | 4 +- src/apps/debugger/model/FileSourceCode.h | 2 +- src/apps/debugger/types/ArrayIndexPath.h | 3 +- .../debugger/types/TargetAddressRangeList.h | 3 +- src/apps/debugger/types/ValueLocation.h | 2 +- src/apps/debugger/util/BitBuffer.h | 3 +- 8 files changed, 54 insertions(+), 39 deletions(-) rename {src/apps/debugger/util => headers/private/shared}/Array.h (74%) diff --git a/src/apps/debugger/util/Array.h b/headers/private/shared/Array.h similarity index 74% rename from src/apps/debugger/util/Array.h rename to headers/private/shared/Array.h index 7b74acbf4d..8b514187cf 100644 --- a/src/apps/debugger/util/Array.h +++ b/headers/private/shared/Array.h @@ -1,16 +1,23 @@ /* - * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. All Rights Reserved. + * Copyright 2009-2011, Ingo Weinhold, ingo_weinhold@gmx.de. * Distributed under the terms of the MIT License. */ -#ifndef ARRAY_H -#define ARRAY_H +#ifndef _ARRAY_H +#define _ARRAY_H #include #include #include -#include +#include + +#if DEBUG +# include +#endif + + +namespace BPrivate { template @@ -20,37 +27,37 @@ public: Array(const Array& other); ~Array(); - inline int Size() const { return fSize; } - inline int Count() const { return fSize; } + inline int32 Size() const { return fSize; } + inline int32 Count() const { return fSize; } inline bool IsEmpty() const { return fSize == 0; } inline Element* Elements() const { return fElements; } inline bool Add(const Element& element); - inline bool AddUninitialized(int elementCount); - inline bool Insert(const Element& element, int index); - inline bool InsertUninitialized(int index, int count); - inline bool Remove(int index, int count = 1); + inline bool AddUninitialized(int32 elementCount); + inline bool Insert(const Element& element, int32 index); + inline bool InsertUninitialized(int32 index, int32 count); + inline bool Remove(int32 index, int32 count = 1); void Clear(); inline void MakeEmpty(); - inline Element& ElementAt(int index); - inline const Element& ElementAt(int index) const; + inline Element& ElementAt(int32 index); + inline const Element& ElementAt(int32 index) const; - inline Element& operator[](int index); - inline const Element& operator[](int index) const; + inline Element& operator[](int32 index); + inline const Element& operator[](int32 index) const; Array& operator=(const Array& other); private: - static const int kMinCapacity = 8; + static const int32 kMinCapacity = 8; - bool _Resize(int index, int delta); + bool _Resize(int32 index, int32 delta); private: Element* fElements; - int fSize; - int fCapacity; + int32 fSize; + int32 fCapacity; }; @@ -97,7 +104,7 @@ Array::Add(const Element& element) template inline bool -Array::AddUninitialized(int elementCount) +Array::AddUninitialized(int32 elementCount) { return InsertUninitialized(fSize, elementCount); } @@ -105,7 +112,7 @@ Array::AddUninitialized(int elementCount) template bool -Array::Insert(const Element& element, int index) +Array::Insert(const Element& element, int32 index) { if (index < 0 || index > fSize) index = fSize; @@ -121,7 +128,7 @@ Array::Insert(const Element& element, int index) template bool -Array::InsertUninitialized(int index, int count) +Array::InsertUninitialized(int32 index, int32 count) { if (index < 0 || index > fSize || count < 0) return false; @@ -138,7 +145,7 @@ Array::InsertUninitialized(int index, int count) template bool -Array::Remove(int index, int count) +Array::Remove(int32 index, int32 count) { if (index < 0 || count < 0 || index + count > fSize) { #if DEBUG @@ -189,7 +196,7 @@ Array::MakeEmpty() template Element& -Array::ElementAt(int index) +Array::ElementAt(int32 index) { return fElements[index]; } @@ -197,7 +204,7 @@ Array::ElementAt(int index) template const Element& -Array::ElementAt(int index) const +Array::ElementAt(int32 index) const { return fElements[index]; } @@ -205,7 +212,7 @@ Array::ElementAt(int index) const template Element& -Array::operator[](int index) +Array::operator[](int32 index) { return fElements[index]; } @@ -213,7 +220,7 @@ Array::operator[](int index) template const Element& -Array::operator[](int index) const +Array::operator[](int32 index) const { return fElements[index]; } @@ -236,11 +243,11 @@ Array::operator=(const Array& other) template bool -Array::_Resize(int index, int delta) +Array::_Resize(int32 index, int32 delta) { // determine new capacity - int newSize = fSize + delta; - int newCapacity = kMinCapacity; + int32 newSize = fSize + delta; + int32 newCapacity = kMinCapacity; while (newCapacity < newSize) newCapacity *= 2; @@ -287,4 +294,10 @@ Array::_Resize(int index, int delta) } -#endif // ARRAY_H +} // namespace BPrivate + + +using BPrivate::Array; + + +#endif // _ARRAY_H diff --git a/src/apps/debugger/arch/x86/ArchitectureX86.h b/src/apps/debugger/arch/x86/ArchitectureX86.h index 0f5bba0975..d2034edb46 100644 --- a/src/apps/debugger/arch/x86/ArchitectureX86.h +++ b/src/apps/debugger/arch/x86/ArchitectureX86.h @@ -6,8 +6,9 @@ #define ARCHITECTURE_X86_H +#include + #include "Architecture.h" -#include "Array.h" #include "Register.h" diff --git a/src/apps/debugger/dwarf/CompilationUnit.h b/src/apps/debugger/dwarf/CompilationUnit.h index 3fc6ddd2ac..44d7520a29 100644 --- a/src/apps/debugger/dwarf/CompilationUnit.h +++ b/src/apps/debugger/dwarf/CompilationUnit.h @@ -6,11 +6,11 @@ #define COMPILATION_UNIT_H +#include #include -#include +#include -#include "Array.h" #include "LineNumberProgram.h" #include "Types.h" diff --git a/src/apps/debugger/model/FileSourceCode.h b/src/apps/debugger/model/FileSourceCode.h index e6a0191fd8..b30415b9d0 100644 --- a/src/apps/debugger/model/FileSourceCode.h +++ b/src/apps/debugger/model/FileSourceCode.h @@ -8,8 +8,8 @@ #include +#include -#include "Array.h" #include "SourceCode.h" diff --git a/src/apps/debugger/types/ArrayIndexPath.h b/src/apps/debugger/types/ArrayIndexPath.h index 834444e3da..b739ef447a 100644 --- a/src/apps/debugger/types/ArrayIndexPath.h +++ b/src/apps/debugger/types/ArrayIndexPath.h @@ -6,7 +6,8 @@ #define ARRAY_INDEX_PATH_H -#include "Array.h" +#include + #include "Types.h" diff --git a/src/apps/debugger/types/TargetAddressRangeList.h b/src/apps/debugger/types/TargetAddressRangeList.h index 118684b10e..3a7fdb325c 100644 --- a/src/apps/debugger/types/TargetAddressRangeList.h +++ b/src/apps/debugger/types/TargetAddressRangeList.h @@ -5,9 +5,10 @@ #ifndef TARGET_ADDRESS_RANGE_LIST_H #define TARGET_ADDRESS_RANGE_LIST_H + +#include #include -#include "Array.h" #include "TargetAddressRange.h" diff --git a/src/apps/debugger/types/ValueLocation.h b/src/apps/debugger/types/ValueLocation.h index e49164e798..5b598d9cdc 100644 --- a/src/apps/debugger/types/ValueLocation.h +++ b/src/apps/debugger/types/ValueLocation.h @@ -6,9 +6,9 @@ #define VALUE_LOCATION_H +#include #include -#include "Array.h" #include "Types.h" diff --git a/src/apps/debugger/util/BitBuffer.h b/src/apps/debugger/util/BitBuffer.h index 6c852c0a9a..51354cbad7 100644 --- a/src/apps/debugger/util/BitBuffer.h +++ b/src/apps/debugger/util/BitBuffer.h @@ -8,8 +8,7 @@ #include - -#include "Array.h" +#include class BitBuffer {