Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 87 additions & 4 deletions Code/png_cicp_editor/Actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Action::Action(VersionAction version) noexcept
: action_type_(Actions::Version)
, action_{.version_ = std::move(version)}
{
action_.version_ = std::move(version);
}
{}

Action::Action(HelpAction help) noexcept
: action_type_(Actions::Help)
Expand Down Expand Up @@ -298,7 +296,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
{}

Action::Action(const Action& rhs) noexcept
: action_type_(rhs.action_type_)
: action_type_(std::move(rhs.action_type_))
, action_{.version_{}}
{
switch (action_type_) {
Expand Down Expand Up @@ -349,4 +347,89 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
}
}


Action::~Action() noexcept {
switch (action_type_) {
case Actions::Version:
(&action_.version_)->~VersionAction();
break;
case Actions::Help:
(&action_.help_)->~HelpAction();
break;
case Actions::License:
(&action_.license_)->~LicenseAction();
break;
case Actions::Add:
(&action_.add_)->~AddAction();
break;
case Actions::Overwrite:
(&action_.overwrite_)->~OverwriteAction();
break;
case Actions::Remove:
(&action_.remove_)->~RemoveAction();
break;
}
}

Action& Action::operator =(const Action& rhs) noexcept {
this->~Action();

action_type_ = rhs.action_type_;

switch (rhs.action_type_) {
case Actions::Version:
action_.version_ = rhs.action_.version_;
break;
case Actions::Help:
action_.help_ = rhs.action_.help_;
break;
case Actions::License:
action_.license_ = rhs.action_.license_;
break;
case Actions::Add:
action_.add_ = rhs.action_.add_;
break;
case Actions::Overwrite:
action_.overwrite_ = rhs.action_.overwrite_;
break;
case Actions::Remove:
action_.remove_ = rhs.action_.remove_;
break;
}

return *this;
}

Action& Action::operator =(Action&& rhs) noexcept {
this->~Action();

action_type_ = std::move(rhs.action_type_);

switch (rhs.action_type_) {
case Actions::Version:
action_.version_ = std::move(rhs.action_.version_);
break;
case Actions::Help:
action_.help_ = std::move(rhs.action_.help_);
break;
case Actions::License:
action_.license_ = std::move(rhs.action_.license_);
break;
case Actions::Add:
action_.add_ = std::move(rhs.action_.add_);
break;
case Actions::Overwrite:
action_.overwrite_ = std::move(rhs.action_.overwrite_);
break;
case Actions::Remove:
action_.remove_ = std::move(rhs.action_.remove_);
break;
}

return *this;
}

Action::A::~A() noexcept {
}

} // namespace PNG_CICP_Editor
7 changes: 6 additions & 1 deletion Code/png_cicp_editor/Actions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ namespace PNG_CICP_Editor {
Action(const Action& rhs) noexcept;
Action(Action&& rhs) noexcept;

~Action() noexcept;

Action& operator =(const Action& rhs) noexcept;
Action& operator =(Action&& rhs) noexcept;

Actions action_type_;
union A {
VersionAction version_;
Expand All @@ -79,7 +84,7 @@ namespace PNG_CICP_Editor {
OverwriteAction overwrite_;
RemoveAction remove_;

~A() noexcept {}
~A() noexcept;
} action_;
};

Expand Down
Loading