| 1 |
/* |
| 2 |
* Copyright (C) 2019-2021 Rerrah |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person |
| 5 |
* obtaining a copy of this software and associated documentation |
| 6 |
* files (the "Software"), to deal in the Software without |
| 7 |
* restriction, including without limitation the rights to use, |
| 8 |
* copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 |
* copies of the Software, and to permit persons to whom the |
| 10 |
* Software is furnished to do so, subject to the following |
| 11 |
* conditions: |
| 12 |
* |
| 13 |
* The above copyright notice and this permission notice shall be |
| 14 |
* included in all copies or substantial portions of the Software. |
| 15 |
* |
| 16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 17 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
| 18 |
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 20 |
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 21 |
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 23 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 24 |
*/ |
| 25 |
|
| 26 |
#include "bank_io.hpp" |
| 27 |
#include <algorithm> |
| 28 |
#include "file_io_error.hpp" |
| 29 |
#include "btb_io.hpp" |
| 30 |
#include "wopn_io.hpp" |
| 31 |
#include "ff_io.hpp" |
| 32 |
#include "ppc_io.hpp" |
| 33 |
#include "p86_io.hpp" |
| 34 |
#include "pps_io.hpp" |
| 35 |
#include "pvi_io.hpp" |
| 36 |
#include "pzi_io.hpp" |
| 37 |
#include "dat_io.hpp" |
| 38 |
#include "pmb_io.hpp" |
| 39 |
|
| 40 |
namespace io |
| 41 |
{ |
| 42 |
AbstractBank* AbstractBankIO::load(const BinaryContainer& ctr) const |
| 43 |
{ |
| 44 |
(void)ctr; |
| 45 |
throw FileUnsupportedError(FileType::Bank); |
| 46 |
} |
| 47 |
|
| 48 |
void AbstractBankIO::save(BinaryContainer& ctr, const std::weak_ptr<InstrumentsManager> instMan, |
| 49 |
const std::vector<int>& instNums) const |
| 50 |
{ |
| 51 |
(void)ctr; |
| 52 |
(void)instMan; |
| 53 |
(void)instNums; |
| 54 |
throw FileUnsupportedError(io::FileType::Bank); |
| 55 |
} |
| 56 |
|
| 57 |
//------------------------------------------------------------ |
| 58 |
|
| 59 |
std::unique_ptr<BankIO> BankIO::instance_; |
| 60 |
|
| 61 |
BankIO::BankIO() |
| 62 |
{ |
| 63 |
handler_.add(new BtbIO); |
| 64 |
handler_.add(new WopnIO); |
| 65 |
handler_.add(new FfIO); |
| 66 |
handler_.add(new PpcIO); |
| 67 |
handler_.add(new P86IO); |
| 68 |
handler_.add(new PpsIO); |
| 69 |
handler_.add(new PviIO); |
| 70 |
handler_.add(new PziIO); |
| 71 |
handler_.add(new DatIO); |
| 72 |
handler_.add(new PmbIO); |
| 73 |
} |
| 74 |
|
| 75 |
BankIO& BankIO::getInstance() |
| 76 |
{ |
| 77 |
if (!instance_) instance_.reset(new BankIO); |
| 78 |
return *instance_; |
| 79 |
} |
| 80 |
|
| 81 |
void BankIO::saveBank(BinaryContainer& ctr, const std::weak_ptr<InstrumentsManager> instMan, |
| 82 |
const std::vector<int>& instNums) |
| 83 |
{ |
| 84 |
handler_.at("btb")->save(ctr, instMan, instNums); |
| 85 |
} |
| 86 |
|
| 87 |
AbstractBank* BankIO::loadBank(const BinaryContainer& ctr, const std::string& path) |
| 88 |
{ |
| 89 |
return handler_.at(getExtension(path))->load(ctr); |
| 90 |
} |
| 91 |
} |