Add MakeUniqueArray for array types
parent
b3b6435039
commit
25eaf8f72f
|
@ -416,7 +416,7 @@ bool CApplication::Create()
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
GetLogger()->Info("No sound support.\n");
|
GetLogger()->Info("No sound support.\n");
|
||||||
m_sound = new CSoundInterface();
|
m_sound = MakeUnique<CSoundInterface>();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_sound->Create();
|
m_sound->Create();
|
||||||
|
|
|
@ -30,3 +30,13 @@ inline std::unique_ptr<T> MakeUnique(Args&&... args)
|
||||||
{
|
{
|
||||||
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
|
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A template function to make std::unique_ptr of array type without naked new
|
||||||
|
* It can be replaced with std::make_unique once we use C++14
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
inline std::unique_ptr<T[]> MakeUniqueArray(size_t size)
|
||||||
|
{
|
||||||
|
return std::unique_ptr<T[]>(new T[size]);
|
||||||
|
}
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
#include "common/resources/inputstreambuffer.h"
|
#include "common/resources/inputstreambuffer.h"
|
||||||
|
|
||||||
|
#include "common/make_unique.h"
|
||||||
|
|
||||||
#include "common/resources/resourcemanager.h"
|
#include "common/resources/resourcemanager.h"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
@ -33,7 +35,7 @@ CInputStreamBuffer::CInputStreamBuffer(size_t bufferSize)
|
||||||
throw std::runtime_error("File buffer must be larger then 0 bytes");
|
throw std::runtime_error("File buffer must be larger then 0 bytes");
|
||||||
}
|
}
|
||||||
|
|
||||||
m_buffer = std::unique_ptr<char[]>(new char[bufferSize]);
|
m_buffer = MakeUniqueArray<char>(bufferSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
#include "common/resources/outputstreambuffer.h"
|
#include "common/resources/outputstreambuffer.h"
|
||||||
|
|
||||||
|
#include "common/make_unique.h"
|
||||||
|
|
||||||
#include "common/resources/resourcemanager.h"
|
#include "common/resources/resourcemanager.h"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
@ -32,7 +34,7 @@ COutputStreamBuffer::COutputStreamBuffer(size_t bufferSize)
|
||||||
throw std::runtime_error("File buffer must be larger then 0 bytes");
|
throw std::runtime_error("File buffer must be larger then 0 bytes");
|
||||||
}
|
}
|
||||||
|
|
||||||
m_buffer = std::unique_ptr<char[]>(new char[bufferSize]);
|
m_buffer = MakeUniqueArray<char>(bufferSize);
|
||||||
setp(m_buffer.get(), m_buffer.get() + bufferSize);
|
setp(m_buffer.get(), m_buffer.get() + bufferSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue