forked from 0ad/0ad
Remove partial emulation of some C++11 features for older compilers.
This was SVN commit r16226.
This commit is contained in:
parent
0261d12727
commit
0843100d11
@ -1,3 +1,25 @@
|
|||||||
|
/* Copyright (c) 2015 Wildfire Games
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included
|
||||||
|
* in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "precompiled.h"
|
#include "precompiled.h"
|
||||||
#include "lib/allocators/unique_range.h"
|
#include "lib/allocators/unique_range.h"
|
||||||
|
|
||||||
@ -66,7 +88,7 @@ UniqueRange AllocateAligned(size_t size, size_t alignment)
|
|||||||
if(idxDeleterAligned == 0) // (optional optimization)
|
if(idxDeleterAligned == 0) // (optional optimization)
|
||||||
RegisterUniqueRangeDeleter(FreeAligned, &idxDeleterAligned);
|
RegisterUniqueRangeDeleter(FreeAligned, &idxDeleterAligned);
|
||||||
|
|
||||||
return RVALUE(UniqueRange(p, size, idxDeleterAligned));
|
return std::move(UniqueRange(p, size, idxDeleterAligned));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -78,5 +100,5 @@ UniqueRange AllocateVM(size_t size, vm::PageType pageType, int prot)
|
|||||||
if(idxDeleter == 0) // (optional optimization)
|
if(idxDeleter == 0) // (optional optimization)
|
||||||
RegisterUniqueRangeDeleter(vm::Free, &idxDeleter);
|
RegisterUniqueRangeDeleter(vm::Free, &idxDeleter);
|
||||||
|
|
||||||
return RVALUE(UniqueRange(p, size, idxDeleter));
|
return std::move(UniqueRange(p, size, idxDeleter));
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,25 @@
|
|||||||
|
/* Copyright (c) 2015 Wildfire Games
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included
|
||||||
|
* in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef INCLUDED_ALLOCATORS_UNIQUE_RANGE
|
#ifndef INCLUDED_ALLOCATORS_UNIQUE_RANGE
|
||||||
#define INCLUDED_ALLOCATORS_UNIQUE_RANGE
|
#define INCLUDED_ALLOCATORS_UNIQUE_RANGE
|
||||||
|
|
||||||
@ -66,14 +88,14 @@ public:
|
|||||||
Set(p, size, deleter);
|
Set(p, size, deleter);
|
||||||
}
|
}
|
||||||
|
|
||||||
UniqueRange(RVALUE_REF(UniqueRange) rvalue)
|
UniqueRange(UniqueRange&& rvalue)
|
||||||
{
|
{
|
||||||
Pilfer(LVALUE(rvalue));
|
Pilfer(rvalue);
|
||||||
}
|
}
|
||||||
|
|
||||||
UniqueRange& operator=(RVALUE_REF(UniqueRange) rvalue)
|
UniqueRange& operator=(UniqueRange&& rvalue)
|
||||||
{
|
{
|
||||||
UniqueRange& lvalue = LVALUE(rvalue);
|
UniqueRange& lvalue = rvalue;
|
||||||
if(this != &lvalue)
|
if(this != &lvalue)
|
||||||
{
|
{
|
||||||
Delete();
|
Delete();
|
||||||
@ -178,14 +200,14 @@ static inline void swap(UniqueRange& p1, UniqueRange& p2)
|
|||||||
p1.swap(p2);
|
p1.swap(p2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void swap(RVALUE_REF(UniqueRange) p1, UniqueRange& p2)
|
static inline void swap(UniqueRange&& p1, UniqueRange& p2)
|
||||||
{
|
{
|
||||||
p2.swap(LVALUE(p1));
|
p2.swap(p1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void swap(UniqueRange& p1, RVALUE_REF(UniqueRange) p2)
|
static inline void swap(UniqueRange& p1, UniqueRange&& p2)
|
||||||
{
|
{
|
||||||
p1.swap(LVALUE(p2));
|
p1.swap(p2);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -378,74 +378,4 @@ template<typename T, size_t n> char (*ArraySizeDeducer(T (&)[n]))[n];
|
|||||||
#define WIDEN2(x) L ## x
|
#define WIDEN2(x) L ## x
|
||||||
#define WIDEN(x) WIDEN2(x)
|
#define WIDEN(x) WIDEN2(x)
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// C++0x rvalue references (required for UniqueRange)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* expands to the type `rvalue reference to T'; used in function
|
|
||||||
* parameter declarations. for example, UniqueRange's move ctor is:
|
|
||||||
* UniqueRange(RVALUE_REF(UniqueRange) rvalue) { ... }
|
|
||||||
**/
|
|
||||||
#define RVALUE_REF(T) T&&
|
|
||||||
|
|
||||||
/**
|
|
||||||
* convert an rvalue to an lvalue
|
|
||||||
**/
|
|
||||||
#define LVALUE(rvalue) rvalue // in C++0x, a named rvalue reference is already an lvalue
|
|
||||||
|
|
||||||
/**
|
|
||||||
* convert anything (lvalue or rvalue) to an rvalue
|
|
||||||
**/
|
|
||||||
#define RVALUE(lvalue) std::move(lvalue)
|
|
||||||
|
|
||||||
|
|
||||||
#if !HAVE_CPP0X // partial emulation
|
|
||||||
|
|
||||||
// lvalue references are wrapped in this class, which is the
|
|
||||||
// actual argument passed to the "move ctor" etc.
|
|
||||||
template<typename T>
|
|
||||||
class RValue
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit RValue(T& lvalue): lvalue(lvalue) {}
|
|
||||||
T& LValue() const { return lvalue; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
// (avoid "assignment operator could not be generated" warning)
|
|
||||||
const RValue& operator=(const RValue&);
|
|
||||||
|
|
||||||
T& lvalue;
|
|
||||||
};
|
|
||||||
|
|
||||||
// (to deduce T automatically, we need function templates)
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
static inline RValue<T> ToRValue(T& lvalue)
|
|
||||||
{
|
|
||||||
return RValue<T>(lvalue);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
static inline RValue<T> ToRValue(const T& lvalue)
|
|
||||||
{
|
|
||||||
return RValue<T>((T&)lvalue);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
static inline RValue<T> ToRValue(const RValue<T>& rvalue)
|
|
||||||
{
|
|
||||||
return RValue<T>(rvalue.LValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
#undef RVALUE_REF
|
|
||||||
#undef LVALUE
|
|
||||||
#undef RVALUE
|
|
||||||
|
|
||||||
#define RVALUE_REF(T) const RValue<T>&
|
|
||||||
#define LVALUE(rvalue) rvalue.LValue()
|
|
||||||
#define RVALUE(lvalue) ToRValue(lvalue)
|
|
||||||
|
|
||||||
#endif // #if !HAVE_CPP0X
|
|
||||||
|
|
||||||
#endif // #ifndef INCLUDED_CODE_ANNOTATION
|
#endif // #ifndef INCLUDED_CODE_ANNOTATION
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (c) 2010 Wildfire Games
|
/* Copyright (c) 2015 Wildfire Games
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the
|
* a copy of this software and associated documentation files (the
|
||||||
@ -448,7 +448,7 @@ public:
|
|||||||
size_t cd_numEntries = 0;
|
size_t cd_numEntries = 0;
|
||||||
size_t cd_size = 0;
|
size_t cd_size = 0;
|
||||||
RETURN_STATUS_IF_ERR(LocateCentralDirectory(m_file, m_fileSize, cd_ofs, cd_numEntries, cd_size));
|
RETURN_STATUS_IF_ERR(LocateCentralDirectory(m_file, m_fileSize, cd_ofs, cd_numEntries, cd_size));
|
||||||
UniqueRange buf(RVALUE(io::Allocate(cd_size)));
|
UniqueRange buf(std::move(io::Allocate(cd_size)));
|
||||||
|
|
||||||
io::Operation op(*m_file.get(), buf.get(), cd_size, cd_ofs);
|
io::Operation op(*m_file.get(), buf.get(), cd_size, cd_ofs);
|
||||||
RETURN_STATUS_IF_ERR(io::Run(op));
|
RETURN_STATUS_IF_ERR(io::Run(op));
|
||||||
@ -533,7 +533,7 @@ private:
|
|||||||
static Status LocateCentralDirectory(const PFile& file, off_t fileSize, off_t& cd_ofs, size_t& cd_numEntries, size_t& cd_size)
|
static Status LocateCentralDirectory(const PFile& file, off_t fileSize, off_t& cd_ofs, size_t& cd_numEntries, size_t& cd_size)
|
||||||
{
|
{
|
||||||
const size_t maxScanSize = 66000u; // see below
|
const size_t maxScanSize = 66000u; // see below
|
||||||
UniqueRange buf(RVALUE(io::Allocate(maxScanSize)));
|
UniqueRange buf(std::move(io::Allocate(maxScanSize)));
|
||||||
|
|
||||||
// expected case: ECDR at EOF; no file comment
|
// expected case: ECDR at EOF; no file comment
|
||||||
Status ret = ScanForEcdr(file, fileSize, (u8*)buf.get(), sizeof(ECDR), cd_numEntries, cd_ofs, cd_size);
|
Status ret = ScanForEcdr(file, fileSize, (u8*)buf.get(), sizeof(ECDR), cd_numEntries, cd_ofs, cd_size);
|
||||||
@ -662,7 +662,7 @@ public:
|
|||||||
|
|
||||||
// allocate memory
|
// allocate memory
|
||||||
const size_t csizeMax = codec->MaxOutputSize(size_t(usize));
|
const size_t csizeMax = codec->MaxOutputSize(size_t(usize));
|
||||||
UniqueRange buf(RVALUE(io::Allocate(sizeof(LFH) + pathnameLength + csizeMax)));
|
UniqueRange buf(std::move(io::Allocate(sizeof(LFH) + pathnameLength + csizeMax)));
|
||||||
|
|
||||||
// read and compress file contents
|
// read and compress file contents
|
||||||
size_t csize; u32 checksum;
|
size_t csize; u32 checksum;
|
||||||
|
@ -54,7 +54,7 @@ namespace io {
|
|||||||
// never reused (avoids displacing other items).
|
// never reused (avoids displacing other items).
|
||||||
static inline UniqueRange Allocate(size_t size, size_t alignment = maxSectorSize)
|
static inline UniqueRange Allocate(size_t size, size_t alignment = maxSectorSize)
|
||||||
{
|
{
|
||||||
return RVALUE(AllocateAligned(size, alignment));
|
return std::move(AllocateAligned(size, alignment));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -190,7 +190,7 @@ public:
|
|||||||
|
|
||||||
const bool temporaryBuffersRequested = (op.buf == 0);
|
const bool temporaryBuffersRequested = (op.buf == 0);
|
||||||
if(temporaryBuffersRequested)
|
if(temporaryBuffersRequested)
|
||||||
buffers = RVALUE(io::Allocate(blockSize * p.queueDepth, p.alignment));
|
buffers = std::move(io::Allocate(blockSize * p.queueDepth, p.alignment));
|
||||||
|
|
||||||
for(size_t i = 0; i < ARRAY_SIZE(controlBlocks); i++)
|
for(size_t i = 0; i < ARRAY_SIZE(controlBlocks); i++)
|
||||||
{
|
{
|
||||||
|
@ -75,13 +75,10 @@ double __cdecl abs(double x); // not declared by mathimf
|
|||||||
#if CONFIG_ENABLE_BOOST
|
#if CONFIG_ENABLE_BOOST
|
||||||
# include "lib/pch/pch_boost.h"
|
# include "lib/pch/pch_boost.h"
|
||||||
using boost::shared_ptr;
|
using boost::shared_ptr;
|
||||||
#elif HAVE_CPP0X
|
#else
|
||||||
# include <array>
|
# include <array>
|
||||||
# include <memory>
|
# include <memory>
|
||||||
using std::shared_ptr;
|
using std::shared_ptr;
|
||||||
#else
|
|
||||||
# include <memory>
|
|
||||||
using std::tr1::shared_ptr;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// (must come after boost and common lib headers, but before re-enabling
|
// (must come after boost and common lib headers, but before re-enabling
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (c) 2010 Wildfire Games
|
/* Copyright (c) 2015 Wildfire Games
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the
|
* a copy of this software and associated documentation files (the
|
||||||
@ -96,17 +96,6 @@
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// do we have (at least rudimentary) support for C++0x?
|
|
||||||
#ifndef HAVE_CPP0X
|
|
||||||
# if defined(__GXX_EXPERIMENTAL_CPP0X__) || MSC_VERSION >= 1600 || ICC_VERSION >= 1200
|
|
||||||
# define HAVE_CPP0X 1
|
|
||||||
# else
|
|
||||||
# define HAVE_CPP0X 0
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
// Streaming SIMD Extensions (not supported by all GCC)
|
// Streaming SIMD Extensions (not supported by all GCC)
|
||||||
// this only ascertains compiler support; use x86_x64::Cap to
|
// this only ascertains compiler support; use x86_x64::Cap to
|
||||||
// check whether the instructions are supported by the CPU.
|
// check whether the instructions are supported by the CPU.
|
||||||
|
Loading…
Reference in New Issue
Block a user