Converted Key hierarchy to use std::auto_ptr where appropriate

This commit is contained in:
Andreas Huggel 2004-10-16 04:43:21 +00:00
parent 4c85e400ae
commit e20bffaec7
10 changed files with 88 additions and 55 deletions

View File

@ -20,13 +20,13 @@
*/
/*
File: datasets.cpp
Version: $Name: $ $Revision: 1.7 $
Version: $Name: $ $Revision: 1.8 $
Author(s): Brad Schick (brad) <schick@robotbattle.com>
History: 24-Jul-04, brad: created
*/
// *****************************************************************************
#include "rcsid.hpp"
EXIV2_RCSID("@(#) $Name: $ $Revision: 1.7 $ $RCSfile: datasets.cpp,v $");
EXIV2_RCSID("@(#) $Name: $ $Revision: 1.8 $ $RCSfile: datasets.cpp,v $");
// *****************************************************************************
// included header files
@ -318,7 +318,12 @@ namespace Exiv2 {
return *this;
}
IptcKey* IptcKey::clone() const
IptcKey::AutoPtr IptcKey::clone() const
{
return AutoPtr(clone_());
}
IptcKey* IptcKey::clone_() const
{
return new IptcKey(*this);
}

View File

@ -21,7 +21,7 @@
/*!
@file datasets.hpp
@brief Iptc dataSet and type information
@version $Name: $ $Revision: 1.6 $
@version $Name: $ $Revision: 1.7 $
@author Brad Schick (brad) <schick@robotbattle.com>
@date 24-Jul-04, brad: created
*/
@ -37,6 +37,7 @@
#include <string>
#include <utility> // for std::pair
#include <iosfwd>
#include <memory>
// *****************************************************************************
// namespace extensions
@ -262,6 +263,9 @@ namespace Exiv2 {
*/
class IptcKey : public Key {
public:
//! Shortcut for an %IptcKey auto pointer.
typedef std::auto_ptr<IptcKey> AutoPtr;
//! @name Creators
//@{
/*!
@ -303,8 +307,8 @@ namespace Exiv2 {
virtual std::string tagName() const
{ return IptcDataSets::dataSetName(tag_, record_); }
virtual uint16_t tag() const { return tag_; }
virtual IptcKey* clone() const;
AutoPtr clone() const;
//! Return the name of the record
std::string recordName() const
{ return IptcDataSets::recordName(record_); }
@ -331,6 +335,9 @@ namespace Exiv2 {
//@}
private:
//! Internal virtual copy constructor.
virtual IptcKey* clone_() const;
// DATA
static const char* familyName_;

View File

@ -20,14 +20,14 @@
*/
/*
File: exif.cpp
Version: $Name: $ $Revision: 1.65 $
Version: $Name: $ $Revision: 1.66 $
Author(s): Andreas Huggel (ahu) <ahuggel@gmx.net>
History: 26-Jan-04, ahu: created
11-Feb-04, ahu: isolated as a component
*/
// *****************************************************************************
#include "rcsid.hpp"
EXIV2_RCSID("@(#) $Name: $ $Revision: 1.65 $ $RCSfile: exif.cpp,v $");
EXIV2_RCSID("@(#) $Name: $ $Revision: 1.66 $ $RCSfile: exif.cpp,v $");
// Define DEBUG_MAKERNOTE to output debug information to std::cerr
#undef DEBUG_MAKERNOTE
@ -74,28 +74,27 @@ namespace {
namespace Exiv2 {
Exifdatum::Exifdatum(const Entry& e, ByteOrder byteOrder)
: pKey_(new ExifKey(e)), pValue_(0)
: key_(ExifKey::AutoPtr(new ExifKey(e))), pValue_(0)
{
pValue_ = Value::create(TypeId(e.type()));
pValue_->read(e.data(), e.count() * e.typeSize(), byteOrder);
}
Exifdatum::Exifdatum(const ExifKey& key, const Value* pValue)
: pKey_(key.clone()), pValue_(0)
: key_(key.clone()), pValue_(0)
{
if (pValue) pValue_ = pValue->clone();
}
Exifdatum::~Exifdatum()
{
delete pKey_;
delete pValue_;
}
Exifdatum::Exifdatum(const Exifdatum& rhs)
: Metadatum(rhs), pKey_(0), pValue_(0)
: Metadatum(rhs), pValue_(0)
{
if (rhs.pKey_ != 0) pKey_ = rhs.pKey_->clone(); // deep copy
if (rhs.key_.get() != 0) key_ = rhs.key_->clone(); // deep copy
if (rhs.pValue_ != 0) pValue_ = rhs.pValue_->clone(); // deep copy
}
@ -104,9 +103,8 @@ namespace Exiv2 {
if (this == &rhs) return *this;
Metadatum::operator=(rhs);
delete pKey_;
pKey_ = 0;
if (rhs.pKey_ != 0) pKey_ = rhs.pKey_->clone(); // deep copy
key_.reset();
if (rhs.key_.get() != 0) key_ = rhs.key_->clone(); // deep copy
delete pValue_;
pValue_ = 0;
@ -1258,7 +1256,8 @@ namespace Exiv2 {
std::ostream& operator<<(std::ostream& os, const Exifdatum& md)
{
return md.pKey_->printTag(os, md.value());
assert(md.key_.get() != 0);
return md.key_->printTag(os, md.value());
}
} // namespace Exiv2

View File

@ -21,7 +21,7 @@
/*!
@file exif.hpp
@brief Encoding and decoding of Exif data
@version $Name: $ $Revision: 1.56 $
@version $Name: $ $Revision: 1.57 $
@author Andreas Huggel (ahu)
<a href="mailto:ahuggel@gmx.net">ahuggel@gmx.net</a>
@date 09-Jan-04, ahu: created
@ -114,28 +114,28 @@ namespace Exiv2 {
//@{
//! Return the key of the %Exifdatum.
std::string key() const
{ return pKey_ == 0 ? "" : pKey_->key(); }
{ return key_.get() == 0 ? "" : key_->key(); }
//! Return the name of the group (the second part of the key)
std::string groupName() const
{ return pKey_ == 0 ? "" : pKey_->groupName(); }
{ return key_.get() == 0 ? "" : key_->groupName(); }
//! Return the name of the tag (which is also the third part of the key)
std::string tagName() const
{ return pKey_ == 0 ? "" : pKey_->tagName(); }
{ return key_.get() == 0 ? "" : key_->tagName(); }
//! Return the tag
uint16_t tag() const
{ return pKey_ == 0 ? 0xffff : pKey_->tag(); }
{ return key_.get() == 0 ? 0xffff : key_->tag(); }
//! Return the IFD id
IfdId ifdId() const
{ return pKey_ == 0 ? ifdIdNotSet : pKey_->ifdId(); }
{ return key_.get() == 0 ? ifdIdNotSet : key_->ifdId(); }
//! Return the name of the IFD
const char* ifdName() const
{ return pKey_ == 0 ? "" : pKey_->ifdName(); }
{ return key_.get() == 0 ? "" : key_->ifdName(); }
//! Return the related image item (deprecated)
std::string ifdItem() const
{ return pKey_ == 0 ? "" : pKey_->ifdItem(); }
{ return key_.get() == 0 ? "" : key_->ifdItem(); }
//! Return the index (unique id of this key within the original IFD)
int idx() const
{ return pKey_ == 0 ? 0 : pKey_->idx(); }
{ return key_.get() == 0 ? 0 : key_->idx(); }
/*!
@brief Write value to a data buffer and return the number
of bytes written.
@ -230,7 +230,7 @@ namespace Exiv2 {
private:
// DATA
ExifKey* pKey_; //!< Key
ExifKey::AutoPtr key_; //!< Key
Value* pValue_; //!< Pointer to the value
}; // class Exifdatum

View File

@ -20,13 +20,13 @@
*/
/*
File: iptc.cpp
Version: $Name: $ $Revision: 1.7 $
Version: $Name: $ $Revision: 1.8 $
Author(s): Brad Schick (brad) <schick@robotbattle.com>
History: 31-July-04, brad: created
*/
// *****************************************************************************
#include "rcsid.hpp"
EXIV2_RCSID("@(#) $Name: $ $Revision: 1.7 $ $RCSfile: iptc.cpp,v $");
EXIV2_RCSID("@(#) $Name: $ $Revision: 1.8 $ $RCSfile: iptc.cpp,v $");
// Define DEBUG_MAKERNOTE to output debug information to std::cerr
#undef DEBUG_MAKERNOTE
@ -50,21 +50,20 @@ namespace Exiv2 {
Iptcdatum::Iptcdatum(const IptcKey& key,
const Value* value)
: pKey_(key.clone()), pValue_(0), modified_(false)
: key_(key.clone()), pValue_(0), modified_(false)
{
if (value) pValue_ = value->clone();
}
Iptcdatum::Iptcdatum(const Iptcdatum& rhs)
: Metadatum(rhs), pKey_(0), pValue_(0), modified_(false)
: Metadatum(rhs), pValue_(0), modified_(false)
{
if (rhs.pKey_ != 0) pKey_ = rhs.pKey_->clone(); // deep copy
if (rhs.key_.get() != 0) key_ = rhs.key_->clone(); // deep copy
if (rhs.pValue_ != 0) pValue_ = rhs.pValue_->clone(); // deep copy
}
Iptcdatum::~Iptcdatum()
{
delete pKey_;
delete pValue_;
}
@ -74,9 +73,8 @@ namespace Exiv2 {
Metadatum::operator=(rhs);
modified_ = true;
delete pKey_;
pKey_ = 0;
if (rhs.pKey_ != 0) pKey_ = rhs.pKey_->clone(); // deep copy
key_.reset();
if (rhs.key_.get() != 0) key_ = rhs.key_->clone(); // deep copy
delete pValue_;
pValue_ = 0;

View File

@ -21,7 +21,7 @@
/*!
@file iptc.hpp
@brief Encoding and decoding of Iptc data
@version $Name: $ $Revision: 1.7 $
@version $Name: $ $Revision: 1.8 $
@author Brad Schick (brad)
<a href="mailto:schick@robotbattle.com">schick@robotbattle.com</a>
@date 31-Jul-04, brad: created
@ -113,30 +113,30 @@ namespace Exiv2 {
is not necessarily unique, i.e., an IptcData may contain
multiple metadata with the same key.
*/
std::string key() const { return pKey_ == 0 ? "" : pKey_->key(); }
std::string key() const { return key_.get() == 0 ? "" : key_->key(); }
/*!
@brief Return the name of the record
@return record name
@throw Error("Unknown record");
*/
std::string recordName() const
{ return pKey_ == 0 ? "" : pKey_->recordName(); }
{ return key_.get() == 0 ? "" : key_->recordName(); }
/*!
@brief Return the record id
@return record id
*/
uint16_t record() const
{ return pKey_ == 0 ? 0 : pKey_->record(); }
{ return key_.get() == 0 ? 0 : key_->record(); }
/*!
@brief Return the name of the tag (aka dataset)
@return tag name
@throw Error("No dataSet for record Id") if tag is unknown
*/
std::string tagName() const
{ return pKey_ == 0 ? "" : pKey_->tagName(); }
{ return key_.get() == 0 ? "" : key_->tagName(); }
//! Return the tag (aka dataset) number
uint16_t tag() const
{ return pKey_ == 0 ? 0 : pKey_->tag(); }
{ return key_.get() == 0 ? 0 : key_->tag(); }
//! Return the type id of the value
TypeId typeId() const
{ return pValue_ == 0 ? invalidTypeId : pValue_->typeId(); }
@ -221,7 +221,7 @@ namespace Exiv2 {
private:
// DATA
IptcKey* pKey_; //!< Key
IptcKey::AutoPtr key_; //!< Key
Value* pValue_; //!< Pointer to the value
bool modified_; //!< Change indicator

View File

@ -20,7 +20,7 @@
*/
/*
File: metadatum.cpp
Version: $Name: $ $Revision: 1.1 $
Version: $Name: $ $Revision: 1.2 $
Author(s): Andreas Huggel (ahu) <ahuggel@gmx.net>
Brad Schick (brad) <schick@robotbattle.com>
History: 26-Jan-04, ahu: created
@ -28,7 +28,7 @@
*/
// *****************************************************************************
#include "rcsid.hpp"
EXIV2_RCSID("@(#) $Name: $ $Revision: 1.1 $ $RCSfile: metadatum.cpp,v $");
EXIV2_RCSID("@(#) $Name: $ $Revision: 1.2 $ $RCSfile: metadatum.cpp,v $");
// *****************************************************************************
// included header files
@ -42,6 +42,11 @@ EXIV2_RCSID("@(#) $Name: $ $Revision: 1.1 $ $RCSfile: metadatum.cpp,v $");
// *****************************************************************************
// class member definitions
namespace Exiv2 {
Key::AutoPtr Key::clone() const
{
return AutoPtr(clone_());
}
std::ostream& operator<<(std::ostream& os, const Metadatum& md)
{
@ -56,7 +61,6 @@ namespace Exiv2 {
return os;
}
bool cmpMetadataByTag(const Metadatum& lhs, const Metadatum& rhs)
{
return lhs.tag() < rhs.tag();

View File

@ -21,7 +21,7 @@
/*!
@file metadatum.hpp
@brief Provides abstract base classes Metadatum and Key
@version $Name: $ $Revision: 1.3 $
@version $Name: $ $Revision: 1.4 $
@author Andreas Huggel (ahu)
<a href="mailto:ahuggel@gmx.net">ahuggel@gmx.net</a>
@author Brad Schick (brad)
@ -40,6 +40,7 @@
// + standard includes
#include <string>
#include <memory>
// *****************************************************************************
// namespace extensions
@ -54,6 +55,9 @@ namespace Exiv2 {
*/
class Key {
public:
//! Shortcut for a %Key auto pointer.
typedef std::auto_ptr<Key> AutoPtr;
//! @name Creators
//@{
//! Destructor
@ -78,10 +82,11 @@ namespace Exiv2 {
//! Return the tag number
virtual uint16_t tag() const =0;
/*!
@brief Return a pointer to a copy of itself (deep copy).
The caller owns this copy and is responsible to delete it!
@brief Return an auto-pointer to a copy of itself (deep copy).
The caller owns this copy and the auto-pointer ensures that it
will be deleted.
*/
virtual Key* clone() const =0;
AutoPtr clone() const;
/*!
@brief Write the key to an output stream. You do not usually have
to use this function; it is used for the implementation of
@ -101,6 +106,10 @@ namespace Exiv2 {
Key& operator=(const Key& rhs) { return *this; }
//@}
private:
//! Internal virtual copy constructor.
virtual Key* clone_() const =0;
}; // class Key
//! Output operator for Key types
@ -241,7 +250,7 @@ namespace Exiv2 {
by subclasses but not directly.
*/
Metadatum& operator=(const Metadatum& rhs) { return *this; }
//@}
//@}
}; // class Metadatum

View File

@ -20,13 +20,13 @@
*/
/*
File: tags.cpp
Version: $Name: $ $Revision: 1.38 $
Version: $Name: $ $Revision: 1.39 $
Author(s): Andreas Huggel (ahu) <ahuggel@gmx.net>
History: 15-Jan-04, ahu: created
*/
// *****************************************************************************
#include "rcsid.hpp"
EXIV2_RCSID("@(#) $Name: $ $Revision: 1.38 $ $RCSfile: tags.cpp,v $");
EXIV2_RCSID("@(#) $Name: $ $Revision: 1.39 $ $RCSfile: tags.cpp,v $");
// *****************************************************************************
// included header files
@ -473,7 +473,12 @@ namespace Exiv2 {
return ExifTags::tagName(tag_, ifdId_);
}
ExifKey* ExifKey::clone() const
ExifKey::AutoPtr ExifKey::clone() const
{
return AutoPtr(clone_());
}
ExifKey* ExifKey::clone_() const
{
return new ExifKey(*this);
}

View File

@ -21,7 +21,7 @@
/*!
@file tags.hpp
@brief Exif tag and type information
@version $Name: $ $Revision: 1.29 $
@version $Name: $ $Revision: 1.30 $
@author Andreas Huggel (ahu)
<a href="mailto:ahuggel@gmx.net">ahuggel@gmx.net</a>
@date 15-Jan-04, ahu: created<BR>
@ -201,6 +201,9 @@ namespace Exiv2 {
*/
class ExifKey : public Key {
public:
//! Shortcut for an %ExifKey auto pointer.
typedef std::auto_ptr<ExifKey> AutoPtr;
//! @name Creators
//@{
/*!
@ -247,8 +250,8 @@ namespace Exiv2 {
virtual std::string groupName() const { return ifdItem(); }
virtual std::string tagName() const;
virtual uint16_t tag() const { return tag_; }
virtual ExifKey* clone() const;
AutoPtr clone() const;
//! Interpret and print the value of an Exif tag
std::ostream& printTag(std::ostream& os, const Value& value) const;
//! Return the IFD id
@ -282,6 +285,9 @@ namespace Exiv2 {
//@}
private:
//! Internal virtual copy constructor.
virtual ExifKey* clone_() const;
// DATA
static const char* familyName_;