Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnings about adding controls/interactions multiple times #107

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 78 additions & 80 deletions Kassiopeia/Utility/Include/KSList.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef KSLIST_H_
#define KSLIST_H_

#include <typeinfo>

namespace Kassiopeia
{

Expand Down Expand Up @@ -70,25 +72,24 @@ template<class XType> class KSList

private:
XType** fElements;
mutable int fCurrentElement;
int fEndElement;
const int fLastElement;
};

template<class XType>
KSList<XType>::KSList(const int aMaxSize) : fCurrentElement(0), fEndElement(0), fLastElement(aMaxSize)
KSList<XType>::KSList(const int aMaxSize) : fEndElement(0), fLastElement(aMaxSize)
{
fElements = new XType*[fLastElement];
for (fCurrentElement = 0; fCurrentElement < fLastElement; fCurrentElement++) {
fElements[fCurrentElement] = nullptr;
for (int currentElement = 0; currentElement < fLastElement; currentElement++) {
fElements[currentElement] = nullptr;
}
}
template<class XType>
KSList<XType>::KSList(const KSList& aCopy) : fCurrentElement(0), fEndElement(0), fLastElement(aCopy.fLastElement)
KSList<XType>::KSList(const KSList& aCopy) : fEndElement(0), fLastElement(aCopy.fLastElement)
{
fElements = new XType*[fLastElement];
for (fCurrentElement = 0; fCurrentElement < fLastElement; fCurrentElement++) {
fElements[fCurrentElement] = aCopy.fElements[fCurrentElement];
for (int currentElement = 0; currentElement < fLastElement; currentElement++) {
fElements[currentElement] = aCopy.fElements[currentElement];
}
}
template<class XType> KSList<XType>::~KSList()
Expand All @@ -107,20 +108,20 @@ template<class XType> bool KSList<XType>::Full() const

template<class XType> void KSList<XType>::ClearContent()
{
for (fCurrentElement = 0; fCurrentElement < fEndElement; fCurrentElement++) {
if (fElements[fCurrentElement] != nullptr) {
fElements[fCurrentElement] = nullptr;
for (int currentElement = 0; currentElement < fEndElement; currentElement++) {
if (fElements[currentElement] != nullptr) {
fElements[currentElement] = nullptr;
}
}
fEndElement = 0;
return;
}
template<class XType> void KSList<XType>::DeleteContent()
{
for (fCurrentElement = 0; fCurrentElement < fEndElement; fCurrentElement++) {
if (fElements[fCurrentElement] != nullptr) {
delete fElements[fCurrentElement];
fElements[fCurrentElement] = nullptr;
for (int currentElement = 0; currentElement < fEndElement; currentElement++) {
if (fElements[currentElement] != nullptr) {
delete fElements[currentElement];
fElements[currentElement] = nullptr;
}
}
fEndElement = 0;
Expand All @@ -132,45 +133,43 @@ template<class XType> int KSList<XType>::AddElement(XType* anElement)
if (fEndElement == fLastElement) {
return -1;
}
fCurrentElement = fEndElement;
fElements[fCurrentElement] = anElement;
const int currentElement = fEndElement;
fElements[currentElement] = anElement;
fEndElement++;
return fCurrentElement;
return currentElement;
}
template<class XType> int KSList<XType>::FindElement(XType* anElement)
{
int tIndex = -1;
for (fCurrentElement = 0; fCurrentElement < fEndElement; fCurrentElement++) {
if (fElements[fCurrentElement] == anElement) {
tIndex = fCurrentElement;
break;
for (int currentElement = 0; currentElement < fEndElement; currentElement++) {
if (fElements[currentElement] == anElement) {
return currentElement;
}
}
return tIndex;
return -1;
}
template<class XType> int KSList<XType>::FindElementByType(XType*)
template<class XType> int KSList<XType>::FindElementByType(XType* anElement)
{
int tIndex = -1;
for (fCurrentElement = 0; fCurrentElement < fEndElement; fCurrentElement++) {
if (dynamic_cast<XType*>(fElements[fCurrentElement]) != nullptr) {
tIndex = fCurrentElement;
break;
const std::type_info& elementType = typeid(*anElement);
for (int currentElement = 0; currentElement < fEndElement; currentElement++) {
const std::type_info& compareType = typeid(*fElements[currentElement]);
if (elementType == compareType) {
return currentElement;
}
}
return tIndex;
return -1;
}
template<class XType> int KSList<XType>::RemoveElement(XType* anElement)
{
int tIndex = -1;
for (fCurrentElement = 0; fCurrentElement < fEndElement; fCurrentElement++) {
for (int currentElement = 0; currentElement < fEndElement; currentElement++) {
if (tIndex == -1) {
if (fElements[fCurrentElement] == anElement) {
fElements[fCurrentElement] = nullptr;
tIndex = fCurrentElement;
if (fElements[currentElement] == anElement) {
fElements[currentElement] = nullptr;
tIndex = currentElement;
}
continue;
}
fElements[fCurrentElement - 1] = fElements[fCurrentElement];
fElements[currentElement - 1] = fElements[currentElement];
}
if (tIndex != -1) {
fEndElement--;
Expand All @@ -180,46 +179,45 @@ template<class XType> int KSList<XType>::RemoveElement(XType* anElement)
}
template<class XType> XType* KSList<XType>::ElementAt(int& anIndex) const
{
fCurrentElement = anIndex;
if (fCurrentElement >= fEndElement || fCurrentElement < 0) {
if (anIndex >= fEndElement || anIndex < 0) {
return nullptr;
}
return fElements[fCurrentElement];
return fElements[anIndex];
}

template<class XType>
template<class XReturnType, class XClassType>
void KSList<XType>::ForEach(XReturnType (XClassType::*aMember)())
{
for (fCurrentElement = 0; fCurrentElement < fEndElement; fCurrentElement++) {
(fElements[fCurrentElement]->*aMember)();
for (int currentElement = 0; currentElement < fEndElement; currentElement++) {
(fElements[currentElement]->*aMember)();
}
return;
}
template<class XType>
template<class XReturnType, class XClassType>
void KSList<XType>::ForEach(XReturnType (XClassType::*aMember)() const)
{
for (fCurrentElement = 0; fCurrentElement < fEndElement; fCurrentElement++) {
(fElements[fCurrentElement]->*aMember)();
for (int currentElement = 0; currentElement < fEndElement; currentElement++) {
(fElements[currentElement]->*aMember)();
}
return;
}
template<class XType>
template<class XReturnType, class XClassType, class XArgumentType>
void KSList<XType>::ForEach(XReturnType (XClassType::*aMember)(XArgumentType), XArgumentType anArgument)
{
for (fCurrentElement = 0; fCurrentElement < fEndElement; fCurrentElement++) {
(fElements[fCurrentElement]->*aMember)(anArgument);
for (int currentElement = 0; currentElement < fEndElement; currentElement++) {
(fElements[currentElement]->*aMember)(anArgument);
}
return;
}
template<class XType>
template<class XReturnType, class XClassType, class XArgumentType>
void KSList<XType>::ForEach(XReturnType (XClassType::*aMember)(XArgumentType) const, XArgumentType anArgument)
{
for (fCurrentElement = 0; fCurrentElement < fEndElement; fCurrentElement++) {
(fElements[fCurrentElement]->*aMember)(anArgument);
for (int currentElement = 0; currentElement < fEndElement; currentElement++) {
(fElements[currentElement]->*aMember)(anArgument);
}
return;
}
Expand All @@ -229,8 +227,8 @@ template<class XReturnType, class XClassType, class XArgumentType1, class XArgum
void KSList<XType>::ForEach(XReturnType (XClassType::*aMember)(XArgumentType1, XArgumentType2),
XArgumentType1 anArgument1, XArgumentType2 anArgument2)
{
for (fCurrentElement = 0; fCurrentElement < fEndElement; fCurrentElement++) {
(fElements[fCurrentElement]->*aMember)(anArgument1, anArgument2);
for (int currentElement = 0; currentElement < fEndElement; currentElement++) {
(fElements[currentElement]->*aMember)(anArgument1, anArgument2);
}
return;
}
Expand All @@ -239,16 +237,16 @@ template<class XReturnType, class XClassType, class XArgumentType1, class XArgum
void KSList<XType>::ForEach(XReturnType (XClassType::*aMember)(XArgumentType1, XArgumentType2) const,
XArgumentType1 anArgument1, XArgumentType2 anArgument2)
{
for (fCurrentElement = 0; fCurrentElement < fEndElement; fCurrentElement++) {
(fElements[fCurrentElement]->*aMember)(anArgument1, anArgument2);
for (int currentElement = 0; currentElement < fEndElement; currentElement++) {
(fElements[currentElement]->*aMember)(anArgument1, anArgument2);
}
return;
}

template<class XType> template<class XClassType> bool KSList<XType>::ForEachUntilTrue(bool (XClassType::*aMember)())
{
for (fCurrentElement = 0; fCurrentElement < fEndElement; fCurrentElement++) {
if ((fElements[fCurrentElement]->*aMember)() == true) {
for (int currentElement = 0; currentElement < fEndElement; currentElement++) {
if ((fElements[currentElement]->*aMember)() == true) {
return true;
}
}
Expand All @@ -258,8 +256,8 @@ template<class XType>
template<class XClassType>
bool KSList<XType>::ForEachUntilTrue(bool (XClassType::*aMember)() const)
{
for (fCurrentElement = 0; fCurrentElement < fEndElement; fCurrentElement++) {
if ((fElements[fCurrentElement]->*aMember)() == true) {
for (int currentElement = 0; currentElement < fEndElement; currentElement++) {
if ((fElements[currentElement]->*aMember)() == true) {
return true;
}
}
Expand All @@ -269,8 +267,8 @@ template<class XType>
template<class XClassType, class XArgumentType>
bool KSList<XType>::ForEachUntilTrue(bool (XClassType::*aMember)(XArgumentType), XArgumentType anArgument)
{
for (fCurrentElement = 0; fCurrentElement < fEndElement; fCurrentElement++) {
if ((fElements[fCurrentElement]->*aMember)(anArgument) == true) {
for (int currentElement = 0; currentElement < fEndElement; currentElement++) {
if ((fElements[currentElement]->*aMember)(anArgument) == true) {
return true;
}
}
Expand All @@ -280,8 +278,8 @@ template<class XType>
template<class XClassType, class XArgumentType>
bool KSList<XType>::ForEachUntilTrue(bool (XClassType::*aMember)(XArgumentType) const, XArgumentType anArgument)
{
for (fCurrentElement = 0; fCurrentElement < fEndElement; fCurrentElement++) {
if ((fElements[fCurrentElement]->*aMember)(anArgument) == true) {
for (int currentElement = 0; currentElement < fEndElement; currentElement++) {
if ((fElements[currentElement]->*aMember)(anArgument) == true) {
return true;
}
}
Expand All @@ -292,8 +290,8 @@ template<class XClassType, class XArgumentType1, class XArgumentType2>
bool KSList<XType>::ForEachUntilTrue(bool (XClassType::*aMember)(XArgumentType1, XArgumentType2),
XArgumentType1 anArgument1, XArgumentType2 anArgument2)
{
for (fCurrentElement = 0; fCurrentElement < fEndElement; fCurrentElement++) {
if ((fElements[fCurrentElement]->*aMember)(anArgument1, anArgument2) == true) {
for (int currentElement = 0; currentElement < fEndElement; currentElement++) {
if ((fElements[currentElement]->*aMember)(anArgument1, anArgument2) == true) {
return true;
}
}
Expand All @@ -304,8 +302,8 @@ template<class XClassType, class XArgumentType1, class XArgumentType2>
bool KSList<XType>::ForEachUntilTrue(bool (XClassType::*aMember)(XArgumentType1, XArgumentType2) const,
XArgumentType1 anArgument1, XArgumentType2 anArgument2)
{
for (fCurrentElement = 0; fCurrentElement < fEndElement; fCurrentElement++) {
if ((fElements[fCurrentElement]->*aMember)(anArgument1, anArgument2) == true) {
for (int currentElement = 0; currentElement < fEndElement; currentElement++) {
if ((fElements[currentElement]->*aMember)(anArgument1, anArgument2) == true) {
return true;
}
}
Expand All @@ -314,8 +312,8 @@ bool KSList<XType>::ForEachUntilTrue(bool (XClassType::*aMember)(XArgumentType1,

template<class XType> template<class XClassType> bool KSList<XType>::ForEachUntilFalse(bool (XClassType::*aMember)())
{
for (fCurrentElement = 0; fCurrentElement < fEndElement; fCurrentElement++) {
if ((fElements[fCurrentElement]->*aMember)() == false) {
for (int currentElement = 0; currentElement < fEndElement; currentElement++) {
if ((fElements[currentElement]->*aMember)() == false) {
return false;
}
}
Expand All @@ -325,8 +323,8 @@ template<class XType>
template<class XClassType>
bool KSList<XType>::ForEachUntilFalse(bool (XClassType::*aMember)() const)
{
for (fCurrentElement = 0; fCurrentElement < fEndElement; fCurrentElement++) {
if ((fElements[fCurrentElement]->*aMember)() == false) {
for (int currentElement = 0; currentElement < fEndElement; currentElement++) {
if ((fElements[currentElement]->*aMember)() == false) {
return false;
}
}
Expand All @@ -336,8 +334,8 @@ template<class XType>
template<class XClassType, class XArgumentType>
bool KSList<XType>::ForEachUntilFalse(bool (XClassType::*aMember)(XArgumentType), XArgumentType anArgument)
{
for (fCurrentElement = 0; fCurrentElement < fEndElement; fCurrentElement++) {
if ((fElements[fCurrentElement]->*aMember)(anArgument) == false) {
for (int currentElement = 0; currentElement < fEndElement; currentElement++) {
if ((fElements[currentElement]->*aMember)(anArgument) == false) {
return false;
}
}
Expand All @@ -347,8 +345,8 @@ template<class XType>
template<class XClassType, class XArgumentType>
bool KSList<XType>::ForEachUntilFalse(bool (XClassType::*aMember)(XArgumentType) const, XArgumentType anArgument)
{
for (fCurrentElement = 0; fCurrentElement < fEndElement; fCurrentElement++) {
if ((fElements[fCurrentElement]->*aMember)(anArgument) == false) {
for (int currentElement = 0; currentElement < fEndElement; currentElement++) {
if ((fElements[currentElement]->*aMember)(anArgument) == false) {
return false;
}
}
Expand All @@ -359,8 +357,8 @@ template<class XClassType, class XArgumentType1, class XArgumentType2>
bool KSList<XType>::ForEachUntilFalse(bool (XClassType::*aMember)(XArgumentType1, XArgumentType2),
XArgumentType1 anArgument1, XArgumentType2 anArgument2)
{
for (fCurrentElement = 0; fCurrentElement < fEndElement; fCurrentElement++) {
if ((fElements[fCurrentElement]->*aMember)(anArgument1, anArgument2) == false) {
for (int currentElement = 0; currentElement < fEndElement; currentElement++) {
if ((fElements[currentElement]->*aMember)(anArgument1, anArgument2) == false) {
return false;
}
}
Expand All @@ -371,8 +369,8 @@ template<class XClassType, class XArgumentType1, class XArgumentType2>
bool KSList<XType>::ForEachUntilFalse(bool (XClassType::*aMember)(XArgumentType1, XArgumentType2) const,
XArgumentType1 anArgument1, XArgumentType2 anArgument2)
{
for (fCurrentElement = 0; fCurrentElement < fEndElement; fCurrentElement++) {
if ((fElements[fCurrentElement]->*aMember)(anArgument1, anArgument2) == false) {
for (int currentElement = 0; currentElement < fEndElement; currentElement++) {
if ((fElements[currentElement]->*aMember)(anArgument1, anArgument2) == false) {
return false;
}
}
Expand All @@ -385,8 +383,8 @@ XReturnType KSList<XType>::LargestOfAll(XReturnType (XClassType::*aMember)())
{
XReturnType Largest = -1.e300;
XReturnType CurrentValue;
for (fCurrentElement = 0; fCurrentElement < fEndElement; fCurrentElement++) {
CurrentValue = (fElements[fCurrentElement]->*aMember)();
for (int currentElement = 0; currentElement < fEndElement; currentElement++) {
CurrentValue = (fElements[currentElement]->*aMember)();
if (CurrentValue > Largest) {
Largest = CurrentValue;
}
Expand All @@ -400,8 +398,8 @@ XReturnType KSList<XType>::SmallestOfAll(XReturnType (XClassType::*aMember)())
{
XReturnType Smallest = 1.e300;
XReturnType CurrentValue;
for (fCurrentElement = 0; fCurrentElement < fEndElement; fCurrentElement++) {
CurrentValue = (fElements[fCurrentElement]->*aMember)();
for (int currentElement = 0; currentElement < fEndElement; currentElement++) {
CurrentValue = (fElements[currentElement]->*aMember)();
if (CurrentValue < Smallest) {
Smallest = CurrentValue;
}
Expand All @@ -414,8 +412,8 @@ template<class XClassType, class XReturnType>
XReturnType KSList<XType>::SumOfAll(XReturnType (XClassType::*aMember)())
{
XReturnType Sum = 0.;
for (fCurrentElement = 0; fCurrentElement < fEndElement; fCurrentElement++) {
Sum += (fElements[fCurrentElement]->*aMember)();
for (int currentElement = 0; currentElement < fEndElement; currentElement++) {
Sum += (fElements[currentElement]->*aMember)();
}
return Sum;
}
Expand Down
Loading