Skip to content

Commit

Permalink
Clean up code (keepassxreboot#3431)
Browse files Browse the repository at this point in the history
* Empty destructors are replaced with default destructors
* A few loop variables made into const references to avoid copies
* Add missing `override` spec for some `Command::execute` methods
  • Loading branch information
sjamesr authored and phoerious committed Aug 19, 2019
1 parent 7cbcea1 commit b9e1088
Show file tree
Hide file tree
Showing 27 changed files with 12 additions and 78 deletions.
4 changes: 0 additions & 4 deletions src/cli/Add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ Add::Add()
positionalArguments.append({QString("entry"), QObject::tr("Path of the entry to add."), QString("")});
}

Add::~Add()
{
}

int Add::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<QCommandLineParser> parser)
{
TextStream inputTextStream(Utils::STDIN, QIODevice::ReadOnly);
Expand Down
3 changes: 1 addition & 2 deletions src/cli/Add.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ class Add : public DatabaseCommand
{
public:
Add();
~Add();

int executeWithDatabase(QSharedPointer<Database> db, QSharedPointer<QCommandLineParser> parser);
int executeWithDatabase(QSharedPointer<Database> db, QSharedPointer<QCommandLineParser> parser) override;

static const QCommandLineOption UsernameOption;
static const QCommandLineOption UrlOption;
Expand Down
4 changes: 0 additions & 4 deletions src/cli/Clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ Clip::Clip()
{QString("timeout"), QObject::tr("Timeout in seconds before clearing the clipboard."), QString("[timeout]")});
}

Clip::~Clip()
{
}

