Add move constructor for ContainerClass and refactor it
Some checks failed
CodeQL / Analyze (push) Waiting to run
Build branch / build-all (push) Failing after 23s

This commit is contained in:
smallmodel 2025-01-31 22:53:31 +01:00
parent fdea2a2e92
commit 7b97ad6e2f
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512

View file

@ -1,6 +1,6 @@
/*
===========================================================================
Copyright (C) 2008 the OpenMoHAA team
Copyright (C) 2025 the OpenMoHAA team
This file is part of OpenMoHAA source code.
@ -33,27 +33,176 @@ class ContainerClass : public Class
Container<Type> value;
public:
virtual ~ContainerClass() { value.FreeObjectList(); }
virtual void Archive(Archiver& arc);
ContainerClass();
ContainerClass(const Container<Type>& container);
ContainerClass<Type>& operator=(const Container<Type>& container);
ContainerClass(Container<Type>&& container);
ContainerClass<Type>& operator=(Container<Type>&& container);
int AddObject(const Type& obj) { return value.AddObject(obj); }
int AddUniqueObject(const Type& obj) { return value.AddUniqueObject(obj); }
void AddObjectAt(int index, const Type& obj) { return value.AddObjectAt(index, obj); }
Type *AddressOfObjectAt(int index) { return value.AddressOfObjectAt(index); }
void ClearObjectList(void) { return value.ClearObjectList(); }
void Fix(void) { return value.Fix(); }
void FreeObjectList(void) { return value.FreeObjectList(); }
int IndexOfObject(const Type& obj) { return value.IndexOfObject(obj); }
void InsertObjectAt(int index, const Type& obj) { return value.InsertObjectAt(index, obj); }
int NumObjects(void) const { return value.NumObjects(); }
Type& ObjectAt(const size_t index) const { return value.ObjectAt(index); }
bool ObjectInList(const Type& obj) { return value.ObjectInList(obj); }
void RemoveObjectAt(int index) { return value.RemoveObjectAt(index); }
void RemoveObject(const Type& obj) { return value.RemoveObject(obj); }
void Reset(void) { return value.Reset(); }
void Resize(int maxelements) { return value.Resize(maxelements); }
void SetObjectAt(int index, const Type& obj) { return value.SetObjectAt(index, obj); }
void Sort(int (*compare)(const void *elem1, const void *elem2)) { return value.Sort(compare); }
Type& operator[](const int index) const { return value[index]; }
Container<Type>& operator=(const Container<Type>& container) { return value = container; }
~ContainerClass() override;
void Archive(Archiver& arc) override;
int AddObject(const Type& obj);
int AddUniqueObject(const Type& obj);
void AddObjectAt(int index, const Type& obj);
Type *AddressOfObjectAt(int index);
void ClearObjectList(void);
void FreeObjectList(void);
int IndexOfObject(const Type& obj);
void InsertObjectAt(int index, const Type& obj);
int NumObjects(void) const;
Type& ObjectAt(const size_t index) const;
bool ObjectInList(const Type& obj);
void RemoveObjectAt(int index);
void RemoveObject(const Type& obj);
void Reset(void);
void Resize(int maxelements);
void SetObjectAt(int index, const Type& obj);
void Sort(int (*compare)(const void *elem1, const void *elem2));
Type& operator[](const int index) const;
};
template<typename Type>
ContainerClass<Type>::ContainerClass()
{}
template<typename Type>
ContainerClass<Type>::ContainerClass(const Container<Type>& container)
: value(container)
{}
template<typename Type>
ContainerClass<Type>& ContainerClass<Type>::operator=(const Container<Type>& container)
{
value = container;
return *this;
}
template<typename Type>
ContainerClass<Type>::ContainerClass(Container<Type>&& container)
: value(std::move(container))
{}
template<typename Type>
ContainerClass<Type>& ContainerClass<Type>::operator=(Container<Type>&& container)
{
value = std::move(container);
return *this;
}
template<typename Type>
ContainerClass<Type>::~ContainerClass()
{
value.FreeObjectList();
}
template<typename Type>
int ContainerClass<Type>::AddObject(const Type& obj)
{
return value.AddObject(obj);
}
template<typename Type>
int ContainerClass<Type>::AddUniqueObject(const Type& obj)
{
return value.AddUniqueObject(obj);
}
template<typename Type>
void ContainerClass<Type>::AddObjectAt(int index, const Type& obj)
{
return value.AddObjectAt(index, obj);
}
template<typename Type>
Type *ContainerClass<Type>::AddressOfObjectAt(int index)
{
return value.AddressOfObjectAt(index);
}
template<typename Type>
void ContainerClass<Type>::ClearObjectList(void)
{
return value.ClearObjectList();
}
template<typename Type>
void ContainerClass<Type>::FreeObjectList(void)
{
return value.FreeObjectList();
}
template<typename Type>
int ContainerClass<Type>::IndexOfObject(const Type& obj)
{
return value.IndexOfObject(obj);
}
template<typename Type>
void ContainerClass<Type>::InsertObjectAt(int index, const Type& obj)
{
return value.InsertObjectAt(index, obj);
}
template<typename Type>
int ContainerClass<Type>::NumObjects(void) const
{
return value.NumObjects();
}
template<typename Type>
Type& ContainerClass<Type>::ObjectAt(const size_t index) const
{
return value.ObjectAt(index);
}
template<typename Type>
bool ContainerClass<Type>::ObjectInList(const Type& obj)
{
return value.ObjectInList(obj);
}
template<typename Type>
void ContainerClass<Type>::RemoveObjectAt(int index)
{
return value.RemoveObjectAt(index);
}
template<typename Type>
void ContainerClass<Type>::RemoveObject(const Type& obj)
{
return value.RemoveObject(obj);
}
template<typename Type>
void ContainerClass<Type>::Reset(void)
{
return value.Reset();
}
template<typename Type>
void ContainerClass<Type>::Resize(int maxelements)
{
return value.Resize(maxelements);
}
template<typename Type>
void ContainerClass<Type>::SetObjectAt(int index, const Type& obj)
{
return value.SetObjectAt(index, obj);
}
template<typename Type>
void ContainerClass<Type>::Sort(int (*compare)(const void *elem1, const void *elem2))
{
return value.Sort(compare);
}
template<typename Type>
Type& ContainerClass<Type>::operator[](const int index) const
{
return value[index];
}