summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2022-04-28 22:12:54 +0200
committerCarl Hetherington <cth@carlh.net>2022-04-29 23:37:48 +0200
commit54141c7a9504e289d41af997067ca6b78a1d4b0a (patch)
tree4f792d29c6d090837be267362334151b23f00399
parentaff13422649363d7fed58287958ca66b363825ba (diff)
Fix (I think) some strange situations where ::get() on dialogs
used by EditableList would return something that wasn't a optional<> but would then get implicitly cast to one. Now we have a static_assert to check that the type is what we expect.
-rw-r--r--src/tools/dcpomatic_combiner.cc2
-rw-r--r--src/wx/content_version_dialog.cc3
-rw-r--r--src/wx/content_version_dialog.h2
-rw-r--r--src/wx/editable_list.h6
-rw-r--r--src/wx/rating_dialog.cc2
-rw-r--r--src/wx/rating_dialog.h2
6 files changed, 10 insertions, 7 deletions
diff --git a/src/tools/dcpomatic_combiner.cc b/src/tools/dcpomatic_combiner.cc
index 40587e23a..4532b0429 100644
--- a/src/tools/dcpomatic_combiner.cc
+++ b/src/tools/dcpomatic_combiner.cc
@@ -65,7 +65,7 @@ public:
}
- boost::filesystem::path get () const
+ optional<boost::filesystem::path> get () const
{
return boost::filesystem::path(wx_to_std(GetPath()));
}
diff --git a/src/wx/content_version_dialog.cc b/src/wx/content_version_dialog.cc
index 37c9cd416..876f43838 100644
--- a/src/wx/content_version_dialog.cc
+++ b/src/wx/content_version_dialog.cc
@@ -24,6 +24,7 @@
using std::string;
+using boost::optional;
ContentVersionDialog::ContentVersionDialog (wxWindow* parent)
@@ -46,7 +47,7 @@ ContentVersionDialog::set (string r)
}
-string
+optional<string>
ContentVersionDialog::get () const
{
return wx_to_std(_version->GetValue());
diff --git a/src/wx/content_version_dialog.h b/src/wx/content_version_dialog.h
index 8f375984d..8407c0475 100644
--- a/src/wx/content_version_dialog.h
+++ b/src/wx/content_version_dialog.h
@@ -30,7 +30,7 @@ public:
ContentVersionDialog (wxWindow* parent);
void set (std::string);
- std::string get () const;
+ boost::optional<std::string> get () const;
private:
wxTextCtrl* _version;
diff --git a/src/wx/editable_list.h b/src/wx/editable_list.h
index 56c3a9463..e82c4f91c 100644
--- a/src/wx/editable_list.h
+++ b/src/wx/editable_list.h
@@ -210,7 +210,8 @@ private:
S* dialog = new S (this);
if (dialog->ShowModal() == wxID_OK) {
- boost::optional<T> const v = dialog->get ();
+ auto const v = dialog->get ();
+ static_assert(std::is_same<typename std::remove_const<decltype(v)>::type, boost::optional<T>>::value, "get() must return boost::optional<T>");
if (v) {
add_to_control (v.get ());
std::vector<T> all = _get ();
@@ -235,7 +236,8 @@ private:
S* dialog = new S (this);
dialog->set (all[item]);
if (dialog->ShowModal() == wxID_OK) {
- boost::optional<T> const v = dialog->get ();
+ auto const v = dialog->get ();
+ static_assert(std::is_same<typename std::remove_const<decltype(v)>::type, boost::optional<T>>::value, "get() must return boost::optional<T>");
if (!v) {
return;
}
diff --git a/src/wx/rating_dialog.cc b/src/wx/rating_dialog.cc
index 9c75f0d4c..691a7d16d 100644
--- a/src/wx/rating_dialog.cc
+++ b/src/wx/rating_dialog.cc
@@ -92,7 +92,7 @@ RatingDialog::set (dcp::Rating rating)
}
-dcp::Rating
+optional<dcp::Rating>
RatingDialog::get () const
{
return _active_page->get();
diff --git a/src/wx/rating_dialog.h b/src/wx/rating_dialog.h
index 66a93305a..97a56f52e 100644
--- a/src/wx/rating_dialog.h
+++ b/src/wx/rating_dialog.h
@@ -90,7 +90,7 @@ public:
RatingDialog (wxWindow* parent);
void set (dcp::Rating r);
- dcp::Rating get () const;
+ boost::optional<dcp::Rating> get () const;
private:
void setup_sensitivity (bool ok_valid);