9#if !defined(OWL_TEMPLATE_H)
13#if defined(BI_HAS_PRAGMA_ONCE)
39 void operator delete(
void *ptr);
40 void *
operator new(
size_t sz);
55inline void TStandardAllocator::operator
delete(
void *ptr){
58inline void * TStandardAllocator::operator
new(
size_t sz){
59 return ::operator
new(
sz);
69 return ::realloc(ptr,
sz);
86 void *
operator new(
size_t sz);
87 void operator delete(
void* ptr);
102inline void * TLocalAllocator::operator
new(
size_t sz){
105inline void TLocalAllocator::operator
delete(
void * ptr){
129 void *
operator new(
size_t sz);
130 void operator delete(
void* ptr);
133 void Free(
void *ptr);
145inline void * TGlobalAllocator::operator
new(
size_t sz){
148inline void TGlobalAllocator::operator
delete(
void * ptr){
205 void operator delete(
void * );
206 void operator delete(
void *p,
size_t,
const A& );
215template <
class A>
inline
219template <
class A>
inline void*
222 return A::operator
new(
sz +
extra);
224template <
class A>
inline void
225TMBlockList<A>::operator
delete (
void *ptr )
227 A::operator
delete (ptr);
229template <
class A>
inline void
230TMBlockList<A>::operator
delete(
void *p,
size_t,
const A& )
232 A::operator
delete (p);
262 unsigned Count()
const {
return BlockCount; }
269 const size_t BlockSize;
276template <
class A>
inline
278: CurBlock(
nullptr), BlockSize(
sz), BlockCount(0)
282template <
class A>
inline
285#if !defined( BI_WINDOWS_WEP_BUG )
289template <
class A>
int
298template <
class A>
void
302 while( BlockCount >
term ){
304 CurBlock =
temp->Next;
329template <
class A>
class TMMarker;
346: Data(
sz ),CurLoc(
sz)
353 sz = std::max(
static_cast<size_t>(1),
sz );
354 if(
sz > Data.GetBlockSize() - CurLoc )
356 if( Data.AllocBlock(
sz ) == 0 )
361 void*
temp = Data.Block() + CurLoc;
376 Memstk(
ms),Blk(
ms.Data.Count()),CurLoc(
ms.CurLoc)
381 const auto ok = Blk < Memstk.Data.Count() || (Blk == Memstk.Data.Count() && CurLoc <= Memstk.CurLoc);
382 WARN(!
ok,
_T(
"TMMarker::~TMMarker: Terminating due to failed precondition."));
383 if (!
ok) std::terminate();
385 Memstk.Data.FreeTo( Blk );
386 Memstk.CurLoc = CurLoc;
435template <
class A>
inline
439 CHECK(
sz != 0 && count != 0 );
442template <
class A>
inline void*
450 if( FreeList ==
nullptr )
451 return Mem.Allocate( Size );
453 void *
temp = FreeList;
454 FreeList = *
static_cast<void**
>(
temp);
459template <
class A>
inline void
462 *
static_cast<void **
>(
block) = FreeList;
497 static_cast<void>(t);
502inline char*
__owl_construct(
void* p,
char c) { *(
static_cast<char*
>(p)) =
c;
return static_cast<char*
>(p);}
505inline int*
__owl_construct(
void* p,
int c) { *(
static_cast<int*
>(p)) =
c;
return static_cast<int*
>(p);}
506inline unsigned int*
__owl_construct(
void* p,
unsigned int c){ *(
static_cast<unsigned int*
>(p)) =
c;
return static_cast<unsigned int*
>(p);}
509inline long*
__owl_construct(
void* p,
long c) { *(
static_cast<long*
>(p)) =
c;
return static_cast<long*
>(p);}
725 int AddAt(
const T&,
int){
return 0;}
753template<
class T,
class R,
class A = TStandardAllocator>
class TTypedArray :
825 int AddAt(
R t,
int index);
919 operator bool()
const {
return Cur !=
nullptr; }
1052 else if(*s > p->Split)
1066 else if(*s == p->Split){
1103 : Data{
nullptr}, Mem{
sizeof(T), std::max(10u, array.Reserved / 10u)}
1128 if(array.ItemCnt >= Reserved)
1129 Resize(array.ItemCnt - Reserved);
1133 ItemCnt = array.ItemCnt;
1141 if(ItemCnt>=Reserved)
1149 if(index == Size()){
1153 if(index >=Reserved)
1155 if(ItemCnt>=Reserved)
1157 if(index < ItemCnt && ItemCnt)
1158 memmove(&Data[index+1], &Data[index],
sizeof(T*)*(ItemCnt-index));
1166 const auto index = this->Find(t);
1167 if (index != this->NPOS)
1169 T*
tmp = Data[index];
1180 if(
loc <
static_cast<int>(Size())){
1193 return this->Find(t) != this->NPOS;
1236 for(
int i =
static_cast<int>(Size())-1;
i >=0;
i--)
1255 if(
static_cast<int>(Reserved) > index)
1257 Resize(index - Reserved);
1264 T**
data =
static_cast<T**
>(A::ReAlloc(
static_cast<void*
>(Data),(Reserved+
delta)*
sizeof(T**)));
1266 data =
static_cast<T**
>(A::Alloc((Reserved+
delta)*
sizeof(T**)));
1273 Data =
static_cast<T**
>(A::Alloc((Reserved+
delta)*
sizeof(T**)));
1275 memset(
reinterpret_cast<uint8*
>(Data)+Reserved*
sizeof(T**),0,
delta*
sizeof(T**));
1282 memmove(&Data[index],&Data[index+1],
sizeof(T*)*(ItemCnt-index-1));
1291template<
class T,
class A>
inline
1311 if(this->ItemCnt>=this->Reserved)
1313 unsigned loc = this->ItemCnt++;
1314 while(
loc > 0 && t < *(this->Data[
loc-1])) {
1315 this->Data[
loc] = this->Data[
loc-1];
1325 const auto index = this->Find(t);
1326 if (index != this->NPOS)
1328 T*
tmp = this->Data[index];
1329 this->Remove(index);
1331 this->Mem.Free(
tmp);
1340 return this->Find(t) != this->NPOS;
1347 auto upper =
static_cast<int>(this->Size()) - 1;
1351 if (*(this->Data[
middle]) == t)
1353 if (*(this->Data[
middle]) < t)
1365template<
class T,
class R,
class A>
1384 if(array.ItemCnt >= Reserved)
1385 Resize(array.ItemCnt - Reserved);
1387 Data[
i] = array.Data[
i];
1388 ItemCnt = array.ItemCnt;
1394template<
class T,
class R,
class A>
inline int
1397 if(ItemCnt>=Reserved)
1399 Data[ItemCnt++] = t;
1404template<
class T,
class R,
class A>
void
1407 if(index == Size()){
1411 if(index >=Reserved)
1413 if(ItemCnt>=Reserved)
1415 if(index < ItemCnt && ItemCnt)
1416 memmove(&Data[index+1], &Data[index],
sizeof(T)*(ItemCnt-index));
1422template<
class T,
class R,
class A>
bool
1425 const auto index = this->Find(t);
1426 if (index != this->NPOS)
1435template<
class T,
class R,
class A>
bool
1438 if(
loc <
static_cast<int>(Size())){
1446template<
class T,
class R,
class A>
inline bool
1449 return DetachItem(t);
1453template<
class T,
class R,
class A>
inline bool
1460template<
class T,
class R,
class A>
inline bool
1463 return this->Find(t) != this->NPOS;
1467template<
class T,
class R,
class A>
int
1477template<
class T,
class R,
class A>
inline T&
1485template<
class T,
class R,
class A>
inline const T&
1493template<
class T,
class R,
class A>
void
1501template<
class T,
class R,
class A> T*
1511template<
class T,
class R,
class A> T*
1514 for(
int i =
static_cast<int>(Size())-1;
i >=0;
i--)
1521template<
class T,
class R,
class A>
inline void
1528template<
class T,
class R,
class A>
inline void
1531 if(Reserved >
static_cast<uint>(index))
1533 Resize(index - Reserved);
1537template<
class T,
class R,
class A>
void
1542 T*
data =
static_cast<T*
>(this->ReAlloc(
static_cast<void*
>(Data),(Reserved+
delta)*
sizeof(T)));
1545 data =
static_cast<T*
>(this->Alloc((Reserved+
delta)*
sizeof(T)));
1559 Data =
static_cast<T*
>(this->Alloc((Reserved+
delta)*
sizeof(T)));
1561 memset(
reinterpret_cast<uint8*
>(Data)+Reserved*
sizeof(T),0,
delta*
sizeof(T));
1566template<
class T,
class R,
class A>
inline void
1569 memmove(&Data[index],&Data[index+1],
sizeof(T)*(ItemCnt-index-1));
1576template<
class T,
class R,
class A>
inline
1594template<
class T,
class R,
class A>
int
1597 if(this->ItemCnt>=this->Reserved)
1598 Resize(this->ItemCnt+1);
1599 unsigned loc = this->ItemCnt++;
1601 this->Data[
loc] = this->Data[
loc-1];
1604 this->Data[
loc] = t;
1609template<
class T,
class R,
class A>
bool
1612 const auto index = this->Find(t);
1613 if (index != this->NPOS)
1615 this->Remove(index);
1622template<
class T,
class R,
class A>
inline bool
1625 return DetachItem(t);
1629template<
class T,
class R,
class A>
inline bool
1632 return this->Find(t) != this->NPOS;
1636template<
class T,
class R,
class A>
int
1640 auto upper =
static_cast<int>(this->Size()) - 1;
1644 if (this->Data[
middle] == t)
1646 if (this->Data[
middle] < t)
1658template<
class T,
class R,
class A>
inline
1665template<
class T,
class R,
class A>
inline
1672template<
class T,
class R,
class A>
inline
1677template<
class T,
class R,
class A>
inline
1693template<
class T,
class R,
class A>
inline bool
1696 const auto index = this->Find(t);
1697 if (index != this->NPOS)
1699 R tmp = this->Data[index];
1700 this->Remove(index);
1707template<
class T,
class R,
class A>
inline bool
1710 if(
loc <
static_cast<int>(this->Size())){
1719template<
class T,
class R,
class A>
void
1724 delete this->Data[
i];
1733template<
class T>
inline
1740template<
class T>
inline
1758template<
class T>
inline
1764template<
class T>
inline
1771template<
class T>
void
1776 delete this->Data[
i];
1782template<
class T>
inline bool
1785 const auto index = this->Find(t);
1786 if (index != this->NPOS)
1788 T
tmp = this->Data[index];
1789 this->Remove(index);
1797template<
class T>
inline bool
1800 if(
loc <
static_cast<int>(this->Size())){
1814template<
class T>
inline
1822template<
class T>
inline
1828template<
class T>
inline
1835template<
class T>
inline
1855template<
class T>
void
1860 delete this->Data[
i];
1866template<
class T>
inline bool
1869 const auto index = this->Find(t);
1870 if (index != this->NPOS)
1872 T
tmp = this->Data[index];
1873 this->Remove(index);
1881template<
class T>
inline bool
1884 if(
loc <
static_cast<int>(this->Size())){
1899template<
class T>
inline
1907template<
class T>
inline
1910 First(0),Last(0),ItemSize(0)
1915template<
class T>
inline
1922template<
class T>
inline void
1930template<
class T>
inline void
1937template<
class T>
inline void
1944template<
class T>
inline void
1951template<
class T>
inline T
1961template<
class T>
inline const T&
1968template<
class T>
inline const T&
1975template<
class T>
void
1983 First = Last =
nullptr;
1988template<
class T>
bool
1992 if(item && Remove(item)){
2000template<
class T>
bool
2003 if(
loc <
static_cast<int>(Size())){
2016template<
class T>
inline bool
2019 return this->Find(t) != 0;
2033template<
class T>
void
2061template<
class T>
bool
2068 node->Next =
nullptr;
2070 First->Prev =
nullptr;
2072 else if(
node == Last){
2074 node->Prev =
nullptr;
2076 Last->Next =
nullptr;
2081 node->Prev =
nullptr;
2082 node->Next =
nullptr;
2090template<
class T>
inline int
2097template<
class T>
int
2115template<
class T>
int
2132 node->Next = item->Next;
2148 return ::operator
new(
sz);
2164 return m.Allocate(
sz );
#define WARN(condition, message)
#define PRECONDITION(condition)
base array class -> reduce code size
uint GetItemsInContainer() const
int Add(TBaseNode< T > *node)
add new item at end of list return index
T Pop()
remove 1 item return data item
int Add(TBaseNode< T > *node, const T &data)
add new item after item, if 0 add before first return index
T * FirstThat(CondFunc cond, void *args) const
FirstThat( return first member.
bool DetachItem(const T &t)
DetachItem( detach item and delete it.
void(* IterFunc)(T &, void *)
T * LastThat(CondFunc cond, void *args) const
LastThat return last member.
void Push(const T &data)
add new item at begin of list
void ForEach(IterFunc iter, void *args)
iterates all strings
TBaseNode< T > * Find(const T &t) const
Find.
uint GetItemsInContainer() const
TBaseListIterator< T > Iterator
bool HasMember(const T &t) const
check item in container
void Flush()
Flush all items.
void Add(TBaseListIterator< T > *iter, const T &data)
add new item after iterator, if 0 add before first
bool Detach(int loc)
Detach( but and delete it.
uint ItemSize
optimization for Size()
bool Remove(TBaseNode< T > *t)
remove item from list not delete node
void Add(const T &data)
add new item at end of list
TBaseList(int, int lower=0, int delta=0)
int Add(TBaseNode< T > *item, TBaseNode< T > *node)
add new item after item, if 0 add before first
const T & Top()
return top of list
void PushBack(const T &data)
add new item at end of list
const T & Bottom()
return bottom of array
bool(* CondFunc)(const T &, void *)
const T & operator*() const
const T & Current() const
TBaseListIterator(TBaseList< T > &list)
TBaseMemBlocks(size_t sz=8192)
TBlockList(TBlockList *blk)
Provides class-specific operator new and operator delete that allocate from global memory.
void * ReAlloc(void *ptr, size_t sz)
TPtrArrayIterator< T, TIPtrArray< T > > Iterator
TIPtrArray< T > & operator=(const TIPtrArray< T > &array)
TIPtrArray(int upper, int lower=0, int delta=0)
void Flush(bool del=true)
TIPtrArray(const TIPtrArray< T > &array)
TISortedPtrArray< T > & operator=(const TISortedPtrArray< T > &array)
void Flush(bool del=true)
TISortedPtrArray(const TISortedPtrArray< T > &array)
TISortedPtrArray(int upper, int lower=0, int delta=0)
TPtrArrayIterator< T, TISortedPtrArray< T > > Iterator
Provides class-specific operator new and operator delete that allocate from local memory.
void * ReAlloc(void *ptr, size_t sz)
template <class A> class TMBaseMemBlocks Used internally.
TMBaseMemBlocks(size_t=8192)
size_t GetBlockSize() const
template <class Alloc> class TMBlockList Used internally.
TMBlockList(TMBlockList *)
TMIPtrArray< T, R, A > & operator=(const TMIPtrArray< T, R, A > &array)
TPtrArrayIterator< R, TMIPtrArray< T, R, A > > Iterator
TMMarker(TMMemStack< A > &ms)
Managed single-size block allocator.
TMMemBlocks(size_t sz, unsigned int count=100)
void * Allocate(size_t sz)
template <class A> class TMMemStack
holded array pointers to strings
T * FirstThat(CondFunc cond, void *args) const
void SqueezeEntry(unsigned loc)
void(* IterFunc)(T &, void *)
bool HasMember(const T &t) const
int Find(const T &t) const
bool(* CondFunc)(const T &, void *)
bool DestroyItem(const T &t)
void RemoveEntry(int loc)
TMObjectArray(const TMObjectArray< T, A > &array)
TMObjectArray(int upper, int lower=0, int=0)
T * LastThat(CondFunc cond, void *args) const
void AddAt(const T &t, uint index)
bool DetachItem(const T &t)
void ForEach(IterFunc iter, void *args)
TMMemBlocks< A > & GetAllocator()
TMObjectArray< T, A > & operator=(const TMObjectArray< T, A > &array)
TObjArrayIterator< T, TMObjectArray< T, A > > Iterator
bool DestroyItem(const T &t)
TObjArrayIterator< T, TMSortedObjectArray< T, A > > Iterator
bool HasMember(const T &t) const
TMSortedObjectArray(int upper, int lower=0, int delta=0)
bool DetachItem(const T &t)
TMSortedObjectArray(const TMSortedObjectArray< T, A > &array)
TMSortedObjectArray< T, A > & operator=(const TMSortedObjectArray< T, A > &array)
int Find(const T &t) const
int AddAt(const T &, int)
Usage: typedef TMapNode<string,string> TStringMapNode; typedef TSortedObjectArray< TStringMapNode > T...
TMapNode(const TMapNode< T1, T2 > &node)
TMapNode(T1 &name, T2 &val)
bool operator<(const TMapNode &ms) const
bool operator==(const TMapNode &ms) const
TMapNode & operator=(const TMapNode &other)
template <class A> class TMarker Provides the mark for TMemStack.
TMarker(TMMemStack< TStandardAllocator > &ms)
Single-size block allocator.
TMemBlocks(size_t sz, unsigned n=100)
Implements mark and release style memory management using the standard allocator.
TMemStack(size_t sz=8192)
class Iterator for TObjectContainer
TObjArrayIterator(T1 &array)
const T & Current() const
const T & operator*() const
TObjectArray(int upper, int lower=0, int delta=0)
TObjArrayIterator< T, TObjectArray< T > > Iterator
TObjectArray< T > & operator=(const TObjectArray< T > &array)
void(* IterFunc)(T &, void *)
TObjectArray(const TObjectArray< T > &array)
bool(* CondFunc)(const T &, void *)
array of pointers of simple types
TPtrArray(int upper, int lower=0, int delta=0)
TPtrArray(const TPtrArray< T > &array)
Iterator for Pointer Container.
TPtrArrayIterator(T1 &array)
const T operator*() const
TSTypedArray(const TSTypedArray< T, R, A > &array)
TSTypedArray(int upper, int lower=0, int delta=0)
TPtrArrayIterator< R, TSTypedArray< T, R, A > > Iterator
TSTypedArray< T, R, A > & operator=(const TSTypedArray< T, R, A > &array)
bool HasMember(R t) const
TSortedObjectArray< T > & operator=(const TSortedObjectArray< T > &array)
TSortedObjectArray(const TSortedObjectArray< T > &array)
void(* IterFunc)(T &, void *)
TSortedObjectArray(int upper, int lower=0, int delta=0)
bool(* CondFunc)(const T &, void *)
TObjArrayIterator< T, TSortedObjectArray< T > > Iterator
sorted array of pointers of simple types
TSortedPtrArray(const TSortedPtrArray< T > &array)
TSortedPtrArray(int upper, int lower=0, int delta=0)
Provides class-specific operator new and operator delete that simply call the global operator new and...
void * ReAlloc(void *ptr, size_t sz)
TTernaryNode(T split, const T1 &data)
TTernaryNode< T, T1 > * RInsert(TTernaryNode< T, T1 > *p, T *s, const T1 &data)
T1 * RSearch(TTernaryNode< T, T1 > *p, T *s)
TTernaryNode< T, T1 > * Root
void Insert(T *s, const T1 &data)
void Flush(TTernaryNode< T, T1 > *p)
(store pointer to object) - Jogy: incorrect, stores simple types without assuming that they are point...
bool(* CondFunc)(R, void *)
TTypedArray(int upper, int=0, int=0)
void RemoveEntry(int loc)
void ForEach(IterFunc iter, void *args)
TTypedArray< T, R, A > & operator=(const TTypedArray< T, R, A > &array)
void AddAt(R t, uint index)
bool HasMember(R t) const
T * FirstThat(CondFunc cond, void *args) const
void(* IterFunc)(R, void *)
void SqueezeEntry(unsigned loc)
TPtrArrayIterator< R, TTypedArray< T, R, A > > Iterator
TTypedArray(const TTypedArray< T, R, A > &array)
T * LastThat(CondFunc cond, void *args) const
TStandardAllocator TSharedAllocator
Object Windows Library (OWLNext Core)
TMMemBlocks< TStandardAllocator > TStandardBlocks
void __owl_destruct(T *t)
T * __owl_construct(void *P)
General definitions used by all ObjectWindows programs.
#define REINTERPRET_CAST(targetType, object)