From 56a3380b46f406ffaf093405ac2db4515b0a4f80 Mon Sep 17 00:00:00 2001 From: "FWoltermann@gmail.com" Date: Mon, 28 May 2012 16:44:39 +0000 Subject: Removes the ArrayList classes, and replaces all instances with std::vector implementations. --- FoundationEx/ArrayList.cpp | 453 --------------------------------------------- FoundationEx/ArrayList.h | 170 ----------------- 2 files changed, 623 deletions(-) delete mode 100644 FoundationEx/ArrayList.cpp delete mode 100644 FoundationEx/ArrayList.h (limited to 'FoundationEx') diff --git a/FoundationEx/ArrayList.cpp b/FoundationEx/ArrayList.cpp deleted file mode 100644 index 64a164f..0000000 --- a/FoundationEx/ArrayList.cpp +++ /dev/null @@ -1,453 +0,0 @@ -/* Project FoundationEx - Destroyer Studios LLC - Copyright © 1997-2004. All Rights Reserved. - - SUBSYSTEM: FoundationEx - FILE: ArrayList.cpp - AUTHOR: John DiCamillo - - - OVERVIEW - ======== - Implementation of the untyped ArrayList class -*/ - -#include "MemDebug.h" -#include "ArrayList.h" -#include - -// +-------------------------------------------------------------------+ - -void Print(const char* fmt, ...); - -// +-------------------------------------------------------------------+ - -ArrayList::ArrayList(const ArrayList& l) -{ - for (auto ali = l.array.begin(); ali != l.array.end(); ++ali) - array.push_back(*ali); - -} - -void ArrayList::clear() -{ - array.clear(); -} - -// +-------------------------------------------------------------------+ - -bool ArrayList::check(int& index) const -{ - if (index > array.size()) { - Print("Bounds error in ArrayList(%08x) index=%d min=0\n", (int)this, index); - index = 0; - } - - return (index >= 0 && index < array.size()); -} - -// +-------------------------------------------------------------------+ - -DWORD ArrayList::operator[](int index) const -{ - if (check(index)) - return array[index]; - return 0; -} - -DWORD& ArrayList::operator[](int index) -{ - if (check(index)) - return array[index]; - - return array[0]; -} - -DWORD ArrayList::at(int index) const -{ - if (check(index)) - return array[index]; - return 0; -} - -DWORD& ArrayList::at(int index) -{ - if (check(index)) - return array[index]; - - return array[0]; -} - -// +-------------------------------------------------------------------+ - -void ArrayList::resize(int newsize) -{ - array.resize(newsize); -} - -// +-------------------------------------------------------------------+ - -void ArrayList::append(DWORD item) -{ - array.push_back(item); -} - -void ArrayList::append(const ArrayList& list) -{ - for (auto li = list.array.begin(); li != list.array.end(); ++li) - array.push_back(*li); -} - -// +-------------------------------------------------------------------+ - -void ArrayList::insert(DWORD item, int index) -{ - auto it = array.begin(); - array.insert(it + index, item); -} - -// +-------------------------------------------------------------------+ - -void ArrayList::insertSort(DWORD item) -{ - for (auto arrit = array.begin(); arrit != array.end(); arrit++) { - if (*arrit < item) { - array.insert(arrit, item); - return; - } - } -} - -// +-------------------------------------------------------------------+ - -void ArrayList::remove(DWORD item) -{ - if (array.size() < 1) - return; - - for (auto it = array.begin(); it != array.end(); ++it) { - if (*it == item) - array.erase(it); - } -} - -// +-------------------------------------------------------------------+ - -void ArrayList::removeIndex(int index) -{ - if (array.size() < 1 || !check(index)) - return; - - array.erase(array.begin()+index); -} - -// +-------------------------------------------------------------------+ - -bool ArrayList::contains(DWORD val) const -{ - for (auto it = array.begin(); it != array.end(); ++it) { - if (*it == val) - return true; - } - - return false; -} - -// +-------------------------------------------------------------------+ - -int ArrayList::count(DWORD val) const -{ - int c = 0; - - for (auto it = array.begin(); it != array.end(); ++it) { - if (*it == val) - c++; - } - - return c; -} - -// +-------------------------------------------------------------------+ - -int ArrayList::index(DWORD val) const -{ - for (size_t i = 0; i < array.size(); i++) { - if (array[i] == val) - return i; - } - - return -1; -} - -// +-------------------------------------------------------------------+ - -void ArrayList::swap(int i, int j) -{ - if (i >= 0 && i < array.size() && j >= 0 && j < array.size() && i != j) { - DWORD t = array[i]; - array[i] = array[j]; - array[j] = t; - } -} - -void ArrayList::sort() -{ - if (array.size() < 2) - return; - - std::sort(array.begin(), array.end()); -} - -void ArrayList::shuffle() -{ - if (array.size() < 3) - return; - - for (int s = 0; s < 5; s++) { - for (int i = 0; i < array.size(); i++) { - int j = (rand()>>4) % array.size(); - swap(i, j); - } - } -} - - -// +===================================================================+ - -DWORD ArrayListIter::value() -{ - if (list && step >= 0) - return list->array[step]; - - return 0; -} - -// +-------------------------------------------------------------------+ - -void ArrayListIter::removeItem() -{ - if (list && step >= 0) - list->removeIndex(step--); -} - -// +-------------------------------------------------------------------+ - -DWORD ArrayListIter::next() -{ - if (list && step >= -1) - return list->array[++step]; - - return 0; -} - -DWORD ArrayListIter::prev() -{ - if (list && step > 0) - return list->array[--step]; - - return 0; -} - -// +-------------------------------------------------------------------+ - -void ArrayListIter::attach(ArrayList& l) -{ - list = &l; - step = -1; -} - -// +-------------------------------------------------------------------+ - -int ArrayListIter::size() -{ - if (!list) return 0; - return list->size(); -} - -// +-------------------------------------------------------------------+ - -ArrayList& ArrayListIter::container() -{ - return *list; -} - - - - -// +-------------------------------------------------------------------+ -// +-------------------------------------------------------------------+ -// +-------------------------------------------------------------------+ - -FloatList::FloatList(const FloatList& l) -{ - for (auto lit = l.array.begin(); lit != l.array.end(); lit++) - array.push_back(*lit); -} - -float FloatList::operator[](int index) const -{ - if (check(index)) - return array[index]; - return 0; -} - -float& FloatList::operator[](int index) -{ - if (check(index)) - return array[index]; - - return array[0]; -} - -float FloatList::at(int index) const -{ - if (check(index)) - return array[index]; - return 0; -} - -float& FloatList::at(int index) -{ - if (check(index)) - return array[index]; - - return array[0]; -} - -void FloatList::append(float value) { - array.push_back(value); -} - -void FloatList::append(const FloatList& list) -{ - for (auto li = list.array.begin(); li != list.array.end(); ++li) - array.push_back(*li); -} - - -void FloatList::insert(float item, int index) -{ - auto it = array.begin(); - array.insert(it + index, item); -} - -// +-------------------------------------------------------------------+ - -void FloatList::insertSort(float item) -{ - for (auto arrit = array.begin(); arrit != array.end(); arrit++) { - if (*arrit < item) { - array.insert(arrit, item); - return; - } - } -} - -// +-------------------------------------------------------------------+ - -void FloatList::remove(float item) -{ - if (array.size() < 1) - return; - - for (auto it = array.begin(); it != array.end(); ++it) { - if (*it == item) - array.erase(it); - } -} - -// +===================================================================+ - -float FloatListIter::value() -{ - if (list && step >= 0) - return list->array[step]; - - return 0; -} - -// +-------------------------------------------------------------------+ - -void FloatListIter::removeItem() -{ - if (list && step >= 0) - list->removeIndex(step--); -} - -// +-------------------------------------------------------------------+ - -float FloatListIter::next() -{ - if (list && step >= -1) - return list->array[++step]; - - return 0; -} - -float FloatListIter::prev() -{ - if (list && step > 0) - return list->array[--step]; - - return 0; -} - -bool FloatList::contains(float val) const -{ - for (auto it = array.begin(); it != array.end(); ++it) { - if (*it == val) - return true; - } - - return false; -} - -// +-------------------------------------------------------------------+ - -int FloatList::count(float val) const -{ - int c = 0; - - for (auto it = array.begin(); it != array.end(); ++it) { - if (*it == val) - c++; - } - - return c; -} - -// +-------------------------------------------------------------------+ - -int FloatList::index(float val) const -{ - for (size_t i = 0; i < array.size(); i++) { - if (array[i] == val) - return i; - } - - return -1; -} - -// +-------------------------------------------------------------------+ - -void FloatListIter::attach(FloatList& l) -{ - list = &l; - step = -1; -} - -// +-------------------------------------------------------------------+ - -int FloatListIter::size() -{ - if (!list) return 0; - return list->size(); -} - -// +-------------------------------------------------------------------+ - -FloatList& FloatListIter::container() -{ - return *list; -} - diff --git a/FoundationEx/ArrayList.h b/FoundationEx/ArrayList.h deleted file mode 100644 index c0985c3..0000000 --- a/FoundationEx/ArrayList.h +++ /dev/null @@ -1,170 +0,0 @@ -/* Project FoundationEx - Destroyer Studios LLC - Copyright © 1997-2004. All Rights Reserved. - - SUBSYSTEM: FoundationEx - FILE: ArrayList.h - AUTHOR: John DiCamillo - - - OVERVIEW - ======== - Simple untyped array list - - The E: That is going to be removed very very soon. For now, it has been aliased to std::vector - (or std::vector for FloatList). Full conversion to std::vector is still needed. -*/ - -#ifndef ArrayList_h -#define ArrayList_h - -#ifdef WIN32 -#include -#include -#endif - -#include - -// +-------------------------------------------------------------------+ - -class ArrayList -{ -public: - ArrayList() { array.clear(); } - ArrayList(const ArrayList& l); - ~ArrayList() { } - - DWORD operator[](int i) const; - DWORD& operator[](int i); - DWORD at(int i) const; - DWORD& at(int i); - - void append(const ArrayList& list); - void append(const DWORD val); - void insert(const DWORD val, int index=0); - void insertSort(DWORD val); - - DWORD first() const { return *array.begin(); } - DWORD last() const { return array.back(); } - void remove(DWORD val); - void removeIndex(int index); - - void clear(); - - int size() const { return array.size(); } - bool isEmpty() const { return array.size() == 0; } - - bool contains(DWORD val) const; - int count(DWORD val) const; - int index(DWORD val) const; - - void sort(); - void shuffle(); - - bool check(int& index) const; - -private: - void swap(int i, int j); - void resize(int newsize); - - - std::vector array; - - friend class ArrayListIter; -}; - -// +-------------------------------------------------------------------+ - -class ArrayListIter -{ -public: - ArrayListIter() : list(0), step(-1) { } - ArrayListIter(const ArrayListIter& i) : list(i.list), step(i.step) { } - ArrayListIter(ArrayList& l) : list(&l), step(-1) { } - - int operator++() { return next() != 0; } - int operator--() { return prev() != 0; } - - void reset() { step = -1; } - DWORD next(); - DWORD prev(); - DWORD value(); - void removeItem(); - - void attach(ArrayList& l); - ArrayList& container(); - int size(); - int index() { return step; } - -private: - ArrayList* list; - int step; -}; - - -// +-------------------------------------------------------------------+ -// +-------------------------------------------------------------------+ -// +-------------------------------------------------------------------+ - -class FloatList : public ArrayList -{ -public: - FloatList() { array.clear(); } - FloatList(const FloatList& l); - ~FloatList() {} - - float operator[](int i) const; - float& operator[](int i); - float at(int i) const; - float& at(int i); - - void append(const float val); - void append(const FloatList& list); - void insert(const float val, int index=0); - void insertSort(float val); - - float first() const { return *array.begin(); } - float last() const { return array.back(); } - void remove(float val); - - bool contains(float val) const; - int count(float val) const; - int index(float val) const; - -private: - - std::vector array; - - friend class FloatListIter; -}; - -// +-------------------------------------------------------------------+ - -class FloatListIter -{ -public: - FloatListIter() : list(0), step(-1) { } - FloatListIter(const FloatListIter& i) : list(i.list), step(i.step) { } - FloatListIter(FloatList& l) : list(&l), step(-1) { } - - int operator++() { return next() != 0; } - int operator--() { return prev() != 0; } - - void reset() { step = -1; } - float next(); - float prev(); - float value(); - void removeItem(); - - void attach(FloatList& l); - FloatList& container(); - int size(); - int index() { return step; } - -private: - FloatList* list; - int step; -}; - -#endif ArrayList_h - -- cgit v1.1