修复 c++ 17下auto_ptr错误

v0.27.3
Matthew 9 months ago
parent ada86be02b
commit 1d3009d723

@ -9,8 +9,11 @@ project(exiv2 # use TWEAK to categorize the build
# 0.27.3.29 = RC2 Not for release
LANGUAGES CXX C
)
set(CMAKE_CXX_STANDARD 14)
include(cmake/mainSetup.cmake REQUIRED)
# options and their default values
option( BUILD_SHARED_LIBS "Build exiv2lib as a shared library" ON )
option( EXIV2_ENABLE_XMP "Build with XMP metadata support" ON )

@ -13,7 +13,7 @@ if (EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(NO_OUTPUT_DIRS KEEP_RPATHS TARGETS)
endif()
find_package(Threads REQUIRED)
# find_package(Threads REQUIRED)
if( EXIV2_ENABLE_PNG )
find_package( ZLIB REQUIRED )

@ -30,7 +30,7 @@
#include "types.hpp"
// + standard includes
#include <memory> // for std::auto_ptr
#include <memory> // for Auto_Ptr
// The way to handle data from stdin or data uri path. If EXV_XPATH_MEMIO = 1,
// it uses MemIo. Otherwises, it uses FileIo.
@ -55,7 +55,7 @@ namespace Exiv2 {
class EXIV2API BasicIo {
public:
//! BasicIo auto_ptr type
typedef std::auto_ptr<BasicIo> AutoPtr;
typedef Auto_Ptr<BasicIo> AutoPtr;
//! Seek starting positions
enum Position { beg, cur, end };
@ -521,7 +521,7 @@ namespace Exiv2 {
// Pimpl idiom
class Impl;
std::auto_ptr<Impl> p_;
Auto_Ptr<Impl> p_;
}; // class FileIo
@ -721,7 +721,7 @@ namespace Exiv2 {
// Pimpl idiom
class Impl;
std::auto_ptr<Impl> p_;
Auto_Ptr<Impl> p_;
}; // class MemIo

@ -275,7 +275,7 @@ namespace Exiv2 {
class EXIV2API IptcKey : public Key {
public:
//! Shortcut for an %IptcKey auto pointer.
typedef std::auto_ptr<IptcKey> AutoPtr;
typedef Auto_Ptr<IptcKey> AutoPtr;
//! @name Creators
//@{

@ -81,7 +81,7 @@ namespace Exiv2 {
class EXIV2API Image {
public:
//! Image auto_ptr type
typedef std::auto_ptr<Image> AutoPtr;
typedef Auto_Ptr<Image> AutoPtr;
//! @name Creators
//@{

@ -55,7 +55,7 @@ namespace Exiv2 {
class EXIV2API Key {
public:
//! Shortcut for a %Key auto pointer.
typedef std::auto_ptr<Key> AutoPtr;
typedef Auto_Ptr<Key> AutoPtr;
//! @name Creators
//@{

@ -242,7 +242,7 @@ namespace Exiv2 {
{
public:
//! Shortcut for an %XmpKey auto pointer.
typedef std::auto_ptr<XmpKey> AutoPtr;
typedef Auto_Ptr<XmpKey> AutoPtr;
//! @name Creators
//@{
@ -305,7 +305,7 @@ namespace Exiv2 {
private:
// Pimpl idiom
struct Impl;
std::auto_ptr<Impl> p_;
Auto_Ptr<Impl> p_;
}; // class XmpKey

@ -148,7 +148,7 @@ namespace Exiv2 {
class EXIV2API ExifKey : public Key {
public:
//! Shortcut for an %ExifKey auto pointer.
typedef std::auto_ptr<ExifKey> AutoPtr;
typedef Auto_Ptr<ExifKey> AutoPtr;
//! @name Creators
//@{
@ -222,7 +222,7 @@ namespace Exiv2 {
private:
// Pimpl idiom
struct Impl;
std::auto_ptr<Impl> p_;
Auto_Ptr<Impl> p_;
}; // class ExifKey

@ -42,6 +42,125 @@
#include <algorithm>
#include <sstream>
template<class _Ty>
class Auto_Ptr;
template<class _Ty>
struct Auto_Ptr_ref
{ // proxy reference for auto_ptr copying
explicit Auto_Ptr_ref(_Ty * _Right)
: _Ref(_Right)
{ // construct from generic pointer to auto_ptr ptr
}
_Ty * _Ref; // generic pointer to auto_ptr ptr
};
template<class _Ty>
class Auto_Ptr
{ // wrap an object pointer to ensure destruction
public:
typedef _Ty element_type;
explicit Auto_Ptr(_Ty * _Ptr = nullptr) noexcept
: _Myptr(_Ptr)
{ // construct from object pointer
}
Auto_Ptr(Auto_Ptr& _Right) noexcept
: _Myptr(_Right.release())
{ // construct by assuming pointer from _Right auto_ptr
}
Auto_Ptr(Auto_Ptr_ref<_Ty> _Right) noexcept
{ // construct by assuming pointer from _Right auto_ptr_ref
_Ty * _Ptr = _Right._Ref;
_Right._Ref = nullptr; // release old
_Myptr = _Ptr; // reset this
}
template<class _Other>
operator Auto_Ptr<_Other>() noexcept
{ // convert to compatible auto_ptr
return (Auto_Ptr<_Other>(*this));
}
template<class _Other>
operator Auto_Ptr_ref<_Other>() noexcept
{ // convert to compatible auto_ptr_ref
_Other * _Cvtptr = _Myptr; // test implicit conversion
Auto_Ptr_ref<_Other> _Ans(_Cvtptr);
_Myptr = nullptr; // pass ownership to auto_ptr_ref
return (_Ans);
}
template<class _Other>
Auto_Ptr& operator=(Auto_Ptr<_Other>& _Right) noexcept
{ // assign compatible _Right (assume pointer)
reset(_Right.release());
return (*this);
}
template<class _Other>
Auto_Ptr(Auto_Ptr<_Other>& _Right) noexcept
: _Myptr(_Right.release())
{ // construct by assuming pointer from _Right
}
Auto_Ptr& operator=(Auto_Ptr& _Right) noexcept
{ // assign compatible _Right (assume pointer)
reset(_Right.release());
return (*this);
}
Auto_Ptr& operator=(Auto_Ptr_ref<_Ty> _Right) noexcept
{ // assign compatible _Right._Ref (assume pointer)
_Ty * _Ptr = _Right._Ref;
_Right._Ref = 0; // release old
reset(_Ptr); // set new
return (*this);
}
~Auto_Ptr() noexcept
{ // destroy the object
delete _Myptr;
}
_Ty& operator*() const noexcept
{ // return designated value
return (*get());
}
_Ty * operator->() const noexcept
{ // return pointer to class object
return (get());
}
_Ty * get() const noexcept
{ // return wrapped pointer
return (_Myptr);
}
_Ty * release() noexcept
{ // return wrapped pointer and give up ownership
_Ty * _Tmp = _Myptr;
_Myptr = nullptr;
return (_Tmp);
}
void reset(_Ty * _Ptr = nullptr)
{ // destroy designated object and store new pointer
if (_Ptr != _Myptr)
delete _Myptr;
_Myptr = _Ptr;
}
private:
_Ty * _Myptr; // the wrapped object pointer
};
#ifdef _MSC_VER
// Visual Studio 2010 and later has stdint.h
# if _MSC_VER >= _MSC_VER_2010
@ -213,7 +332,7 @@ namespace Exiv2 {
DataBuf(const byte* pData, long size);
/*!
@brief Copy constructor. Transfers the buffer to the newly created
object similar to std::auto_ptr, i.e., the original object is
object similar to Auto_Ptr, i.e., the original object is
modified.
*/
DataBuf(DataBuf& rhs);
@ -225,7 +344,7 @@ namespace Exiv2 {
//@{
/*!
@brief Assignment operator. Transfers the buffer and releases the
buffer at the original object similar to std::auto_ptr, i.e.,
buffer at the original object similar to Auto_Ptr, i.e.,
the original object is modified.
*/
DataBuf& operator=(DataBuf& rhs);
@ -255,7 +374,7 @@ namespace Exiv2 {
@name Conversions
Special conversions with auxiliary type to enable copies
and assignments, similar to those used for std::auto_ptr.
and assignments, similar to those used for Auto_Ptr.
See http://www.josuttis.com/libbook/auto_ptr.html for a discussion.
*/
//@{

@ -42,6 +42,8 @@
#include <cstring>
#include <climits>
// *****************************************************************************
// namespace extensions
namespace Exiv2 {
@ -60,7 +62,8 @@ namespace Exiv2 {
class EXIV2API Value {
public:
//! Shortcut for a %Value auto pointer.
typedef std::auto_ptr<Value> AutoPtr;
typedef Auto_Ptr<Value> AutoPtr;
//! @name Creators
//@{
@ -262,7 +265,7 @@ namespace Exiv2 {
class EXIV2API DataValue : public Value {
public:
//! Shortcut for a %DataValue auto pointer.
typedef std::auto_ptr<DataValue> AutoPtr;
typedef Auto_Ptr<DataValue> AutoPtr;
explicit DataValue(TypeId typeId =undefined);
@ -344,7 +347,7 @@ namespace Exiv2 {
class EXIV2API StringValueBase : public Value {
public:
//! Shortcut for a %StringValueBase auto pointer.
typedef std::auto_ptr<StringValueBase> AutoPtr;
typedef Auto_Ptr<StringValueBase> AutoPtr;
//! @name Creators
//@{
@ -426,7 +429,7 @@ namespace Exiv2 {
class EXIV2API StringValue : public StringValueBase {
public:
//! Shortcut for a %StringValue auto pointer.
typedef std::auto_ptr<StringValue> AutoPtr;
typedef Auto_Ptr<StringValue> AutoPtr;
//! @name Creators
//@{
@ -458,7 +461,7 @@ namespace Exiv2 {
class EXIV2API AsciiValue : public StringValueBase {
public:
//! Shortcut for a %AsciiValue auto pointer.
typedef std::auto_ptr<AsciiValue> AutoPtr;
typedef Auto_Ptr<AsciiValue> AutoPtr;
//! @name Creators
//@{
@ -546,7 +549,7 @@ namespace Exiv2 {
}; // class CharsetInfo
//! Shortcut for a %CommentValue auto pointer.
typedef std::auto_ptr<CommentValue> AutoPtr;
typedef Auto_Ptr<CommentValue> AutoPtr;
//! @name Creators
//@{
@ -633,7 +636,7 @@ namespace Exiv2 {
class EXIV2API XmpValue : public Value {
public:
//! Shortcut for a %XmpValue auto pointer.
typedef std::auto_ptr<XmpValue> AutoPtr;
typedef Auto_Ptr<XmpValue> AutoPtr;
//! XMP array types.
enum XmpArrayType { xaNone, xaAlt, xaBag, xaSeq };
@ -724,7 +727,7 @@ namespace Exiv2 {
class EXIV2API XmpTextValue : public XmpValue {
public:
//! Shortcut for a %XmpTextValue auto pointer.
typedef std::auto_ptr<XmpTextValue> AutoPtr;
typedef Auto_Ptr<XmpTextValue> AutoPtr;
//! @name Creators
//@{
@ -806,7 +809,7 @@ namespace Exiv2 {
class EXIV2API XmpArrayValue : public XmpValue {
public:
//! Shortcut for a %XmpArrayValue auto pointer.
typedef std::auto_ptr<XmpArrayValue> AutoPtr;
typedef Auto_Ptr<XmpArrayValue> AutoPtr;
//! @name Creators
//@{
@ -899,7 +902,7 @@ namespace Exiv2 {
class EXIV2API LangAltValue : public XmpValue {
public:
//! Shortcut for a %LangAltValue auto pointer.
typedef std::auto_ptr<LangAltValue> AutoPtr;
typedef Auto_Ptr<LangAltValue> AutoPtr;
//! @name Creators
//@{
@ -987,7 +990,7 @@ namespace Exiv2 {
class EXIV2API DateValue : public Value {
public:
//! Shortcut for a %DateValue auto pointer.
typedef std::auto_ptr<DateValue> AutoPtr;
typedef Auto_Ptr<DateValue> AutoPtr;
//! @name Creators
//@{
@ -1088,7 +1091,7 @@ namespace Exiv2 {
class EXIV2API TimeValue : public Value {
public:
//! Shortcut for a %TimeValue auto pointer.
typedef std::auto_ptr<TimeValue> AutoPtr;
typedef Auto_Ptr<TimeValue> AutoPtr;
//! @name Creators
//@{
@ -1244,7 +1247,7 @@ namespace Exiv2 {
class ValueType : public Value {
public:
//! Shortcut for a %ValueType\<T\> auto pointer.
typedef std::auto_ptr<ValueType<T> > AutoPtr;
typedef Auto_Ptr<ValueType<T> > AutoPtr;
//! @name Creators
//@{

@ -153,7 +153,7 @@ namespace Exiv2 {
private:
// Pimpl idiom
struct Impl;
std::auto_ptr<Impl> p_;
Auto_Ptr<Impl> p_;
}; // class Xmpdatum

@ -201,7 +201,7 @@ if (NOT MSVC)
target_link_libraries( exiv2lib PRIVATE psapi ws2_32 shell32 )
endif()
target_link_libraries( exiv2lib PRIVATE Threads::Threads)
# target_link_libraries( exiv2lib PRIVATE Threads::Threads)
else()
target_link_libraries( exiv2lib PRIVATE psapi ws2_32 shell32 )
endif()

@ -1989,19 +1989,19 @@ namespace {
static CRITICAL_SECTION cs;
#else
/* Unix/Linux/Cygwin/macOS */
#include <pthread.h>
#include <mutex>
/* This is the critical section object (statically allocated). */
#if defined(__APPLE__)
#if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
static pthread_mutex_t cs = PTHREAD_RECURSIVE_MUTEX_INITIALIZER;
static std::mutex cs;
#else
static pthread_mutex_t cs = PTHREAD_MUTEX_INITIALIZER;
static std::mutex cs;
#endif
#else
#if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
static pthread_mutex_t cs = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
static std::mutex cs;
#else
static pthread_mutex_t cs = PTHREAD_MUTEX_INITIALIZER;
static std::mutex cs;
#endif
#endif
#endif
@ -2020,7 +2020,7 @@ namespace {
DWORD pid = ::GetProcessId(process);
#else
pid_t pid = ::getpid();
pthread_mutex_lock( &cs );
cs.lock();
std::string tmp = "/tmp/";
#endif
char sCount[13];
@ -2032,7 +2032,7 @@ namespace {
#if defined(_MSC_VER) || defined(__MINGW__)
LeaveCriticalSection(&cs);
#else
pthread_mutex_unlock( &cs );
cs.unlock();
#endif
return result;

@ -65,7 +65,7 @@ namespace Action {
class Task {
public:
//! Shortcut for an auto pointer.
typedef std::auto_ptr<Task> AutoPtr;
typedef Auto_Ptr<Task> AutoPtr;
//! Virtual destructor.
virtual ~Task();
//! Virtual copy construction.
@ -149,7 +149,7 @@ namespace Action {
public:
virtual ~Print();
virtual int run(const std::string& path);
typedef std::auto_ptr<Print> AutoPtr;
typedef Auto_Ptr<Print> AutoPtr;
AutoPtr clone() const;
//! Print the Jpeg comment
@ -204,7 +204,7 @@ namespace Action {
public:
virtual ~Rename();
virtual int run(const std::string& path);
typedef std::auto_ptr<Rename> AutoPtr;
typedef Auto_Ptr<Rename> AutoPtr;
AutoPtr clone() const;
private:
@ -216,7 +216,7 @@ namespace Action {
public:
virtual ~Adjust();
virtual int run(const std::string& path);
typedef std::auto_ptr<Adjust> AutoPtr;
typedef Auto_Ptr<Adjust> AutoPtr;
AutoPtr clone() const;
private:
@ -239,7 +239,7 @@ namespace Action {
public:
virtual ~Erase();
virtual int run(const std::string& path);
typedef std::auto_ptr<Erase> AutoPtr;
typedef Auto_Ptr<Erase> AutoPtr;
AutoPtr clone() const;
/*!
@ -281,7 +281,7 @@ namespace Action {
public:
virtual ~Extract();
virtual int run(const std::string& path);
typedef std::auto_ptr<Extract> AutoPtr;
typedef Auto_Ptr<Extract> AutoPtr;
AutoPtr clone() const;
/*!
@ -320,7 +320,7 @@ namespace Action {
public:
virtual ~Insert();
virtual int run(const std::string& path);
typedef std::auto_ptr<Insert> AutoPtr;
typedef Auto_Ptr<Insert> AutoPtr;
AutoPtr clone() const;
/*!
@ -361,7 +361,7 @@ namespace Action {
public:
virtual ~Modify();
virtual int run(const std::string& path);
typedef std::auto_ptr<Modify> AutoPtr;
typedef Auto_Ptr<Modify> AutoPtr;
AutoPtr clone() const;
Modify() {}
//! Apply modification commands to the \em pImage, return 0 if successful.
@ -394,7 +394,7 @@ namespace Action {
public:
virtual ~FixIso();
virtual int run(const std::string& path);
typedef std::auto_ptr<FixIso> AutoPtr;
typedef Auto_Ptr<FixIso> AutoPtr;
AutoPtr clone() const;
private:
@ -412,7 +412,7 @@ namespace Action {
public:
virtual ~FixCom();
virtual int run(const std::string& path);
typedef std::auto_ptr<FixCom> AutoPtr;
typedef Auto_Ptr<FixCom> AutoPtr;
AutoPtr clone() const;
private:

@ -183,7 +183,7 @@ namespace Exiv2 {
ed.end());
}
std::auto_ptr<TiffHeaderBase> header(new Cr2Header(byteOrder));
Auto_Ptr<TiffHeaderBase> header(new Cr2Header(byteOrder));
OffsetWriter offsetWriter;
offsetWriter.setOrigin(OffsetWriter::cr2RawIfdOffset, Cr2Header::offset2addr(), byteOrder);
return TiffParserWorker::encode(io,

@ -91,7 +91,7 @@ namespace Exiv2 {
class CiffComponent {
public:
//! CiffComponent auto_ptr type
typedef std::auto_ptr<CiffComponent> AutoPtr;
typedef Auto_Ptr<CiffComponent> AutoPtr;
//! Container type to hold all metadata
typedef std::vector<CiffComponent*> Components;
@ -435,7 +435,7 @@ namespace Exiv2 {
class CiffHeader {
public:
//! CiffHeader auto_ptr type
typedef std::auto_ptr<CiffHeader> AutoPtr;
typedef Auto_Ptr<CiffHeader> AutoPtr;
//! @name Creators
//@{

@ -80,7 +80,7 @@ namespace {
class Thumbnail {
public:
//! Shortcut for a %Thumbnail auto pointer.
typedef std::auto_ptr<Thumbnail> AutoPtr;
typedef Auto_Ptr<Thumbnail> AutoPtr;
//! @name Creators
//@{
@ -123,7 +123,7 @@ namespace {
class TiffThumbnail : public Thumbnail {
public:
//! Shortcut for a %TiffThumbnail auto pointer.
typedef std::auto_ptr<TiffThumbnail> AutoPtr;
typedef Auto_Ptr<TiffThumbnail> AutoPtr;
//! @name Manipulators
//@{
@ -147,7 +147,7 @@ namespace {
class JpegThumbnail : public Thumbnail {
public:
//! Shortcut for a %JpegThumbnail auto pointer.
typedef std::auto_ptr<JpegThumbnail> AutoPtr;
typedef Auto_Ptr<JpegThumbnail> AutoPtr;
//! @name Manipulators
//@{
@ -192,8 +192,8 @@ namespace Exiv2 {
template<typename T>
Exiv2::Exifdatum& setValue(Exiv2::Exifdatum& exifDatum, const T& value)
{
std::auto_ptr<Exiv2::ValueType<T> > v
= std::auto_ptr<Exiv2::ValueType<T> >(new Exiv2::ValueType<T>);
Auto_Ptr<Exiv2::ValueType<T> > v
= Auto_Ptr<Exiv2::ValueType<T> >(new Exiv2::ValueType<T>);
v->value_.push_back(value);
exifDatum.value_ = v;
return exifDatum;
@ -726,7 +726,7 @@ namespace Exiv2 {
// Encode and check if the result fits into a JPEG Exif APP1 segment
MemIo mio1;
std::auto_ptr<TiffHeaderBase> header(new TiffHeader(byteOrder, 0x00000008, false));
Auto_Ptr<TiffHeaderBase> header(new TiffHeader(byteOrder, 0x00000008, false));
WriteMethod wm = TiffParserWorker::encode(mio1,
pData,
size,

@ -938,7 +938,7 @@ namespace Exiv2 {
Image::AutoPtr ImageFactory::create(int type,
const std::string& path)
{
std::auto_ptr<FileIo> fileIo(new FileIo(path));
Auto_Ptr<FileIo> fileIo(new FileIo(path));
// Create or overwrite the file, then close it
if (fileIo->open("w+b") != 0) {
throw Error(kerFileOpenFailed, path, "w+b", strError());
@ -954,7 +954,7 @@ namespace Exiv2 {
Image::AutoPtr ImageFactory::create(int type,
const std::wstring& wpath)
{
std::auto_ptr<FileIo> fileIo(new FileIo(wpath));
Auto_Ptr<FileIo> fileIo(new FileIo(wpath));
// Create or overwrite the file, then close it
if (fileIo->open("w+b") != 0) {
throw WError(kerFileOpenFailed, wpath, "w+b", strError().c_str());

@ -195,7 +195,7 @@ namespace Exiv2 {
ed.end());
}
std::auto_ptr<TiffHeaderBase> header(new OrfHeader(byteOrder));
Auto_Ptr<TiffHeaderBase> header(new OrfHeader(byteOrder));
return TiffParserWorker::encode(io,
pData,
size,

@ -93,7 +93,7 @@ namespace {
virtual ~Loader() {}
//! Loader auto pointer
typedef std::auto_ptr<Loader> AutoPtr;
typedef Auto_Ptr<Loader> AutoPtr;
//! Create a Loader subclass for requested id
static AutoPtr create(PreviewId id, const Image &image);

@ -174,7 +174,7 @@ namespace Exiv2 {
class TiffComponent {
public:
//! TiffComponent auto_ptr type
typedef std::auto_ptr<TiffComponent> AutoPtr;
typedef Auto_Ptr<TiffComponent> AutoPtr;
//! Container type to hold all metadata
typedef std::vector<TiffComponent*> Components;

@ -105,7 +105,7 @@ namespace Exiv2 {
Use TiffComponent::AutoPtr, it is not used in this declaration only
to reduce dependencies.
*/
typedef std::auto_ptr<TiffComponent> (*NewTiffCompFct)(uint16_t tag, IfdId group);
typedef Auto_Ptr<TiffComponent> (*NewTiffCompFct)(uint16_t tag, IfdId group);
//! Stack to hold a path from the TIFF root element to a TIFF entry
typedef std::stack<TiffPathItem> TiffPath;

@ -292,7 +292,7 @@ namespace Exiv2 {
ed.end());
}
std::auto_ptr<TiffHeaderBase> header(new TiffHeader(byteOrder));
Auto_Ptr<TiffHeaderBase> header(new TiffHeader(byteOrder));
return TiffParserWorker::encode(io,
pData,
size,

@ -1675,9 +1675,9 @@ namespace Exiv2 {
)
{
// Create standard TIFF header if necessary
std::auto_ptr<TiffHeaderBase> ph;
Auto_Ptr<TiffHeaderBase> ph;
if (!pHeader) {
ph = std::auto_ptr<TiffHeaderBase>(new TiffHeader);
ph = Auto_Ptr<TiffHeaderBase>(new TiffHeader);
pHeader = ph.get();
}
TiffComponent::AutoPtr rootDir = parse(pData, size, root, pHeader);

@ -256,7 +256,7 @@ namespace Exiv2 {
component creation function. If the pointer that is returned
is 0, then the TIFF entry should be ignored.
*/
static std::auto_ptr<TiffComponent> create(uint32_t extendedTag,
static Auto_Ptr<TiffComponent> create(uint32_t extendedTag,
IfdId group);
/*!
@brief Get the path, i.e., a list of extended tag and group pairs, from
@ -349,7 +349,7 @@ namespace Exiv2 {
composite structure. If \em pData is 0 or \em size
is 0, the return value is a 0 pointer.
*/
static std::auto_ptr<TiffComponent> parse(
static Auto_Ptr<TiffComponent> parse(
const byte* pData,
uint32_t size,
uint32_t root,

Loading…
Cancel
Save