aboutsummaryrefslogtreecommitdiff
path: root/src/adlmidi_private.hpp
diff options
context:
space:
mode:
authorVitaly Novichkov <admin@wohlnet.ru>2018-05-16 03:38:54 +0300
committerJP Cimalando <jpcima@users.noreply.github.com>2018-05-16 19:34:07 +0200
commitf7e659977e033f491f00d7e8720c8a4acfc62daf (patch)
treed29769b3325f5ae8cebd228a5d275f3ea3dc5f83 /src/adlmidi_private.hpp
parent5fdd39289affe341151839a48e227d51b08c4a25 (diff)
downloadlibADLMIDI-f7e659977e033f491f00d7e8720c8a4acfc62daf.tar.gz
libADLMIDI-f7e659977e033f491f00d7e8720c8a4acfc62daf.tar.bz2
libADLMIDI-f7e659977e033f491f00d7e8720c8a4acfc62daf.zip
Move smart pointer classes into separated header
Diffstat (limited to 'src/adlmidi_private.hpp')
-rw-r--r--src/adlmidi_private.hpp112
1 files changed, 1 insertions, 111 deletions
diff --git a/src/adlmidi_private.hpp b/src/adlmidi_private.hpp
index b23e845..10bd517 100644
--- a/src/adlmidi_private.hpp
+++ b/src/adlmidi_private.hpp
@@ -145,6 +145,7 @@ typedef int32_t ssize_t;
#ifndef ADLMIDI_DISABLE_CPP_EXTRAS
#include "adlmidi.hpp" //Extra C++ API
#endif
+#include "adlmidi_ptr.hpp"
#include "adlmidi_bankmap.h"
#define ADL_UNUSED(x) (void)x
@@ -200,117 +201,6 @@ inline int32_t adl_cvtU32(int32_t x)
return (uint32_t)adl_cvtS32(x) - (uint32_t)INT32_MIN;
}
-/*
- 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(p != m_p) {
- if(m_p)
- free(m_p);
- m_p = p;
- }
- }
-
- PTR *get()
- {
- return m_p;
- }
- PTR &operator*()
- {
- return *m_p;
- }
- PTR *operator->()
- {
- return m_p;
- }
-private:
- AdlMIDI_CPtr(const AdlMIDI_CPtr &);
- AdlMIDI_CPtr &operator=(const AdlMIDI_CPtr &);
-};
-
-/*
- Shared pointer with non-atomic counter
- FAQ: Why not std::shared_ptr? Because of Android NDK now doesn't supports it
-*/
-template<class VALUE>
-class AdlMIDI_SPtr
-{
- VALUE *m_p;
- size_t *m_counter;
-public:
- AdlMIDI_SPtr() : m_p(NULL), m_counter(NULL) {}
- ~AdlMIDI_SPtr()
- {
- reset(NULL);
- }
-
- AdlMIDI_SPtr(const AdlMIDI_SPtr &other)
- : m_p(other.m_p), m_counter(other.m_counter)
- {
- if(m_counter)
- ++*m_counter;
- }
-
- AdlMIDI_SPtr &operator=(const AdlMIDI_SPtr &other)
- {
- if(this == &other)
- return *this;
- reset();
- m_p = other.m_p;
- m_counter = other.m_counter;
- if(m_counter)
- ++*m_counter;
- return *this;
- }
-
- void reset(VALUE *p = NULL)
- {
- if(p != m_p) {
- if(m_p && --*m_counter == 0)
- delete m_p;
- m_p = p;
- if(!p) {
- if(m_counter) {
- delete m_counter;
- m_counter = NULL;
- }
- }
- else
- {
- if(!m_counter)
- m_counter = new size_t;
- *m_counter = 1;
- }
- }
- }
-
- VALUE *get()
- {
- return m_p;
- }
- VALUE &operator*()
- {
- return *m_p;
- }
- VALUE *operator->()
- {
- return m_p;
- }
-};
-
class MIDIplay;
struct ADL_MIDIPlayer;
class OPL3