Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct IMAP {
- struct PACKAGE {
- PACKAGE() {
- this->z = 0;
- this->exist = false;
- this->item = nullptr;
- };
- ITEM* item;
- bool exist;
- double z;
- void Make(const ITEM item, double z = 0.0) {
- this->Clear();
- this->item = new ITEM(item);
- this->z = z;
- this->exist = true;
- }
- void Make(PACKAGE p) {
- this->item = new ITEM((const ITEM)*p.item);
- this->z = p.z;
- this->exist = true;
- p.Clear();
- }
- void Clear() {
- if (this->item != nullptr) {
- delete this->item;
- this->item = nullptr;
- this->exist = false;
- this->z = 0.0;
- }
- else {
- this->exist = false;
- this->z = 0.0;
- }
- }
- };
- IMAP(SINT block = 8) {
- this->block = block;
- this->size = 0;
- this->length = 0;
- this->last = 0;
- this->counter = 0;
- this->package = nullptr;
- this->debug = false;
- this->z = false;
- };
- DINT size, length, block, last, counter;
- bool debug, z;
- drx::util::IMAP<ITEM>::PACKAGE* package;
- drx::util::IMAP<ITEM>::PACKAGE dummy;
- void _resize(DINT size = 0) {
- int total = this->size;
- if (size > 0) {
- this->size += size;
- }
- else {
- this->size += this->block;
- }
- if (this->length > 0) {
- drx::util::IMAP<ITEM>::PACKAGE* package = new drx::util::IMAP<ITEM>::PACKAGE[this->size];
- for (int i = 0, c = 0; i < total; i++) {
- if (this->package[i].exist) {
- package[c].Make((const drx::util::IMAP<ITEM>::PACKAGE)this->package[i]);
- c++;
- }
- }
- delete[] this->package;
- this->package = package;
- }
- else {
- this->package = new drx::util::IMAP<ITEM>::PACKAGE[this->size];
- }
- }
- void Position(ITEM item, DINT pos) {
- for (; this->size <= pos;) this->_resize();
- if (!this->package[pos].exist) {
- this->package[pos].Make(item, 0.0);
- this->last = pos;
- this->length++;
- this->counter++;
- }
- }
- bool Null(SINT pos) {
- return (this->package[pos].item == nullptr);
- }
- void operator << (ITEM item) {
- if (this->size == 0 || this->length == this->size) this->_resize();
- for (DINT i = 0; i < this->size; i++) {
- if (!this->package[i].exist && this->package[i].item == nullptr) {
- this->package[i].Make(item, (double)this->counter);
- this->last = i;
- this->length++;
- this->counter++;
- break;
- }
- }
- }
- ITEM& operator [] (DINT pos) {
- if (1 == 0 && this->debug) {
- for (DINT i = 0; i < this->size; i++) {
- PACKAGE p = this->package[i];
- if (p.exist) {
- std::cout << "\nI :: " << i;
- }
- }
- }
- if (pos >= 0 && pos < this->size) return *this->package[pos].item;
- return *this->dummy.item;
- }
- void _close() {
- if (this != nullptr) {
- if (this->size > 0) {
- for (DINT i = 0; i < this->size; i++) {
- this->package[i].Clear();
- }
- this->size = 0;
- }
- if (this->package != nullptr) {
- delete[] this->package;
- this->package = nullptr;
- }
- this->length = 0;
- this->last = 0;
- this->counter = 0;
- this->z = false;
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment