Fix (I think) some strange situations where ::get() on dialogs
authorCarl Hetherington <cth@carlh.net>
Thu, 28 Apr 2022 20:12:54 +0000 (22:12 +0200)
committerCarl Hetherington <cth@carlh.net>
Fri, 29 Apr 2022 21:37:48 +0000 (23:37 +0200)
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.

src/tools/dcpomatic_combiner.cc
src/wx/content_version_dialog.cc
src/wx/content_version_dialog.h
src/wx/editable_list.h
src/wx/rating_dialog.cc
src/wx/rating_dialog.h

index 40587e23ad4b5f9fae1ea114fadc7ca824751d6b..4532b04299981c35297d97d5b3bee0dbc1ef83eb 100644 (file)
@@ -65,7 +65,7 @@ public:
 
        }
 
-       boost::filesystem::path get () const
+       optional<boost::filesystem::path> get () const
        {
                return boost::filesystem::path(wx_to_std(GetPath()));
        }
index 37c9cd416ae9353bc3ee4c4d8df8ced85339c7c5..876f4383855960c4fae4009f670eb83ef4c090c5 100644 (file)
@@ -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());
index 8f375984d92403f4405803c6c4e2ec9fccfe4cdb..8407c0475b97f389e119eda1beec80431bc9ba77 100644 (file)
@@ -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;
index 56c3a946379cedfa99ef19da832327eda7597291..e82c4f91cdf77b44d9c35eb5bb786f6e3ae00b06 100644 (file)
@@ -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;
                        }
index 9c75f0d4cacf8d53bcdd6c408f1583332391891b..691a7d16d5e2555ceb646920ecb8b895ca8e59aa 100644 (file)
@@ -92,7 +92,7 @@ RatingDialog::set (dcp::Rating rating)
 }
 
 
-dcp::Rating
+optional<dcp::Rating>
 RatingDialog::get () const
 {
        return _active_page->get();
index 66a93305a865df091352a95cfedc1f44feb77331..97a56f52ec6c66fd8686e89e451282a03bde548d 100644 (file)
@@ -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);