Merge branch 'master' into jgrpp

# Conflicts:
#	src/genworld_gui.cpp
#	src/group_gui.cpp
#	src/saveload/saveload.cpp
#	src/settings_gui.cpp
#	src/toolbar_gui.cpp
#	src/vehicle_gui.cpp
#	src/vehicle_gui_base.h
#	src/widgets/dropdown.cpp
#	src/widgets/dropdown_type.h
This commit is contained in:
Jonathan G Rennison
2019-04-11 18:12:22 +01:00
53 changed files with 587 additions and 627 deletions

View File

@@ -167,7 +167,7 @@ public:
template <typename T>
class AutoFreePtr
{
T *ptr; ///< Stored pointer.
T *ptr = nullptr; ///< Stored pointer.
public:
AutoFreePtr(T *ptr) : ptr(ptr) {}
@@ -192,6 +192,18 @@ public:
inline operator T *() { return this->ptr; }
/** Cast to underlaying regular pointer. */
inline operator const T *() const { return this->ptr; }
AutoFreePtr(AutoFreePtr<T> &&other) noexcept
{
*this = std::move(other);
}
AutoFreePtr& operator=(AutoFreePtr<T> &&other) noexcept
{
this->Assign(other.ptr);
other.ptr = nullptr;
return *this;
}
};
#endif /* ALLOC_TYPE_HPP */

View File

@@ -69,66 +69,4 @@ T* grow(std::vector<T>& vec, std::size_t num)
return vec.data() + pos;
}
/**
* Simple vector template class, with automatic free.
*
* @note There are no asserts in the class so you have
* to care about that you grab an item which is
* inside the list.
*
* @param T The type of the items stored, must be a pointer
*/
template <typename T>
class AutoFreeSmallVector : public std::vector<T> {
public:
~AutoFreeSmallVector()
{
this->Clear();
}
/**
* Remove all items from the list.
*/
inline void Clear()
{
for (T p : *this) {
free(p);
}
std::vector<T>::clear();
}
};
/**
* Simple vector template class, with automatic delete.
*
* @note There are no asserts in the class so you have
* to care about that you grab an item which is
* inside the list.
*
* @param T The type of the items stored, must be a pointer
*/
template <typename T>
class AutoDeleteSmallVector : public std::vector<T> {
public:
~AutoDeleteSmallVector()
{
this->Clear();
}
/**
* Remove all items from the list.
*/
inline void Clear()
{
for (T p : *this) {
delete p;
}
std::vector<T>::clear();
}
};
typedef AutoFreeSmallVector<char*> StringList; ///< Type for a list of strings.
#endif /* SMALLVEC_TYPE_HPP */