int Clip::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<QCommandLineParser> parser)
{
const QStringList args = parser->positionalArguments();
Expand Down
3 changes: 1 addition & 2 deletions src/cli/Clip.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ class Clip : public DatabaseCommand
{
public:
Clip();
~Clip();

int executeWithDatabase(QSharedPointer<Database> db, QSharedPointer<QCommandLineParser> parser);
int executeWithDatabase(QSharedPointer<Database> db, QSharedPointer<QCommandLineParser> parser) override;

static const QCommandLineOption TotpOption;
};
Expand Down
6 changes: 3 additions & 3 deletions src/cli/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ QSharedPointer<QCommandLineParser> Command::getCommandLineParser(const QStringLi

QSharedPointer<QCommandLineParser> parser = QSharedPointer<QCommandLineParser>(new QCommandLineParser());
parser->setApplicationDescription(description);
for (CommandLineArgument positionalArgument : positionalArguments) {
for (const CommandLineArgument& positionalArgument : positionalArguments) {
parser->addPositionalArgument(
positionalArgument.name, positionalArgument.description, positionalArgument.syntax);
}
for (CommandLineArgument optionalArgument : optionalArguments) {
for (const CommandLineArgument& optionalArgument : optionalArguments) {
parser->addPositionalArgument(optionalArgument.name, optionalArgument.description, optionalArgument.syntax);
}
for (QCommandLineOption option : options) {
for (const QCommandLineOption& option : options) {
parser->addOption(option);
}
parser->addHelpOption();
Expand Down
4 changes: 0 additions & 4 deletions src/cli/Create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ Create::Create()
options.append(Command::KeyFileOption);
}

Create::~Create()
{
}

/**
* Create a database file using the command line. A key file and/or
* password can be specified to encrypt the password. If none is
Expand Down
4 changes: 1 addition & 3 deletions src/cli/Create.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ class Create : public Command
{
public:
Create();
~Create();
int execute(const QStringList& arguments);
int execute(const QStringList& arguments) override;

private:
QSharedPointer<PasswordKey> getPasswordFromStdin();
QSharedPointer<FileKey> getFileKeyFromStdin();
bool loadFileKey(const QString& path, QSharedPointer<FileKey>& fileKey);
};

Expand Down
4 changes: 0 additions & 4 deletions src/cli/Diceware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ Diceware::Diceware()
options.append(Diceware::WordListOption);
}

Diceware::~Diceware()
{
}

int Diceware::execute(const QStringList& arguments)
{
QSharedPointer<QCommandLineParser> parser = getCommandLineParser(arguments);
Expand Down
3 changes: 1 addition & 2 deletions src/cli/Diceware.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ class Diceware : public Command
{
public:
Diceware();
~Diceware();

int execute(const QStringList& arguments);
int execute(const QStringList& arguments) override;

static const QCommandLineOption WordCountOption;
static const QCommandLineOption WordListOption;
Expand Down
4 changes: 0 additions & 4 deletions src/cli/Edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ Edit::Edit()
positionalArguments.append({QString("entry"), QObject::tr("Path of the entry to edit."), QString("")});
}

Edit::~Edit()
{
}

int Edit::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<QCommandLineParser> parser)
{
TextStream outputTextStream(parser->isSet(Command::QuietOption) ? Utils::DEVNULL : Utils::STDOUT,
Expand Down
3 changes: 1 addition & 2 deletions src/cli/Edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class Edit : public DatabaseCommand
{
public:
Edit();
~Edit();
int executeWithDatabase(QSharedPointer<Database> db, QSharedPointer<QCommandLineParser> parser);
int executeWithDatabase(QSharedPointer<Database> db, QSharedPointer<QCommandLineParser> parser) override;

static const QCommandLineOption TitleOption;
};
Expand Down
4 changes: 0 additions & 4 deletions src/cli/Estimate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ Estimate::Estimate()
description = QObject::tr("Estimate the entropy of a password.");
}

Estimate::~Estimate()
{
}

static void estimate(const char* pwd, bool advanced)
{
TextStream out(Utils::STDOUT, QIODevice::WriteOnly);
Expand Down
1 change: 0 additions & 1 deletion src/cli/Estimate.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class Estimate : public Command
{
public:
Estimate();
~Estimate();
int execute(const QStringList& arguments) override;

static const QCommandLineOption AdvancedOption;
Expand Down
4 changes: 0 additions & 4 deletions src/cli/Extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ Extract::Extract()
description = QObject::tr("Extract and print the content of a database.");
}

Extract::~Extract()
{
}

int Extract::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<QCommandLineParser>)
{
TextStream outputTextStream(Utils::STDOUT, QIODevice::WriteOnly);
Expand Down
3 changes: 1 addition & 2 deletions src/cli/Extract.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ class Extract : public DatabaseCommand
{
public:
Extract();
~Extract();

int executeWithDatabase(QSharedPointer<Database> db, QSharedPointer<QCommandLineParser> parser);
int executeWithDatabase(QSharedPointer<Database> db, QSharedPointer<QCommandLineParser> parser) override;
};

#endif // KEEPASSXC_EXTRACT_H
4 changes: 0 additions & 4 deletions src/cli/Generate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ Generate::Generate()
options.append(Generate::IncludeEveryGroupOption);
}

Generate::~Generate()
{
}

int Generate::execute(const QStringList& arguments)
{
QSharedPointer<QCommandLineParser> parser = getCommandLineParser(arguments);
Expand Down
1 change: 0 additions & 1 deletion src/cli/Generate.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class Generate : public Command
{
public:
Generate();
~Generate();
int execute(const QStringList& arguments) override;

static const QCommandLineOption PasswordLengthOption;
Expand Down
4 changes: 0 additions & 4 deletions src/cli/List.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ List::List()
{QString("group"), QObject::tr("Path of the group to list. Default is /"), QString("[group]")});
}

List::~List()
{
}

int List::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<QCommandLineParser> parser)
{
TextStream outputTextStream(Utils::STDOUT, QIODevice::WriteOnly);
Expand Down
3 changes: 1 addition & 2 deletions src/cli/List.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ class List : public DatabaseCommand
{
public:
List();
~List();

int executeWithDatabase(QSharedPointer<Database> db, QSharedPointer<QCommandLineParser> parser);
int executeWithDatabase(QSharedPointer<Database> db, QSharedPointer<QCommandLineParser> parser) override;

static const QCommandLineOption RecursiveOption;
static const QCommandLineOption FlattenOption;
Expand Down
4 changes: 0 additions & 4 deletions src/cli/Locate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ Locate::Locate()
positionalArguments.append({QString("term"), QObject::tr("Search term."), QString("")});
}

Locate::~Locate()
{
}

int Locate::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<QCommandLineParser> parser)
{

Expand Down
3 changes: 1 addition & 2 deletions src/cli/Locate.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ class Locate : public DatabaseCommand
{
public:
Locate();
~Locate();

int executeWithDatabase(QSharedPointer<Database> db, QSharedPointer<QCommandLineParser> parser);
int executeWithDatabase(QSharedPointer<Database> db, QSharedPointer<QCommandLineParser> parser) override;
};

#endif // KEEPASSXC_LOCATE_H
4 changes: 0 additions & 4 deletions src/cli/Merge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ Merge::Merge()
positionalArguments.append({QString("database2"), QObject::tr("Path of the database to merge from."), QString("")});
}

Merge::~Merge()
{
}

int Merge::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<QCommandLineParser> parser)
{
TextStream outputTextStream(parser->isSet(Command::QuietOption) ? Utils::DEVNULL : Utils::STDOUT,
Expand Down
3 changes: 1 addition & 2 deletions src/cli/Merge.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ class Merge : public DatabaseCommand
{
public:
Merge();
~Merge();

int executeWithDatabase(QSharedPointer<Database> db, QSharedPointer<QCommandLineParser> parser);
int executeWithDatabase(QSharedPointer<Database> db, QSharedPointer<QCommandLineParser> parser) override;

static const QCommandLineOption SameCredentialsOption;
static const QCommandLineOption KeyFileFromOption;
Expand Down
4 changes: 0 additions & 4 deletions src/cli/Remove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ Remove::Remove()
positionalArguments.append({QString("entry"), QObject::tr("Path of the entry to remove."), QString("")});
}

Remove::~Remove()
{
}

int Remove::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<QCommandLineParser> parser)
{
bool quiet = parser->isSet(Command::QuietOption);
Expand Down
1 change: 0 additions & 1 deletion src/cli/Remove.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class Remove : public DatabaseCommand
{
public:
Remove();
~Remove();

int executeWithDatabase(QSharedPointer<Database> db, QSharedPointer<QCommandLineParser> parser);
};
Expand Down
4 changes: 0 additions & 4 deletions src/cli/Show.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ Show::Show()
positionalArguments.append({QString("entry"), QObject::tr("Name of the entry to show."), QString("")});
}

Show::~Show()
{
}

int Show::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<QCommandLineParser> parser)
{
TextStream outputTextStream(Utils::STDOUT, QIODevice::WriteOnly);
Expand Down
1 change: 0 additions & 1 deletion src/cli/Show.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class Show : public DatabaseCommand
{
public:
Show();
~Show();

int executeWithDatabase(QSharedPointer<Database> db, QSharedPointer<QCommandLineParser> parser);

Expand Down

0 comments on commit b9e1088

Please sign in to comment.