diff options
author | Christian Glöckner <cgloeckner@freenet.de> | 2016-05-09 11:09:06 +0200 |
---|---|---|
committer | Christian Glöckner <cgloeckner@freenet.de> | 2016-05-26 17:52:21 +0200 |
commit | 52b37cac974eb150d49eee1f0b5ba3654f6d7716 (patch) | |
tree | 353daa0524c2f918caeac17b704b016e651af6e2 /src | |
parent | 355f9e4e2ebace6cce52a277cbaf1d1bfc904d61 (diff) |
Instrument Vector using UniquePtr
Diffstat (limited to 'src')
-rw-r--r-- | src/drumkit.cc | 5 | ||||
-rw-r--r-- | src/drumkitloader.cc | 8 | ||||
-rw-r--r-- | src/drumkitparser.cc | 13 | ||||
-rw-r--r-- | src/instrument.h | 3 | ||||
-rw-r--r-- | src/memchecker.cc | 6 |
5 files changed, 16 insertions, 19 deletions
diff --git a/src/drumkit.cc b/src/drumkit.cc index f25a6ea..1dadf04 100644 --- a/src/drumkit.cc +++ b/src/drumkit.cc @@ -39,11 +39,6 @@ DrumKit::~DrumKit() void DrumKit::clear() { - for(auto& instrument : instruments) - { - delete instrument; - } - instruments.clear(); channels.clear(); diff --git a/src/drumkitloader.cc b/src/drumkitloader.cc index 94daf79..f2ef61a 100644 --- a/src/drumkitloader.cc +++ b/src/drumkitloader.cc @@ -133,15 +133,15 @@ void DrumKitLoader::loadKit(DrumKit *kit) // Count total number of files that need loading: settings.number_of_files.store(0); - for(auto instr : kit->instruments) + for(auto& instr_ptr: kit->instruments) { - settings.number_of_files.fetch_add(instr->audiofiles.size()); + settings.number_of_files.fetch_add(instr_ptr->audiofiles.size()); } // Now actually queue them for loading: - for(auto instr : kit->instruments) + for(auto& instr_ptr: kit->instruments) { - for(auto audiofile : instr->audiofiles) + for(auto& audiofile: instr_ptr->audiofiles) { load_queue.push_back(audiofile); } diff --git a/src/drumkitparser.cc b/src/drumkitparser.cc index 073d240..cd1c32d 100644 --- a/src/drumkitparser.cc +++ b/src/drumkitparser.cc @@ -30,6 +30,7 @@ #include <stdio.h> #include <hugin.hpp> +#include "cpp11fix.h" #include "instrumentparser.h" #include "path.h" #include "drumgizmo.h" @@ -184,14 +185,14 @@ void DrumKitParser::endTag(const std::string& name) { if(name == "instrument") { - Instrument* instrument = new Instrument(settings, rand); - instrument->setGroup(instr_group); - - InstrumentParser parser(*instrument); + auto ptr = std::make_unique<Instrument>(settings, rand); + ptr->setGroup(instr_group); + + InstrumentParser parser(*ptr); parser.parseFile(path + "/" + instr_file); // Transfer ownership to the DrumKit object. - kit.instruments.push_back(instrument); + kit.instruments.push_back(std::move(ptr)); // Assign kit channel numbers to instruments channels. std::vector<InstrumentChannel*>::iterator ic = parser.channellist.begin(); @@ -216,7 +217,7 @@ void DrumKitParser::endTag(const std::string& name) if(c->num == NO_CHANNEL) { ERR(kitparser, "Missing channel '%s' in instrument '%s'\n", - c->name.c_str(), instrument->getName().c_str()); + c->name.c_str(), ptr->getName().c_str()); } else { diff --git a/src/instrument.h b/src/instrument.h index 621dddb..ee67b3f 100644 --- a/src/instrument.h +++ b/src/instrument.h @@ -28,6 +28,7 @@ #include <string> #include <vector> +#include <memory> #include "rangemap.h" #include "powerlist.h" @@ -83,4 +84,4 @@ private: }; // typedef std::map< std::string, Instrument > Instruments; -typedef std::vector<Instrument*> Instruments; +using Instruments = std::vector<std::unique_ptr<Instrument>>; diff --git a/src/memchecker.cc b/src/memchecker.cc index 81c9da7..6d66965 100644 --- a/src/memchecker.cc +++ b/src/memchecker.cc @@ -73,12 +73,12 @@ uint64_t MemChecker::calcNeededMemory(const DrumKit& drumkit) const uint64_t needed_memory = 0; // Calculate memory usage of all instruments of drumkit. - for(auto instrument : drumkit.instruments) + for(auto& instr_ptr: drumkit.instruments) { - const auto& audiofiles = instrument->audiofiles; + const auto& audiofiles = instr_ptr->audiofiles; // Calculate memory usage of all audiofiles. - for(auto audiofile : audiofiles) + for(auto& audiofile: audiofiles) { needed_memory += calcBytesPerChannel(audiofile->filename); } |