ReactOS 0.4.15-dev-8222-g9164419
cicarray.h
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Cicero
3 * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4 * PURPOSE: Cicero dynamic array
5 * COPYRIGHT: Copyright 2023 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6 */
7
8#pragma once
9
10#include "cicbase.h"
11
13{
14protected:
17
18public:
19 CicArrayBase(size_t cbItem);
20 virtual ~CicArrayBase();
21
22 BOOL Insert(size_t iItem, size_t cGrow);
23 LPVOID Append(size_t cGrow);
24 void Remove(size_t iItem, size_t cRemove = 1);
25};
26
27template <typename T_ITEM>
28class CicArray : protected CicArrayBase
29{
30public:
31 CicArray() : CicArrayBase(sizeof(T_ITEM)) { }
32
33 T_ITEM* data() const { return (T_ITEM*)m_pb; }
34 size_t size() const { return m_cItems; }
35 bool empty() const { return !size(); }
36 void clear()
37 {
39 m_pb = NULL;
41 }
42
43 T_ITEM& operator[](size_t iItem)
44 {
45 return *(T_ITEM*)&m_pb[iItem * m_cbItem];
46 }
47 const T_ITEM& operator[](size_t iItem) const
48 {
49 return *(const T_ITEM*)&m_pb[iItem * m_cbItem];
50 }
51
52 T_ITEM* Append(size_t cGrow)
53 {
54 return (T_ITEM*)CicArrayBase::Append(cGrow);
55 }
56
59
60 BOOL Add(const T_ITEM& item)
61 {
62 T_ITEM *pItem = Append(1);
63 if (!pItem)
64 return FALSE;
65 CopyMemory(pItem, &item, sizeof(T_ITEM));
66 return TRUE;
67 }
68
69 ptrdiff_t Find(const T_ITEM& item) const
70 {
71 for (size_t iItem = 0; iItem < m_cItems; ++iItem)
72 {
73 if ((*this)[iItem] == item)
74 return iItem;
75 }
76 return -1;
77 }
78};
static void cicMemFree(LPVOID ptr)
Definition: cicbase.h:27
LPVOID Append(size_t cGrow)
Definition: cicarray.cpp:23
void Remove(size_t iItem, size_t cRemove=1)
Definition: cicarray.cpp:57
BOOL Insert(size_t iItem, size_t cGrow)
Definition: cicarray.cpp:30
size_t m_cCapacity
Definition: cicarray.h:16
virtual ~CicArrayBase()
Definition: cicarray.cpp:18
size_t m_cbItem
Definition: cicarray.h:16
size_t m_cItems
Definition: cicarray.h:16
LPBYTE m_pb
Definition: cicarray.h:15
void clear()
Definition: cicarray.h:36
const T_ITEM & operator[](size_t iItem) const
Definition: cicarray.h:47
ptrdiff_t Find(const T_ITEM &item) const
Definition: cicarray.h:69
size_t size() const
Definition: cicarray.h:34
BOOL Add(const T_ITEM &item)
Definition: cicarray.h:60
CicArray()
Definition: cicarray.h:31
T_ITEM & operator[](size_t iItem)
Definition: cicarray.h:43
T_ITEM * Append(size_t cGrow)
Definition: cicarray.h:52
T_ITEM * data() const
Definition: cicarray.h:33
bool empty() const
Definition: cicarray.h:35
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
__kernel_ptrdiff_t ptrdiff_t
Definition: linux.h:247
unsigned int BOOL
Definition: ntddk_ex.h:94
static ATOM item
Definition: dde.c:856
unsigned char * LPBYTE
Definition: typedefs.h:53
#define CopyMemory
Definition: winbase.h:1710
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
_In_ BOOLEAN Remove
Definition: psfuncs.h:110