Sync AMTL.
This commit is contained in:
@@ -33,11 +33,10 @@
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
//#include <stdint.h>
|
||||
#include <stdint.h>
|
||||
#if defined(_MSC_VER)
|
||||
# include <intrin.h>
|
||||
#endif
|
||||
#include <am-moveable.h>
|
||||
|
||||
#define KE_32BIT
|
||||
|
||||
@@ -53,7 +52,7 @@ static const size_t kKB = 1024;
|
||||
static const size_t kMB = 1024 * kKB;
|
||||
static const size_t kGB = 1024 * kMB;
|
||||
|
||||
typedef unsigned char * Address;
|
||||
typedef uint8_t * Address;
|
||||
|
||||
template <typename T> T
|
||||
ReturnAndVoid(T &t)
|
||||
@@ -63,18 +62,6 @@ ReturnAndVoid(T &t)
|
||||
return saved;
|
||||
}
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
# define KE_CXX11
|
||||
#endif
|
||||
|
||||
#if defined(KE_CXX11)
|
||||
# define KE_DELETE = delete
|
||||
# define KE_OVERRIDE = override
|
||||
#else
|
||||
# define KE_DELETE
|
||||
# define KE_OVERRIDE
|
||||
#endif
|
||||
|
||||
// Wrapper that automatically deletes its contents. The pointer can be taken
|
||||
// to avoid destruction.
|
||||
template <typename T>
|
||||
@@ -87,15 +74,10 @@ class AutoPtr
|
||||
: t_(NULL)
|
||||
{
|
||||
}
|
||||
AutoPtr(T *t)
|
||||
explicit AutoPtr(T *t)
|
||||
: t_(t)
|
||||
{
|
||||
}
|
||||
AutoPtr(Moveable<AutoPtr<T> > other)
|
||||
{
|
||||
t_ = other->t_;
|
||||
other->t_ = NULL;
|
||||
}
|
||||
~AutoPtr() {
|
||||
delete t_;
|
||||
}
|
||||
@@ -111,24 +93,13 @@ class AutoPtr
|
||||
operator T *() const {
|
||||
return t_;
|
||||
}
|
||||
T *operator =(T *t) {
|
||||
void operator =(T *t) {
|
||||
delete t_;
|
||||
t_ = t;
|
||||
return t_;
|
||||
}
|
||||
T *operator =(Moveable<AutoPtr<T> > other) {
|
||||
delete t_;
|
||||
t_ = other->t_;
|
||||
other->t_ = NULL;
|
||||
return t_;
|
||||
}
|
||||
bool operator !() const {
|
||||
return !t_;
|
||||
}
|
||||
|
||||
private:
|
||||
AutoPtr(const AutoPtr &other) KE_DELETE;
|
||||
AutoPtr &operator =(const AutoPtr &other) KE_DELETE;
|
||||
};
|
||||
|
||||
// Wrapper that automatically deletes its contents. The pointer can be taken
|
||||
@@ -327,6 +298,37 @@ class StorageBuffer
|
||||
};
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class SaveAndSet
|
||||
{
|
||||
public:
|
||||
SaveAndSet(T *location, const T &value)
|
||||
: location_(location),
|
||||
old_(*location)
|
||||
{
|
||||
*location_ = value;
|
||||
}
|
||||
~SaveAndSet() {
|
||||
*location_ = old_;
|
||||
}
|
||||
|
||||
private:
|
||||
T *location_;
|
||||
T old_;
|
||||
};
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
# define KE_CXX11
|
||||
#endif
|
||||
|
||||
#if defined(KE_CXX11)
|
||||
# define KE_DELETE = delete
|
||||
# define KE_OVERRIDE override
|
||||
#else
|
||||
# define KE_DELETE
|
||||
# define KE_OVERRIDE
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# define KE_SIZET_FMT "%Iu"
|
||||
#elif defined(__GNUC__)
|
||||
|
||||
Reference in New Issue
Block a user