Changeset - r23540:8ae17b2213ea
[Not reviewed]
master
0 2 0
Henry Wilson - 6 years ago 2019-03-13 20:55:31
m3henry@googlemail.com
Codechange: Use range-based for-loop in Auto[Free|Delete]SmallVector
2 files changed with 5 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/core/smallvec_type.hpp
Show inline comments
 
@@ -82,26 +82,26 @@ template <typename T>
 
class AutoFreeSmallVector : public std::vector<T> {
 
public:
 
	~AutoFreeSmallVector()
 
	{
 
		this->Clear();
 
	}
 

	
 
	/**
 
	 * Remove all items from the list.
 
	 */
 
	inline void Clear()
 
	{
 
		for (uint i = 0; i < std::vector<T>::size(); i++) {
 
			free(std::vector<T>::operator[](i));
 
		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.
 
@@ -112,23 +112,23 @@ template <typename T>
 
class AutoDeleteSmallVector : public std::vector<T> {
 
public:
 
	~AutoDeleteSmallVector()
 
	{
 
		this->Clear();
 
	}
 

	
 
	/**
 
	 * Remove all items from the list.
 
	 */
 
	inline void Clear()
 
	{
 
		for (uint i = 0; i < std::vector<T>::size(); i++) {
 
			delete std::vector<T>::operator[](i);
 
		for (T p : *this) {
 
			delete p;
 
		}
 

	
 
		std::vector<T>::clear();
 
	}
 
};
 

	
 
typedef AutoFreeSmallVector<char*> StringList; ///< Type for a list of strings.
 

	
 
#endif /* SMALLVEC_TYPE_HPP */
src/script/squirrel_helper.hpp
Show inline comments
 
@@ -23,25 +23,25 @@ template <class CL, ScriptType ST> const
 
/**
 
 * The Squirrel convert routines
 
 */
 
namespace SQConvert {
 
	/**
 
	 * Pointers assigned to this class will be free'd when this instance
 
	 *  comes out of scope. Useful to make sure you can use stredup(),
 
	 *  without leaking memory.
 
	 */
 
	struct SQAutoFreePointers : std::vector<void *> {
 
		~SQAutoFreePointers()
 
		{
 
			for (uint i = 0; i < std::vector<void *>::size(); i++) free(std::vector<void *>::operator[](i));
 
			for (void * p : *this) free(p);
 
		}
 
	};
 

	
 
	template <bool Y> struct YesT {
 
		static const bool Yes = Y;
 
		static const bool No = !Y;
 
	};
 

	
 
	/**
 
	 * Helper class to recognize if the given type is void. Usage: 'IsVoidT<T>::Yes'
 
	 */
 
	template <typename T> struct IsVoidT : YesT<false> {};
0 comments (0 inline, 0 general)