From 154e2d7f4a063703dbdbb0984579be10355bf785 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 1 Mar 2024 01:41:44 +0100 Subject: Rename inline files to .inl.h --- FoundationEx/Dictionary.h | 2 +- FoundationEx/Dictionary.inl | 246 ------------------------ FoundationEx/Dictionary.inl.h | 246 ++++++++++++++++++++++++ FoundationEx/List.h | 2 +- FoundationEx/List.inl | 432 ------------------------------------------ FoundationEx/List.inl.h | 432 ++++++++++++++++++++++++++++++++++++++++++ StarsEx/Clock.h | 2 +- StarsEx/Clock.inl | 28 --- StarsEx/Clock.inl.h | 28 +++ 9 files changed, 709 insertions(+), 709 deletions(-) delete mode 100644 FoundationEx/Dictionary.inl create mode 100644 FoundationEx/Dictionary.inl.h delete mode 100644 FoundationEx/List.inl create mode 100644 FoundationEx/List.inl.h delete mode 100644 StarsEx/Clock.inl create mode 100644 StarsEx/Clock.inl.h diff --git a/FoundationEx/Dictionary.h b/FoundationEx/Dictionary.h index dae9ca4..bcb30ed 100644 --- a/FoundationEx/Dictionary.h +++ b/FoundationEx/Dictionary.h @@ -95,6 +95,6 @@ public: // +-------------------------------------------------------------------+ -#include "Dictionary.inl" +#include "Dictionary.inl.h" #endif // Dictionary_h diff --git a/FoundationEx/Dictionary.inl b/FoundationEx/Dictionary.inl deleted file mode 100644 index cd58679..0000000 --- a/FoundationEx/Dictionary.inl +++ /dev/null @@ -1,246 +0,0 @@ -/* Starshatter: The Open Source Project - Copyright (c) 2021-2022, Starshatter: The Open Source Project Contributors - Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors - Copyright (c) 1997-2006, Destroyer Studios LLC. - - AUTHOR: John DiCamillo - - - OVERVIEW - ======== - Implementation of the Dictionary class -*/ - -#ifndef NDEBUG -#define DICT_CHECK(a, b) if ((a) == 0) throw b; -#else -#define DICT_CHECK(a, b) -#endif - -const int CHAINS = 256; - -// +-------------------------------------------------------------------+ - -template Dictionary::Dictionary() - : items(0) -{ init(); } - -template Dictionary::~Dictionary() -{ clear(); } - -// +-------------------------------------------------------------------+ - -template -void Dictionary::init() -{ - items = 0; - memset(table, 0, CHAINS*sizeof(PTR)); -} - -template -void Dictionary::clear() -{ - for (int i = 0; i < CHAINS; i++) { - DictionaryCell* link = table[i]; - - while (link) { - DictionaryCell* n = link->next; - delete link; - link = n; - } - } - - init(); -} - -// +-------------------------------------------------------------------+ - -template -T& Dictionary::operator[](const Text& key) -{ - int idx = key.hash() % CHAINS; - DictionaryCell* cell = table[idx]; - - if (cell == 0) { // empty chain - items++; - cell = new DictionaryCell(key); - table[idx] = cell; - return cell->value; - } - else { // search for key - while (cell->next && cell->key != key) - cell = cell->next; - - if (cell->key != key) { // not found in chain - items++; - cell->next = new DictionaryCell(key); - return cell->next->value; - } - else { // found: return it! - return cell->value; - } - } -} - -// +-------------------------------------------------------------------+ - -template -void Dictionary::insert(const Text& key, const T& val) -{ - T& value = operator[](key); - value = val; -} - -// +-------------------------------------------------------------------+ - -template -void Dictionary::remove(const Text& key) -{ - int idx = key.hash() % CHAINS; - DictionaryCell* cell = table[idx]; - - if (cell == 0) { // empty chain - return; - } - else { // search for key - while (cell->next && cell->key != key) - cell = cell->next; - - if (cell->key != key) { // not found in chain - return; - } - else { // found: remove it! - if (table[idx] == cell) { - table[idx] = cell->next; - delete cell; - } - else { - DictionaryCell* p = table[idx]; - while (p->next != cell) - p = p->next; - p->next = cell->next; - delete cell; - } - } - } -} - -// +-------------------------------------------------------------------+ - -template -int Dictionary::contains(const Text& key) const -{ - int idx = key.hash() % CHAINS; - DictionaryCell* cell = table[idx]; - - if (cell != 0) { - while (cell->next && cell->key != key) - cell = cell->next; - - if (cell->key == key) - return 1; - } - - return 0; -} - -// +-------------------------------------------------------------------+ - -template -T Dictionary::find(const Text& key, T defval) const -{ - int idx = key.hash() % CHAINS; - DictionaryCell* cell = table[idx]; - - if (cell != 0) { - while (cell->next && cell->key != key) - cell = cell->next; - - if (cell->key == key) - return cell->value; - } - - return defval; -} - -// +-------------------------------------------------------------------+ - -template DictionaryIter::DictionaryIter(Dictionary& d) - : dict(&d), chain(0), here(0) -{ } - -template DictionaryIter::~DictionaryIter() -{ } - -// +-------------------------------------------------------------------+ - -template -void DictionaryIter::reset() -{ - chain = 0; - here = 0; -} - -// +-------------------------------------------------------------------+ - -template -Text DictionaryIter::key() const -{ - return here->key; -} - -template -T DictionaryIter::value() const -{ - return here->value; -} - -// +-------------------------------------------------------------------+ - -template -int DictionaryIter::operator++() -{ - forth(); - int more = chain < CHAINS; - return more; -} - -// +-------------------------------------------------------------------+ - -template -void DictionaryIter::forth() -{ - if (here) { - here = here->next; - if (!here) // off the end of this chain - chain++; - } - - if (!here) { - while (!dict->table[chain] && chain < CHAINS) - chain++; - - if (chain < CHAINS) - here = dict->table[chain]; - else - here = 0; - } -} - -// +-------------------------------------------------------------------+ - -template -void DictionaryIter::attach(Dictionary& d) -{ - dict = &d; - reset(); -} - -// +-------------------------------------------------------------------+ - -template -Dictionary& DictionaryIter::container() -{ - return *dict; -} - diff --git a/FoundationEx/Dictionary.inl.h b/FoundationEx/Dictionary.inl.h new file mode 100644 index 0000000..cd58679 --- /dev/null +++ b/FoundationEx/Dictionary.inl.h @@ -0,0 +1,246 @@ +/* Starshatter: The Open Source Project + Copyright (c) 2021-2022, Starshatter: The Open Source Project Contributors + Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors + Copyright (c) 1997-2006, Destroyer Studios LLC. + + AUTHOR: John DiCamillo + + + OVERVIEW + ======== + Implementation of the Dictionary class +*/ + +#ifndef NDEBUG +#define DICT_CHECK(a, b) if ((a) == 0) throw b; +#else +#define DICT_CHECK(a, b) +#endif + +const int CHAINS = 256; + +// +-------------------------------------------------------------------+ + +template Dictionary::Dictionary() + : items(0) +{ init(); } + +template Dictionary::~Dictionary() +{ clear(); } + +// +-------------------------------------------------------------------+ + +template +void Dictionary::init() +{ + items = 0; + memset(table, 0, CHAINS*sizeof(PTR)); +} + +template +void Dictionary::clear() +{ + for (int i = 0; i < CHAINS; i++) { + DictionaryCell* link = table[i]; + + while (link) { + DictionaryCell* n = link->next; + delete link; + link = n; + } + } + + init(); +} + +// +-------------------------------------------------------------------+ + +template +T& Dictionary::operator[](const Text& key) +{ + int idx = key.hash() % CHAINS; + DictionaryCell* cell = table[idx]; + + if (cell == 0) { // empty chain + items++; + cell = new DictionaryCell(key); + table[idx] = cell; + return cell->value; + } + else { // search for key + while (cell->next && cell->key != key) + cell = cell->next; + + if (cell->key != key) { // not found in chain + items++; + cell->next = new DictionaryCell(key); + return cell->next->value; + } + else { // found: return it! + return cell->value; + } + } +} + +// +-------------------------------------------------------------------+ + +template +void Dictionary::insert(const Text& key, const T& val) +{ + T& value = operator[](key); + value = val; +} + +// +-------------------------------------------------------------------+ + +template +void Dictionary::remove(const Text& key) +{ + int idx = key.hash() % CHAINS; + DictionaryCell* cell = table[idx]; + + if (cell == 0) { // empty chain + return; + } + else { // search for key + while (cell->next && cell->key != key) + cell = cell->next; + + if (cell->key != key) { // not found in chain + return; + } + else { // found: remove it! + if (table[idx] == cell) { + table[idx] = cell->next; + delete cell; + } + else { + DictionaryCell* p = table[idx]; + while (p->next != cell) + p = p->next; + p->next = cell->next; + delete cell; + } + } + } +} + +// +-------------------------------------------------------------------+ + +template +int Dictionary::contains(const Text& key) const +{ + int idx = key.hash() % CHAINS; + DictionaryCell* cell = table[idx]; + + if (cell != 0) { + while (cell->next && cell->key != key) + cell = cell->next; + + if (cell->key == key) + return 1; + } + + return 0; +} + +// +-------------------------------------------------------------------+ + +template +T Dictionary::find(const Text& key, T defval) const +{ + int idx = key.hash() % CHAINS; + DictionaryCell* cell = table[idx]; + + if (cell != 0) { + while (cell->next && cell->key != key) + cell = cell->next; + + if (cell->key == key) + return cell->value; + } + + return defval; +} + +// +-------------------------------------------------------------------+ + +template DictionaryIter::DictionaryIter(Dictionary& d) + : dict(&d), chain(0), here(0) +{ } + +template DictionaryIter::~DictionaryIter() +{ } + +// +-------------------------------------------------------------------+ + +template +void DictionaryIter::reset() +{ + chain = 0; + here = 0; +} + +// +-------------------------------------------------------------------+ + +template +Text DictionaryIter::key() const +{ + return here->key; +} + +template +T DictionaryIter::value() const +{ + return here->value; +} + +// +-------------------------------------------------------------------+ + +template +int DictionaryIter::operator++() +{ + forth(); + int more = chain < CHAINS; + return more; +} + +// +-------------------------------------------------------------------+ + +template +void DictionaryIter::forth() +{ + if (here) { + here = here->next; + if (!here) // off the end of this chain + chain++; + } + + if (!here) { + while (!dict->table[chain] && chain < CHAINS) + chain++; + + if (chain < CHAINS) + here = dict->table[chain]; + else + here = 0; + } +} + +// +-------------------------------------------------------------------+ + +template +void DictionaryIter::attach(Dictionary& d) +{ + dict = &d; + reset(); +} + +// +-------------------------------------------------------------------+ + +template +Dictionary& DictionaryIter::container() +{ + return *dict; +} + diff --git a/FoundationEx/List.h b/FoundationEx/List.h index 12fc635..54dfcb1 100644 --- a/FoundationEx/List.h +++ b/FoundationEx/List.h @@ -101,6 +101,6 @@ private: int step; }; -#include "List.inl" +#include "List.inl.h" #endif // List_h diff --git a/FoundationEx/List.inl b/FoundationEx/List.inl deleted file mode 100644 index 9ccb796..0000000 --- a/FoundationEx/List.inl +++ /dev/null @@ -1,432 +0,0 @@ -/* Starshatter: The Open Source Project - Copyright (c) 2021-2022, Starshatter: The Open Source Project Contributors - Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors - Copyright (c) 1997-2006, Destroyer Studios LLC. - - AUTHOR: John DiCamillo - - - OVERVIEW - ======== - Implementation of the List class template -*/ - -#include - -#include "Utils.h" - - -template -List::List(const List& l) - : items(l.items), extent(l.extent) -{ - array = new PTR[extent]; - for (int i = 0; i < extent; i++) - array[i] = l.array[i]; -} - -template -void List::clear() -{ - delete [] array; - items = 0; - extent = 0; - array = 0; -} - -template -void List::destroy() -{ - if (items) { - items = 0; // prevent dangerous re-entrancy - - for (int i = 0; i < extent; i++) - delete array[i]; - - delete [] array; - items = 0; - extent = 0; - array = 0; - } -} - -// +-------------------------------------------------------------------+ - -template -bool List::check(int& index) const -{ - if (index < 0) { - Print("Bounds error in List(%08p) T=%s index=%d min=0\n", this, T::TYPENAME(), index); - index = 0; - } - - else if (index >= items) { - Print("Bounds error in List(%08p) T=%s index=%d max=%d\n", this, T::TYPENAME(), index, items-1); - index = items-1; - } - - return (index >= 0 && index < items); -} - -// +-------------------------------------------------------------------+ - -template -T*& List::operator[](int index) -{ - if (check(index)) - return array[index]; - - if (!array || !extent) - resize(1); - - return array[0]; -} - -template -T* List::operator[](int index) const -{ - if (check(index)) - return array[index]; - return 0; -} - -template -T*& List::at(int index) -{ - if (check(index)) - return array[index]; - - if (!array || !extent) - resize(1); - - return array[0]; -} - -template -T* List::at(int index) const -{ - if (check(index)) - return array[index]; - return 0; -} - -// +-------------------------------------------------------------------+ - -template -void List::resize(int newsize) -{ - if (newsize > extent) { - extent = 16 * (newsize/16 + 1); - T** v = new PTR[extent]; - int i; - for (i = 0; i < items; i++) - v[i] = array[i]; - - for (; i < extent; i++) - v[i] = 0; - - delete [] array; - array = v; - } -} - -// +-------------------------------------------------------------------+ - -template -void List::append(const T* item) -{ - if (item) { - if (items+1 > extent) resize(items+1); - array[items++] = (T*)item; - } -} - -template -void List::append(List& list) -{ - if (&list != this && list.items > 0) { - int need = items + list.items; - if (need > extent) resize(need); - - for (int i = 0; i < list.items; i++) - array[items++] = list.array[i]; - } -} - -// +-------------------------------------------------------------------+ - -template -void List::insert(const T* item, int index) -{ - if (item && index >= 0 && index <= items) { - if (items+1 > extent) resize(items+1); - - // slide right: - for (int i = items; i > index; i--) - array[i] = array[i-1]; - - array[index] = (T*)item; - items++; - } -} - -// +-------------------------------------------------------------------+ - -template -void List::insertSort(const T* item) -{ - if (item) { - int i; - for (i = 0; i < items; i++) { - if (*item < *array[i]) - break; - } - - insert(item, i); - } -} - -// +-------------------------------------------------------------------+ - -template -T* List::remove(const T* val) -{ - if (items == 0 || val == 0) - return 0; - - for (int i = 0; i < items; i++) { - if (array[i] == val) { - return removeIndex(i); - } - } - - return 0; -} - -// +-------------------------------------------------------------------+ - -template -T* List::removeIndex(int index) -{ - if (!check(index)) - return 0; - - T* tmp = array[index]; - array[index] = 0; - - // slide left: - for (int i = index; i < items-1; i++) - array[i] = array[i+1]; - - // blank out the hole we just created: - array[items-1] = 0; - - items--; - return tmp; -} - -// +-------------------------------------------------------------------+ - -template -bool List::contains(const T* val) const -{ - if (val) { - if (index(val) != -1) - return true; - } - - return false; -} - -// +-------------------------------------------------------------------+ - -template -int List::count(const T* val) const -{ - int c = 0; - - if (val) { - for (int i = 0; i < items; i++) { - if (array[i] && ((*array[i])==(*val))) - c++; - } - } - - return c; -} - -// +-------------------------------------------------------------------+ - -template -int List::index(const T* val) const -{ - if (val) { - for (int i = 0; i < items; i++) { - if (array[i] && ((*array[i])==(*val))) - return i; - } - } - - return -1; -} - -// +-------------------------------------------------------------------+ - -template -T* List::find(const T* val) const -{ - if (val) { - for (int i = 0; i < items; i++) { - if (array[i] && ((*array[i])==(*val))) - return array[i]; - } - } - - return 0; -} - -// +-------------------------------------------------------------------+ - -template -void List::swap(T** a, int i, int j) -{ - if (i >= 0 && i < items && j >= 0 && j < items && i != j) { - T* t = a[i]; - a[i] = a[j]; - a[j] = t; - } -} - -template -void List::qsort(T** a, int lo0, int hi0) -{ - int lo = lo0; - int hi = hi0; - - // zero or one element list, nothing to do: - if (lo >= hi) { - return; - } - - // two element list, swap if needed: - else if (lo == hi-1) { - if (*a[hi] < *a[lo]) { - swap(a, lo, hi); - } - return; - } - - // pick a pivot, and move it out of the way: - int mid = (lo+hi)/2; - T* pivot = a[mid]; - a[mid] = a[hi]; - a[hi] = pivot; - - while (lo < hi) { - while ((*a[lo] <= *pivot) && lo < hi) lo++; - while ((*pivot <= *a[hi]) && lo < hi) hi--; - - if (lo < hi) { - swap(a, lo, hi); - } - } - - // Put the pivot into its final location: - a[hi0] = a[hi]; - a[hi] = pivot; - - qsort(a, lo0, lo-1); - qsort(a, hi+1, hi0); -} - -template -void List::sort() -{ - if (items < 2) - return; - - qsort(array, 0, items-1); -} - -template -void List::shuffle() -{ - if (items < 3) - return; - - for (int s = 0; s < 5; s++) { - for (int i = 0; i < items; i++) { - int j = (rand()>>4) % items; - swap(array, i, j); - } - } -} - -// +===================================================================+ - -template -T* ListIter::value() -{ - if (list && step >= 0 && step < list->items) - return list->array[step]; - - return 0; -} - -// +-------------------------------------------------------------------+ - -template -T* ListIter::removeItem() -{ - if (list && step >= 0 && step < list->items) - return list->removeIndex(step--); - - return 0; -} - -// +-------------------------------------------------------------------+ - -template -T* ListIter::next() -{ - if (list && step >= -1 && step < list->items-1) - return list->array[++step]; - - return 0; -} - -template -T* ListIter::prev() -{ - if (list && step > 0 && step < list->items) - return list->array[--step]; - - return 0; -} - -// +-------------------------------------------------------------------+ - -template -void ListIter::attach(List& l) -{ - list = &l; - step = -1; -} - -// +-------------------------------------------------------------------+ - -template -int ListIter::size() -{ - if (!list) return 0; - return list->items; -} - -// +-------------------------------------------------------------------+ - -template -List& ListIter::container() -{ - return *list; -} - diff --git a/FoundationEx/List.inl.h b/FoundationEx/List.inl.h new file mode 100644 index 0000000..9ccb796 --- /dev/null +++ b/FoundationEx/List.inl.h @@ -0,0 +1,432 @@ +/* Starshatter: The Open Source Project + Copyright (c) 2021-2022, Starshatter: The Open Source Project Contributors + Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors + Copyright (c) 1997-2006, Destroyer Studios LLC. + + AUTHOR: John DiCamillo + + + OVERVIEW + ======== + Implementation of the List class template +*/ + +#include + +#include "Utils.h" + + +template +List::List(const List& l) + : items(l.items), extent(l.extent) +{ + array = new PTR[extent]; + for (int i = 0; i < extent; i++) + array[i] = l.array[i]; +} + +template +void List::clear() +{ + delete [] array; + items = 0; + extent = 0; + array = 0; +} + +template +void List::destroy() +{ + if (items) { + items = 0; // prevent dangerous re-entrancy + + for (int i = 0; i < extent; i++) + delete array[i]; + + delete [] array; + items = 0; + extent = 0; + array = 0; + } +} + +// +-------------------------------------------------------------------+ + +template +bool List::check(int& index) const +{ + if (index < 0) { + Print("Bounds error in List(%08p) T=%s index=%d min=0\n", this, T::TYPENAME(), index); + index = 0; + } + + else if (index >= items) { + Print("Bounds error in List(%08p) T=%s index=%d max=%d\n", this, T::TYPENAME(), index, items-1); + index = items-1; + } + + return (index >= 0 && index < items); +} + +// +-------------------------------------------------------------------+ + +template +T*& List::operator[](int index) +{ + if (check(index)) + return array[index]; + + if (!array || !extent) + resize(1); + + return array[0]; +} + +template +T* List::operator[](int index) const +{ + if (check(index)) + return array[index]; + return 0; +} + +template +T*& List::at(int index) +{ + if (check(index)) + return array[index]; + + if (!array || !extent) + resize(1); + + return array[0]; +} + +template +T* List::at(int index) const +{ + if (check(index)) + return array[index]; + return 0; +} + +// +-------------------------------------------------------------------+ + +template +void List::resize(int newsize) +{ + if (newsize > extent) { + extent = 16 * (newsize/16 + 1); + T** v = new PTR[extent]; + int i; + for (i = 0; i < items; i++) + v[i] = array[i]; + + for (; i < extent; i++) + v[i] = 0; + + delete [] array; + array = v; + } +} + +// +-------------------------------------------------------------------+ + +template +void List::append(const T* item) +{ + if (item) { + if (items+1 > extent) resize(items+1); + array[items++] = (T*)item; + } +} + +template +void List::append(List& list) +{ + if (&list != this && list.items > 0) { + int need = items + list.items; + if (need > extent) resize(need); + + for (int i = 0; i < list.items; i++) + array[items++] = list.array[i]; + } +} + +// +-------------------------------------------------------------------+ + +template +void List::insert(const T* item, int index) +{ + if (item && index >= 0 && index <= items) { + if (items+1 > extent) resize(items+1); + + // slide right: + for (int i = items; i > index; i--) + array[i] = array[i-1]; + + array[index] = (T*)item; + items++; + } +} + +// +-------------------------------------------------------------------+ + +template +void List::insertSort(const T* item) +{ + if (item) { + int i; + for (i = 0; i < items; i++) { + if (*item < *array[i]) + break; + } + + insert(item, i); + } +} + +// +-------------------------------------------------------------------+ + +template +T* List::remove(const T* val) +{ + if (items == 0 || val == 0) + return 0; + + for (int i = 0; i < items; i++) { + if (array[i] == val) { + return removeIndex(i); + } + } + + return 0; +} + +// +-------------------------------------------------------------------+ + +template +T* List::removeIndex(int index) +{ + if (!check(index)) + return 0; + + T* tmp = array[index]; + array[index] = 0; + + // slide left: + for (int i = index; i < items-1; i++) + array[i] = array[i+1]; + + // blank out the hole we just created: + array[items-1] = 0; + + items--; + return tmp; +} + +// +-------------------------------------------------------------------+ + +template +bool List::contains(const T* val) const +{ + if (val) { + if (index(val) != -1) + return true; + } + + return false; +} + +// +-------------------------------------------------------------------+ + +template +int List::count(const T* val) const +{ + int c = 0; + + if (val) { + for (int i = 0; i < items; i++) { + if (array[i] && ((*array[i])==(*val))) + c++; + } + } + + return c; +} + +// +-------------------------------------------------------------------+ + +template +int List::index(const T* val) const +{ + if (val) { + for (int i = 0; i < items; i++) { + if (array[i] && ((*array[i])==(*val))) + return i; + } + } + + return -1; +} + +// +-------------------------------------------------------------------+ + +template +T* List::find(const T* val) const +{ + if (val) { + for (int i = 0; i < items; i++) { + if (array[i] && ((*array[i])==(*val))) + return array[i]; + } + } + + return 0; +} + +// +-------------------------------------------------------------------+ + +template +void List::swap(T** a, int i, int j) +{ + if (i >= 0 && i < items && j >= 0 && j < items && i != j) { + T* t = a[i]; + a[i] = a[j]; + a[j] = t; + } +} + +template +void List::qsort(T** a, int lo0, int hi0) +{ + int lo = lo0; + int hi = hi0; + + // zero or one element list, nothing to do: + if (lo >= hi) { + return; + } + + // two element list, swap if needed: + else if (lo == hi-1) { + if (*a[hi] < *a[lo]) { + swap(a, lo, hi); + } + return; + } + + // pick a pivot, and move it out of the way: + int mid = (lo+hi)/2; + T* pivot = a[mid]; + a[mid] = a[hi]; + a[hi] = pivot; + + while (lo < hi) { + while ((*a[lo] <= *pivot) && lo < hi) lo++; + while ((*pivot <= *a[hi]) && lo < hi) hi--; + + if (lo < hi) { + swap(a, lo, hi); + } + } + + // Put the pivot into its final location: + a[hi0] = a[hi]; + a[hi] = pivot; + + qsort(a, lo0, lo-1); + qsort(a, hi+1, hi0); +} + +template +void List::sort() +{ + if (items < 2) + return; + + qsort(array, 0, items-1); +} + +template +void List::shuffle() +{ + if (items < 3) + return; + + for (int s = 0; s < 5; s++) { + for (int i = 0; i < items; i++) { + int j = (rand()>>4) % items; + swap(array, i, j); + } + } +} + +// +===================================================================+ + +template +T* ListIter::value() +{ + if (list && step >= 0 && step < list->items) + return list->array[step]; + + return 0; +} + +// +-------------------------------------------------------------------+ + +template +T* ListIter::removeItem() +{ + if (list && step >= 0 && step < list->items) + return list->removeIndex(step--); + + return 0; +} + +// +-------------------------------------------------------------------+ + +template +T* ListIter::next() +{ + if (list && step >= -1 && step < list->items-1) + return list->array[++step]; + + return 0; +} + +template +T* ListIter::prev() +{ + if (list && step > 0 && step < list->items) + return list->array[--step]; + + return 0; +} + +// +-------------------------------------------------------------------+ + +template +void ListIter::attach(List& l) +{ + list = &l; + step = -1; +} + +// +-------------------------------------------------------------------+ + +template +int ListIter::size() +{ + if (!list) return 0; + return list->items; +} + +// +-------------------------------------------------------------------+ + +template +List& ListIter::container() +{ + return *list; +} + diff --git a/StarsEx/Clock.h b/StarsEx/Clock.h index 39e08ac..238616d 100644 --- a/StarsEx/Clock.h +++ b/StarsEx/Clock.h @@ -50,6 +50,6 @@ private: }; -#include "Clock.inl" +#include "Clock.inl.h" #endif // Clock_h diff --git a/StarsEx/Clock.inl b/StarsEx/Clock.inl deleted file mode 100644 index 42a2693..0000000 --- a/StarsEx/Clock.inl +++ /dev/null @@ -1,28 +0,0 @@ -/* Starshatter: The Open Source Project - Copyright (c) 2021-2022, Starshatter: The Open Source Project Contributors - Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors - Copyright (c) 1997-2006, Destroyer Studios LLC. -*/ - -#include "Clock.h" - -#include -#include - - -template -R -Clock::GameTime() const -{ - using target_duration = std::chrono::duration; - return std::chrono::duration_cast(m_game_elapsed).count(); -} - - -template -R -Clock::RealTime() const -{ - using target_duration = std::chrono::duration; - return std::chrono::duration_cast(m_real_elapsed).count(); -} diff --git a/StarsEx/Clock.inl.h b/StarsEx/Clock.inl.h new file mode 100644 index 0000000..42a2693 --- /dev/null +++ b/StarsEx/Clock.inl.h @@ -0,0 +1,28 @@ +/* Starshatter: The Open Source Project + Copyright (c) 2021-2022, Starshatter: The Open Source Project Contributors + Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors + Copyright (c) 1997-2006, Destroyer Studios LLC. +*/ + +#include "Clock.h" + +#include +#include + + +template +R +Clock::GameTime() const +{ + using target_duration = std::chrono::duration; + return std::chrono::duration_cast(m_game_elapsed).count(); +} + + +template +R +Clock::RealTime() const +{ + using target_duration = std::chrono::duration; + return std::chrono::duration_cast(m_real_elapsed).count(); +} -- cgit v1.1