commit 379a9ba5ddc1b8a0833fbbb4b868daad9d62d992
parent b8e430fd15a3c654b18309f72f971d589ce862c9
Author: cfillion <cfillion@users.noreply.github.com>
Date: Sun, 5 Jun 2016 14:23:16 -0400
mild refactoring: add operator bool() to Remote
Diffstat:
5 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/src/manager.cpp b/src/manager.cpp
@@ -134,7 +134,7 @@ void Manager::onContextMenu(HWND target, const int x, const int y)
Menu menu;
- if(remote.isNull()) {
+ if(!remote) {
menu.addAction(AUTO_STR("&Select all"), ACTION_SELECT);
menu.addAction(AUTO_STR("&Unselect all"), ACTION_UNSELECT);
menu.show(x, y, handle());
diff --git a/src/reapack.cpp b/src/reapack.cpp
@@ -205,7 +205,7 @@ bool ReaPack::import(const Remote &remote, HWND parent)
const Remote &existing = remotes->get(remote.name());
- if(!existing.isNull()) {
+ if(existing) {
if(existing.isProtected()) {
MessageBox(parent,
AUTO_STR("This repository is protected and cannot be overwritten."),
@@ -297,7 +297,7 @@ void ReaPack::about(const string &remoteName, HWND parent)
void ReaPack::about(const Remote &remote, HWND parent)
{
- if(remote.isNull())
+ if(!remote)
return;
fetchIndex(remote, [=] (IndexPtr index) {
diff --git a/src/remote.cpp b/src/remote.cpp
@@ -119,7 +119,7 @@ string Remote::toString() const
void RemoteList::add(const Remote &remote)
{
- if(!remote.isValid())
+ if(!remote)
return;
size_t index = 0;
diff --git a/src/remote.hpp b/src/remote.hpp
@@ -45,7 +45,6 @@ public:
const std::string &url() const { return m_url; }
bool isNull() const { return m_name.empty() || m_url.empty(); }
- bool isValid() const { return !isNull(); }
void enable() { setEnabled(true); }
void disable() { setEnabled(false); }
@@ -56,6 +55,7 @@ public:
bool isProtected() const { return m_protected; }
bool operator<(const Remote &o) const { return m_name < o.name(); }
+ operator bool() const { return !isNull(); }
private:
std::string m_name;
diff --git a/test/remote.cpp b/test/remote.cpp
@@ -115,6 +115,7 @@ TEST_CASE("valide remote urls", M) {
TEST_CASE("null remote", M) {
Remote remote;
REQUIRE(remote.isNull());
+ REQUIRE_FALSE(remote);
CHECK(remote.isEnabled());
SECTION("set name") {
@@ -133,6 +134,7 @@ TEST_CASE("null remote", M) {
remote.setName("hello");
remote.setUrl("world");
REQUIRE_FALSE(remote.isNull());
+ REQUIRE(remote);
}
}