Debian Codegraph @

BambooTracker/command/instrument/add_instrument_command.cpp

raw
1 /*
2 * SPDX-FileCopyrightText: 2018 Rerrah
3 * SPDX-License-Identifier: MIT
4 */
5
6 #include "add_instrument_command.hpp"
7 #include <utility>
8
9 AddInstrumentCommand::AddInstrumentCommand(std::weak_ptr<InstrumentsManager> manager,
10 int num, InstrumentType type, const std::string& name)
11 : AbstractCommand(CommandId::AddInstrument),
12 manager_(manager),
13 num_(num),
14 type_(type),
15 name_(name)
16 {
17 }
18
19 AddInstrumentCommand::AddInstrumentCommand(std::weak_ptr<InstrumentsManager> manager,
20 std::unique_ptr<AbstractInstrument> inst)
21 : AbstractCommand(CommandId::AddInstrument),
22 manager_(manager),
23 num_(inst->getNumber()),
24 inst_(std::move(inst))
25 {
26 }
27
28 bool AddInstrumentCommand::redo()
29 {
30 if (inst_) manager_.lock()->addInstrument(inst_->clone());
31 else manager_.lock()->addInstrument(num_, type_, name_);
32 return true;
33 }
34
35 bool AddInstrumentCommand::undo()
36 {
37 manager_.lock()->removeInstrument(num_);
38 return true;
39 }