diff --git a/source/lib/allocators/unique_range.cpp b/source/lib/allocators/unique_range.cpp index bc4581d767..758e433dd8 100644 --- a/source/lib/allocators/unique_range.cpp +++ b/source/lib/allocators/unique_range.cpp @@ -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 "lib/allocators/unique_range.h" @@ -66,7 +88,7 @@ UniqueRange AllocateAligned(size_t size, size_t alignment) if(idxDeleterAligned == 0) // (optional optimization) 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) RegisterUniqueRangeDeleter(vm::Free, &idxDeleter); - return RVALUE(UniqueRange(p, size, idxDeleter)); + return std::move(UniqueRange(p, size, idxDeleter)); } diff --git a/source/lib/allocators/unique_range.h b/source/lib/allocators/unique_range.h index 097e193119..7a3041f03e 100644 --- a/source/lib/allocators/unique_range.h +++ b/source/lib/allocators/unique_range.h @@ -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 #define INCLUDED_ALLOCATORS_UNIQUE_RANGE @@ -66,14 +88,14 @@ public: 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) { Delete(); @@ -178,14 +200,14 @@ static inline void swap(UniqueRange& p1, UniqueRange& 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); } } diff --git a/source/lib/code_annotation.h b/source/lib/code_annotation.h index 4d2d63a163..7b1cbdb8e6 100644 --- a/source/lib/code_annotation.h +++ b/source/lib/code_annotation.h @@ -378,74 +378,4 @@ template char (*ArraySizeDeducer(T (&)[n]))[n]; #define WIDEN2(x) L ## 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 -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 -static inline RValue ToRValue(T& lvalue) -{ - return RValue(lvalue); -} - -template -static inline RValue ToRValue(const T& lvalue) -{ - return RValue((T&)lvalue); -} - -template -static inline RValue ToRValue(const RValue& rvalue) -{ - return RValue(rvalue.LValue()); -} - -#undef RVALUE_REF -#undef LVALUE -#undef RVALUE - -#define RVALUE_REF(T) const RValue& -#define LVALUE(rvalue) rvalue.LValue() -#define RVALUE(lvalue) ToRValue(lvalue) - -#endif // #if !HAVE_CPP0X - #endif // #ifndef INCLUDED_CODE_ANNOTATION diff --git a/source/lib/file/archive/archive_zip.cpp b/source/lib/file/archive/archive_zip.cpp index 5b6ac78510..32c3766e6e 100644 --- a/source/lib/file/archive/archive_zip.cpp +++ b/source/lib/file/archive/archive_zip.cpp @@ -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 * a copy of this software and associated documentation files (the @@ -448,7 +448,7 @@ public: size_t cd_numEntries = 0; size_t cd_size = 0; 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); 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) { 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 Status ret = ScanForEcdr(file, fileSize, (u8*)buf.get(), sizeof(ECDR), cd_numEntries, cd_ofs, cd_size); @@ -662,7 +662,7 @@ public: // allocate memory 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 size_t csize; u32 checksum; diff --git a/source/lib/file/io/io.h b/source/lib/file/io/io.h index 1500c37d7f..29dd1cbde6 100644 --- a/source/lib/file/io/io.h +++ b/source/lib/file/io/io.h @@ -54,7 +54,7 @@ namespace io { // never reused (avoids displacing other items). 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); 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++) { diff --git a/source/lib/precompiled.h b/source/lib/precompiled.h index 428a654353..a90631f8b5 100644 --- a/source/lib/precompiled.h +++ b/source/lib/precompiled.h @@ -75,13 +75,10 @@ double __cdecl abs(double x); // not declared by mathimf #if CONFIG_ENABLE_BOOST # include "lib/pch/pch_boost.h" using boost::shared_ptr; -#elif HAVE_CPP0X +#else # include # include using std::shared_ptr; -#else -# include -using std::tr1::shared_ptr; #endif // (must come after boost and common lib headers, but before re-enabling diff --git a/source/lib/sysdep/compiler.h b/source/lib/sysdep/compiler.h index 63b9e6e5dd..658c3230f0 100644 --- a/source/lib/sysdep/compiler.h +++ b/source/lib/sysdep/compiler.h @@ -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 * a copy of this software and associated documentation files (the @@ -96,17 +96,6 @@ # 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) // this only ascertains compiler support; use x86_x64::Cap to // check whether the instructions are supported by the CPU.