Removed util::scoped_ptr, util::scoped_array and util::scoped_file code

This commit is contained in:
Charles Dang 2016-09-15 16:56:10 +11:00
parent 3eac7281d9
commit 04d012a692
2 changed files with 0 additions and 75 deletions

View file

@ -19,7 +19,6 @@
#include "generators/default_map_generator.hpp"
#include "generators/lua_map_generator.hpp"
#include "log.hpp"
#include "scoped_resource.hpp"
#include "serialization/string_utils.hpp"
#include <cassert>

View file

@ -114,80 +114,6 @@ public:
}
};
/**
* A helper policy for scoped_ptr.
* It will call the delete operator on a pointer, and assign the pointer to nullptr
*/
struct delete_item {
template<typename T>
void operator()(T*& p) const { delete p; p = nullptr; }
};
/**
* A helper policy for scoped_array.
* It will call the delete[] operator on a pointer, and assign the pointer to nullptr
*/
struct delete_array {
template<typename T>
void operator()(T*& p) const { delete [] p; p = nullptr; }
};
/**
* A class which implements an approximation of
* template<typename T>
* typedef scoped_resource<T*,delete_item> scoped_ptr<T>;
*
* It is a convenient synonym for a common usage of @ref scoped_resource.
* See scoped_resource for more details on how this class behaves.
*
* Usage example:
* @code
* {
* const scoped_ptr<Object> ptr(new Object);
* ...use ptr as you would a normal Object*...
* } // ptr is automatically deleted here
* @endcode
*
* NOTE: use this class only to manage a single object, *never* an array.
* Use scoped_array to manage arrays.
* This distinction is because you may call delete only
* on objects allocated with new,
* delete[] only on objects allocated with new[].
*/
template<typename T>
struct scoped_ptr : public scoped_resource<T*,delete_item>
{
explicit scoped_ptr(T* p) : scoped_resource<T*,delete_item>(p) {}
};
/**
* This class has identical behavior to @ref scoped_ptr, except it
* manages heap-allocated arrays instead of heap-allocated single objects
*
* Usage example:
* @code
* {
* const scoped_array<char> ptr(new char[n]);
* ...use ptr as you would a normal char*...
* } // ptr is automatically deleted here
* @endcode
*
*/
template<typename T>
struct scoped_array : public scoped_resource<T*,delete_array>
{
explicit scoped_array(T* p) : scoped_resource<T*,delete_array>(p) {}
};
/**
* This class specializes the scoped_resource to implement scoped FILEs.
* Not sure this is the best place to place such an utility, though.
*/
struct close_FILE
{
void operator()(std::FILE* f) const { if(f != nullptr) { std::fclose(f); } }
};
typedef scoped_resource<std::FILE*,close_FILE> scoped_FILE;
}
#endif