22 #ifndef ULTIMA8_USECODE_UCLIST_H 23 #define ULTIMA8_USECODE_UCLIST_H 25 #include "ultima/shared/std/containers.h" 26 #include "ultima/shared/std/string.h" 43 unsigned int _elementSize;
47 UCList(
unsigned int elementSize,
unsigned int capacity = 0) :
48 _elementSize(elementSize), _size(0) {
50 _elements.
reserve(_elementSize * capacity);
60 const uint8 *operator[](uint32 index)
const {
62 return &(_elements[index * _elementSize]);
65 uint16 getuint16(uint32 index)
const {
66 assert(_elementSize == 2);
67 uint16 t = _elements[index * _elementSize];
68 t += _elements[index * _elementSize + 1] << 8;
72 void append(
const uint8 *e) {
73 _elements.
resize((_size + 1) * _elementSize);
74 for (
unsigned int i = 0; i < _elementSize; i++)
75 _elements[_size * _elementSize + i] = e[i];
79 void appenduint16(uint16 val) {
80 assert(_elementSize == 2);
82 buf[0] =
static_cast<uint8
>(val);
83 buf[1] =
static_cast<uint8
>(val >> 8);
87 void remove(
const uint8 *e) {
90 for (
unsigned int i = 0; i < _size; i++) {
92 for (
unsigned int j = 0; j < _elementSize && equal; j++)
93 equal = equal && (_elements[i * _elementSize + j] == e[j]);
95 _elements.
erase(_elements.
begin() + i * _elementSize,
96 _elements.
begin() + (i + 1)*_elementSize);
103 bool inList(
const uint8 *e)
const {
104 for (
unsigned int i = 0; i < _size; i++) {
106 for (
unsigned int j = 0; j < _elementSize && equal; j++)
107 equal = (_elements[i * _elementSize + j] == e[j]);
114 void appendList(
const UCList &l) {
116 assert(_elementSize == l.getElementSize());
117 _elements.
reserve(_elementSize * (_size + l._size));
118 for (
unsigned int i = 0; i < l._size; i++)
121 void unionList(
const UCList &l) {
123 assert(_elementSize == l.getElementSize());
124 _elements.
reserve(_elementSize * (_size + l._size));
125 for (
unsigned int i = 0; i < l._size; i++)
129 void subtractList(
const UCList &l) {
131 assert(_elementSize == l.getElementSize());
132 for (
unsigned int i = 0; i < l._size; i++)
140 uint32 getSize()
const {
143 unsigned int getElementSize()
const {
147 void assign(uint32 index,
const uint8 *e) {
149 for (
unsigned int i = 0; i < _elementSize; i++)
150 _elements[index * _elementSize + i] = e[i];
153 void copyList(
const UCList &l) {
159 void copyStringList(
const UCList &l) ;
160 void unionStringList(
UCList &l);
161 void subtractStringList(
const UCList &l);
162 bool stringInList(uint16 str)
const;
163 void assignString(uint32 index, uint16 str);
164 void removeString(uint16 str,
bool nodel =
false);
166 uint16 getStringIndex(uint32 index)
const;
void clear()
Definition: array.h:320
iterator begin()
Definition: array.h:374
Definition: detection.h:27
void reserve(size_type newCapacity)
Definition: array.h:396
void resize(size_type newSize)
Definition: array.h:411
iterator erase(iterator pos)
Definition: array.h:328