[poppler] poppler/Link.cc poppler/Link.h
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Sat Feb 29 10:18:38 UTC 2020
poppler/Link.cc | 60 +++++++++++---------------------------------------------
poppler/Link.h | 37 +++++++++++++---------------------
2 files changed, 26 insertions(+), 71 deletions(-)
New commits:
commit b3cfbbf2679618d0c32670090717a6e2f70faf9c
Author: Oliver Sander <oliver.sander at tu-dresden.de>
Date: Tue Feb 11 22:34:10 2020 +0100
Use std::unique_ptr for LinkGoto data members
This makes it clear that these pointers are owning.
It makes the code slightly shorter, too.
diff --git a/poppler/Link.cc b/poppler/Link.cc
index 0bf57b3e..c9945ce8 100644
--- a/poppler/Link.cc
+++ b/poppler/Link.cc
@@ -425,21 +425,17 @@ LinkDest::LinkDest(const LinkDest *dest) {
//------------------------------------------------------------------------
LinkGoTo::LinkGoTo(const Object *destObj) {
- dest = nullptr;
- namedDest = nullptr;
-
// named destination
if (destObj->isName()) {
- namedDest = new GooString(destObj->getName());
+ namedDest = std::make_unique<GooString>(destObj->getName());
} else if (destObj->isString()) {
- namedDest = destObj->getString()->copy();
+ namedDest = std::unique_ptr<GooString>(destObj->getString()->copy());
// destination dictionary
} else if (destObj->isArray()) {
- dest = new LinkDest(destObj->getArray());
+ dest = std::make_unique<LinkDest>(destObj->getArray());
if (!dest->isOk()) {
- delete dest;
- dest = nullptr;
+ dest.reset();
}
// error
@@ -448,40 +444,28 @@ LinkGoTo::LinkGoTo(const Object *destObj) {
}
}
-LinkGoTo::~LinkGoTo() {
- if (dest)
- delete dest;
- if (namedDest)
- delete namedDest;
-}
-
//------------------------------------------------------------------------
// LinkGoToR
//------------------------------------------------------------------------
LinkGoToR::LinkGoToR(Object *fileSpecObj, Object *destObj) {
- fileName = nullptr;
- dest = nullptr;
- namedDest = nullptr;
-
// get file name
Object obj1 = getFileSpecNameForPlatform (fileSpecObj);
if (obj1.isString()) {
- fileName = obj1.getString()->copy();
+ fileName = std::unique_ptr<GooString>(obj1.getString()->copy());
}
// named destination
if (destObj->isName()) {
- namedDest = new GooString(destObj->getName());
+ namedDest = std::make_unique<GooString>(destObj->getName());
} else if (destObj->isString()) {
- namedDest = destObj->getString()->copy();
+ namedDest = std::unique_ptr<GooString>(destObj->getString()->copy());
// destination dictionary
} else if (destObj->isArray()) {
- dest = new LinkDest(destObj->getArray());
+ dest = std::make_unique<LinkDest>(destObj->getArray());
if (!dest->isOk()) {
- delete dest;
- dest = nullptr;
+ dest.reset();
}
// error
@@ -490,31 +474,18 @@ LinkGoToR::LinkGoToR(Object *fileSpecObj, Object *destObj) {
}
}
-LinkGoToR::~LinkGoToR() {
- if (fileName)
- delete fileName;
- if (dest)
- delete dest;
- if (namedDest)
- delete namedDest;
-}
-
-
//------------------------------------------------------------------------
// LinkLaunch
//------------------------------------------------------------------------
LinkLaunch::LinkLaunch(const Object *actionObj) {
- fileName = nullptr;
- params = nullptr;
-
if (actionObj->isDict()) {
Object obj1 = actionObj->dictLookup("F");
if (!obj1.isNull()) {
Object obj3 = getFileSpecNameForPlatform (&obj1);
if (obj3.isString()) {
- fileName = obj3.getString()->copy();
+ fileName = std::unique_ptr<GooString>(obj3.getString()->copy());
}
} else {
#ifdef _WIN32
@@ -528,11 +499,11 @@ LinkLaunch::LinkLaunch(const Object *actionObj) {
Object obj2 = obj1.dictLookup("F");
Object obj3 = getFileSpecNameForPlatform (&obj2);
if (obj3.isString()) {
- fileName = obj3.getString()->copy();
+ fileName = std::unique_ptr<GooString>(obj3.getString()->copy());
}
obj2 = obj1.dictLookup("P");
if (obj2.isString()) {
- params = obj2.getString()->copy();
+ params = std::unique_ptr<GooString>(obj2.getString()->copy());
}
} else {
error(errSyntaxWarning, -1, "Bad launch-type link action");
@@ -541,13 +512,6 @@ LinkLaunch::LinkLaunch(const Object *actionObj) {
}
}
-LinkLaunch::~LinkLaunch() {
- if (fileName)
- delete fileName;
- if (params)
- delete params;
-}
-
//------------------------------------------------------------------------
// LinkURI
//------------------------------------------------------------------------
diff --git a/poppler/Link.h b/poppler/Link.h
index b996f560..3aa5e0a8 100644
--- a/poppler/Link.h
+++ b/poppler/Link.h
@@ -164,22 +164,19 @@ public:
// Build a LinkGoTo from a destination (dictionary, name, or string).
LinkGoTo(const Object *destObj);
- // Destructor.
- ~LinkGoTo() override;
-
// Was the LinkGoTo created successfully?
bool isOk() const override { return dest || namedDest; }
// Accessors.
LinkActionKind getKind() const override { return actionGoTo; }
- const LinkDest *getDest() const { return dest; }
- const GooString *getNamedDest() const { return namedDest; }
+ const LinkDest *getDest() const { return dest.get(); }
+ const GooString *getNamedDest() const { return namedDest.get(); }
private:
- LinkDest *dest; // regular destination (nullptr for remote
+ std::unique_ptr<LinkDest> dest; // regular destination (nullptr for remote
// link with bad destination)
- GooString *namedDest; // named destination (only one of dest and
+ std::unique_ptr<GooString> namedDest; // named destination (only one of dest and
// and namedDest may be non-nullptr)
};
@@ -194,24 +191,21 @@ public:
// (dictionary, name, or string).
LinkGoToR(Object *fileSpecObj, Object *destObj);
- // Destructor.
- ~LinkGoToR() override;
-
// Was the LinkGoToR created successfully?
bool isOk() const override { return fileName && (dest || namedDest); }
// Accessors.
LinkActionKind getKind() const override { return actionGoToR; }
- const GooString *getFileName() const { return fileName; }
- const LinkDest *getDest() const { return dest; }
- const GooString *getNamedDest() const { return namedDest; }
+ const GooString *getFileName() const { return fileName.get(); }
+ const LinkDest *getDest() const { return dest.get(); }
+ const GooString *getNamedDest() const { return namedDest.get(); }
private:
- GooString *fileName; // file name
- LinkDest *dest; // regular destination (nullptr for remote
+ std::unique_ptr<GooString> fileName; // file name
+ std::unique_ptr<LinkDest> dest; // regular destination (nullptr for remote
// link with bad destination)
- GooString *namedDest; // named destination (only one of dest and
+ std::unique_ptr<GooString> namedDest; // named destination (only one of dest and
// and namedDest may be non-nullptr)
};
@@ -225,21 +219,18 @@ public:
// Build a LinkLaunch from an action dictionary.
LinkLaunch(const Object *actionObj);
- // Destructor.
- ~LinkLaunch() override;
-
// Was the LinkLaunch created successfully?
bool isOk() const override { return fileName != nullptr; }
// Accessors.
LinkActionKind getKind() const override { return actionLaunch; }
- const GooString *getFileName() const { return fileName; }
- const GooString *getParams() const { return params; }
+ const GooString *getFileName() const { return fileName.get(); }
+ const GooString *getParams() const { return params.get(); }
private:
- GooString *fileName; // file name
- GooString *params; // parameters
+ std::unique_ptr<GooString> fileName; // file name
+ std::unique_ptr<GooString> params; // parameters
};
//------------------------------------------------------------------------
More information about the poppler
mailing list