Commit b3cfbbf2 authored by Oliver Sander's avatar Oliver Sander Committed by Albert Astals Cid

Use std::unique_ptr for LinkGoto data members

This makes it clear that these pointers are owning.
It makes the code slightly shorter, too.
parent a9ba550c
Pipeline #114160 passed with stage
in 4 minutes and 48 seconds
......@@ -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
//------------------------------------------------------------------------
......
......@@ -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
};
//------------------------------------------------------------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment