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:
@@ -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 */
|
||||
|
@@ -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 */
|
||||
|
Reference in New Issue
Block a user