diff options
author | Wohlstand <admin@wohlnet.ru> | 2017-02-16 18:07:13 +0300 |
---|---|---|
committer | Wohlstand <admin@wohlnet.ru> | 2017-02-16 18:07:13 +0300 |
commit | 88a117c706328e8ccead5280490a447ab8a28383 (patch) | |
tree | d9b87df76527f17fc83c5392154cadc572e368bb | |
parent | 4091cf15cd5273f1381f1ed6d3e836774f9ac0e8 (diff) | |
download | libADLMIDI-88a117c706328e8ccead5280490a447ab8a28383.tar.gz libADLMIDI-88a117c706328e8ccead5280490a447ab8a28383.tar.bz2 libADLMIDI-88a117c706328e8ccead5280490a447ab8a28383.zip |
Remove usage of std::shared_ptr
because it is not supported on Android NDK, yet (even C++11 usagae is enabled!)
-rw-r--r-- | src/adlmidi_load.cpp | 8 | ||||
-rw-r--r-- | src/adlmidi_private.hpp | 27 |
2 files changed, 30 insertions, 5 deletions
diff --git a/src/adlmidi_load.cpp b/src/adlmidi_load.cpp index 1ef355d..a39c191 100644 --- a/src/adlmidi_load.cpp +++ b/src/adlmidi_load.cpp @@ -26,8 +26,6 @@ #include "adlmidi_mus2mid.h" #include "adlmidi_xmi2mid.h" -#include <memory> - uint64_t MIDIplay::ReadBEint(const void *buffer, size_t nbytes) { uint64_t result = 0; @@ -105,7 +103,7 @@ bool MIDIplay::LoadMIDI(MIDIplay::fileReader &fr) size_t fsize; qqq(fsize); //! Temp buffer for conversion - std::shared_ptr<uint8_t> cvt_buf; + AdlMIDI_CPtr<uint8_t> cvt_buf; //std::FILE* fr = std::fopen(filename.c_str(), "rb"); if(!fr.isValid()) @@ -219,7 +217,7 @@ riffskip: ADLMIDI_ErrorString = "Invalid MUS/DMX data format!"; return false; } - cvt_buf.reset(mid, ::free); + cvt_buf.reset(mid); //Open converted MIDI file fr.openData(mid, static_cast<size_t>(mid_len)); //Re-Read header again! @@ -257,7 +255,7 @@ riffskip: ADLMIDI_ErrorString = "Invalid XMI data format!"; return false; } - cvt_buf.reset(mid, ::free); + cvt_buf.reset(mid); //Open converted MIDI file fr.openData(mid, static_cast<size_t>(mid_len)); //Re-Read header again! diff --git a/src/adlmidi_private.hpp b/src/adlmidi_private.hpp index 4f89cae..2d6ecae 100644 --- a/src/adlmidi_private.hpp +++ b/src/adlmidi_private.hpp @@ -68,6 +68,33 @@ extern std::string ADLMIDI_ErrorString; +/* + Smart pointer for C heaps, created with malloc() call. + FAQ: Why not std::shared_ptr? Because of Android NDK now doesn't supports it +*/ +template<class PTR> +class AdlMIDI_CPtr +{ + PTR* m_p; +public: + AdlMIDI_CPtr() : m_p(NULL) {} + ~AdlMIDI_CPtr() + { + reset(NULL); + } + + void reset(PTR *p = NULL) + { + if(m_p) + free(m_p); + m_p = p; + } + + PTR* get() { return m_p;} + PTR& operator*() { return *m_p; } + PTR* operator->() { return m_p; } +}; + class MIDIplay; struct OPL3 { |