Second pass idLib integration.
This commit is contained in:
@@ -1,88 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "xmlattribute.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <new>
|
||||
|
||||
template<typename type>
|
||||
class idRecoveredList {
|
||||
public:
|
||||
explicit idRecoveredList(const std::uint8_t tag = 44,
|
||||
const std::int16_t initialGranularity = 16)
|
||||
: list(nullptr), num(0), size(0), granularity(initialGranularity),
|
||||
memTag(tag), listStatic(0) {
|
||||
}
|
||||
|
||||
~idRecoveredList() {
|
||||
Clear();
|
||||
}
|
||||
|
||||
idRecoveredList(const idRecoveredList&) = delete;
|
||||
idRecoveredList& operator=(const idRecoveredList&) = delete;
|
||||
|
||||
int Num() const { return num; }
|
||||
type& operator[](const int index) { return list[index]; }
|
||||
const type& operator[](const int index) const { return list[index]; }
|
||||
|
||||
type* Append(const type& value) {
|
||||
if (num == size && !Grow()) {
|
||||
return nullptr;
|
||||
}
|
||||
list[num] = value;
|
||||
return &list[num++];
|
||||
}
|
||||
|
||||
void Clear() {
|
||||
if (list != nullptr) {
|
||||
for (int index = 0; index < size; ++index) {
|
||||
list[index].~type();
|
||||
}
|
||||
std::free(list);
|
||||
}
|
||||
list = nullptr;
|
||||
num = 0;
|
||||
size = 0;
|
||||
}
|
||||
|
||||
private:
|
||||
type* list;
|
||||
int num;
|
||||
int size;
|
||||
std::int16_t granularity;
|
||||
std::uint8_t memTag;
|
||||
std::uint8_t listStatic;
|
||||
|
||||
bool Grow() {
|
||||
const int amount = granularity > 0 ? granularity : 16;
|
||||
const int newSize = size + amount;
|
||||
type* const replacement = static_cast<type*>(
|
||||
std::malloc(sizeof(type) * static_cast<std::size_t>(newSize))
|
||||
);
|
||||
if (replacement == nullptr) {
|
||||
return false;
|
||||
}
|
||||
for (int index = 0; index < newSize; ++index) {
|
||||
new (&replacement[index]) type();
|
||||
}
|
||||
for (int index = 0; index < num; ++index) {
|
||||
replacement[index] = list[index];
|
||||
}
|
||||
if (list != nullptr) {
|
||||
for (int index = 0; index < size; ++index) {
|
||||
list[index].~type();
|
||||
}
|
||||
std::free(list);
|
||||
}
|
||||
list = replacement;
|
||||
size = newSize;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
static_assert(sizeof(idRecoveredList<int>) == 16,
|
||||
"Recovered idList ABI changed");
|
||||
#include "../containers/recoveredlist.h"
|
||||
|
||||
class idXMLElement {
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user