enhanced constructors of some Mmged classes.
added Mmged:setMmgr() and changed the accessibility of the member manager variable
This commit is contained in:
parent
23b718f366
commit
3793785e7c
@ -57,7 +57,7 @@ public:
|
|||||||
|
|
||||||
static qse_size_t getHashCode (const qse_char_t* str)
|
static qse_size_t getHashCode (const qse_char_t* str)
|
||||||
{
|
{
|
||||||
return this->getHashCode (0, str);
|
return Hashable::getHashCode (0, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
static qse_size_t getHashCode (qse_size_t init, const void* data, qse_size_t size)
|
static qse_size_t getHashCode (qse_size_t init, const void* data, qse_size_t size)
|
||||||
@ -88,7 +88,7 @@ public:
|
|||||||
|
|
||||||
static qse_size_t getHashCode (const void* data, qse_size_t size)
|
static qse_size_t getHashCode (const void* data, qse_size_t size)
|
||||||
{
|
{
|
||||||
return this->getHashCode (0, data, size);
|
return Hashable::getHashCode (0, data, size);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ pkginclude_HEADERS = \
|
|||||||
if ENABLE_CXX
|
if ENABLE_CXX
|
||||||
pkginclude_HEADERS += \
|
pkginclude_HEADERS += \
|
||||||
Types.hpp Hashable.hpp Uncopyable.hpp RefCounted.hpp \
|
Types.hpp Hashable.hpp Uncopyable.hpp RefCounted.hpp \
|
||||||
ScopedPtr.hpp Exception.hpp
|
Exception.hpp
|
||||||
endif
|
endif
|
||||||
|
|
||||||
install-data-hook:
|
install-data-hook:
|
||||||
|
@ -52,7 +52,7 @@ build_triplet = @build@
|
|||||||
host_triplet = @host@
|
host_triplet = @host@
|
||||||
@ENABLE_CXX_TRUE@am__append_1 = \
|
@ENABLE_CXX_TRUE@am__append_1 = \
|
||||||
@ENABLE_CXX_TRUE@ Types.hpp Hashable.hpp Uncopyable.hpp RefCounted.hpp \
|
@ENABLE_CXX_TRUE@ Types.hpp Hashable.hpp Uncopyable.hpp RefCounted.hpp \
|
||||||
@ENABLE_CXX_TRUE@ ScopedPtr.hpp Exception.hpp
|
@ENABLE_CXX_TRUE@ Exception.hpp
|
||||||
|
|
||||||
subdir = include/qse
|
subdir = include/qse
|
||||||
DIST_COMMON = $(am__pkginclude_HEADERS_DIST) $(srcdir)/Makefile.am \
|
DIST_COMMON = $(am__pkginclude_HEADERS_DIST) $(srcdir)/Makefile.am \
|
||||||
@ -95,7 +95,7 @@ am__can_run_installinfo = \
|
|||||||
am__pkginclude_HEADERS_DIST = conf-msw.h conf-os2.h conf-dos.h \
|
am__pkginclude_HEADERS_DIST = conf-msw.h conf-os2.h conf-dos.h \
|
||||||
conf-vms.h conf-mac.h conf-inf.h types.h macros.h pack1.h \
|
conf-vms.h conf-mac.h conf-inf.h types.h macros.h pack1.h \
|
||||||
unpack.h Types.hpp Hashable.hpp Uncopyable.hpp RefCounted.hpp \
|
unpack.h Types.hpp Hashable.hpp Uncopyable.hpp RefCounted.hpp \
|
||||||
ScopedPtr.hpp Exception.hpp
|
Exception.hpp
|
||||||
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
|
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
|
||||||
am__vpath_adj = case $$p in \
|
am__vpath_adj = case $$p in \
|
||||||
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
|
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
|
||||||
|
@ -75,7 +75,8 @@ public:
|
|||||||
INVALID_INDEX = ~(qse_size_t)0
|
INVALID_INDEX = ~(qse_size_t)0
|
||||||
};
|
};
|
||||||
|
|
||||||
Array (Mmgr* mmgr = QSE_NULL, qse_size_t capacity = DEFAULT_CAPACITY): Mmged (mmgr)
|
private:
|
||||||
|
void init_array (int capacity)
|
||||||
{
|
{
|
||||||
if (capacity <= 0)
|
if (capacity <= 0)
|
||||||
{
|
{
|
||||||
@ -92,6 +93,17 @@ public:
|
|||||||
this->count = 0;
|
this->count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
Array (qse_size_t capacity = DEFAULT_CAPACITY): Mmged (QSE_NULL)
|
||||||
|
{
|
||||||
|
this->init_array (capacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
Array (Mmgr* mmgr, qse_size_t capacity = DEFAULT_CAPACITY): Mmged (mmgr)
|
||||||
|
{
|
||||||
|
this->init_array (capacity);
|
||||||
|
}
|
||||||
|
|
||||||
Array (const SelfType& array):
|
Array (const SelfType& array):
|
||||||
Mmged (array.getMmgr()),
|
Mmged (array.getMmgr()),
|
||||||
count (0), capacity (0), buffer (QSE_NULL)
|
count (0), capacity (0), buffer (QSE_NULL)
|
||||||
|
@ -117,7 +117,12 @@ public:
|
|||||||
INVALID_INDEX = ParentType::INVALID_INDEX
|
INVALID_INDEX = ParentType::INVALID_INDEX
|
||||||
};
|
};
|
||||||
|
|
||||||
BinaryHeap (Mmgr* mmgr = QSE_NULL, qse_size_t capacity = DEFAULT_CAPACITY):
|
BinaryHeap (qse_size_t capacity = DEFAULT_CAPACITY):
|
||||||
|
ParentType (QSE_NULL, capacity)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
BinaryHeap (Mmgr* mmgr, qse_size_t capacity = DEFAULT_CAPACITY):
|
||||||
ParentType (mmgr, capacity)
|
ParentType (mmgr, capacity)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -99,11 +99,8 @@ public:
|
|||||||
MIN_LOAD_FACTOR = 20
|
MIN_LOAD_FACTOR = 20
|
||||||
};
|
};
|
||||||
|
|
||||||
HashList (
|
private:
|
||||||
Mmgr* mmgr = QSE_NULL,
|
void init_list (qse_size_t node_capacity, qse_size_t load_factor, qse_size_t mpb_size)
|
||||||
qse_size_t node_capacity = DEFAULT_CAPACITY,
|
|
||||||
qse_size_t load_factor = DEFAULT_LOAD_FACTOR,
|
|
||||||
qse_size_t mpb_size = 0): Mmged(mmgr)
|
|
||||||
{
|
{
|
||||||
if (node_capacity < MIN_CAPACITY) node_capacity = MIN_CAPACITY;
|
if (node_capacity < MIN_CAPACITY) node_capacity = MIN_CAPACITY;
|
||||||
if (load_factor < MIN_LOAD_FACTOR) load_factor = MIN_LOAD_FACTOR;
|
if (load_factor < MIN_LOAD_FACTOR) load_factor = MIN_LOAD_FACTOR;
|
||||||
@ -151,7 +148,25 @@ public:
|
|||||||
this->threshold = node_capacity * load_factor / 100;
|
this->threshold = node_capacity * load_factor / 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
HashList (const SelfType& list): Mmged (list)
|
public:
|
||||||
|
HashList (
|
||||||
|
qse_size_t node_capacity = DEFAULT_CAPACITY,
|
||||||
|
qse_size_t load_factor = DEFAULT_LOAD_FACTOR,
|
||||||
|
qse_size_t mpb_size = 0): Mmged(QSE_NULL)
|
||||||
|
{
|
||||||
|
this->init_list (node_capacity, load_factor, mpb_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
HashList (
|
||||||
|
Mmgr* mmgr,
|
||||||
|
qse_size_t node_capacity = DEFAULT_CAPACITY,
|
||||||
|
qse_size_t load_factor = DEFAULT_LOAD_FACTOR,
|
||||||
|
qse_size_t mpb_size = 0): Mmged(mmgr)
|
||||||
|
{
|
||||||
|
this->init_list (node_capacity, load_factor, mpb_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
HashList (const SelfType& list): Mmged(list)
|
||||||
{
|
{
|
||||||
this->nodes = QSE_NULL;
|
this->nodes = QSE_NULL;
|
||||||
this->node_capacity = 0;
|
this->node_capacity = 0;
|
||||||
|
@ -117,15 +117,22 @@ public:
|
|||||||
MIN_LOAD_FACTOR = PairList::MIN_LOAD_FACTOR
|
MIN_LOAD_FACTOR = PairList::MIN_LOAD_FACTOR
|
||||||
};
|
};
|
||||||
|
|
||||||
HashTable (Mmgr* mmgr = QSE_NULL,
|
HashTable (qse_size_t capacity = DEFAULT_CAPACITY,
|
||||||
qse_size_t capacity = DEFAULT_CAPACITY,
|
|
||||||
qse_size_t load_factor = DEFAULT_LOAD_FACTOR,
|
qse_size_t load_factor = DEFAULT_LOAD_FACTOR,
|
||||||
qse_size_t mpb_size = 0):
|
qse_size_t mpb_size = 0):
|
||||||
Mmged(mmgr), pair_list (mmgr, capacity, load_factor, mpb_size)
|
Mmged(QSE_NULL), pair_list(QSE_NULL, capacity, load_factor, mpb_size)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
HashTable (const SelfType& table): Mmged (table), pair_list (table.pair_list)
|
HashTable (Mmgr* mmgr,
|
||||||
|
qse_size_t capacity = DEFAULT_CAPACITY,
|
||||||
|
qse_size_t load_factor = DEFAULT_LOAD_FACTOR,
|
||||||
|
qse_size_t mpb_size = 0):
|
||||||
|
Mmged(mmgr), pair_list(mmgr, capacity, load_factor, mpb_size)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
HashTable (const SelfType& table): Mmged(table), pair_list(table.pair_list)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,8 +211,16 @@ public:
|
|||||||
this->clear (true);
|
this->clear (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
LinkedList (Mmgr* mmgr = QSE_NULL, qse_size_t mpb_size = 0):
|
LinkedList (qse_size_t mpb_size = 0):
|
||||||
Mmged(mmgr), mp (mmgr, QSE_SIZEOF(Node), mpb_size)
|
Mmged(QSE_NULL), mp(QSE_NULL, QSE_SIZEOF(Node), mpb_size)
|
||||||
|
{
|
||||||
|
this->node_count = 0;
|
||||||
|
this->head_node = QSE_NULL;
|
||||||
|
this->tail_node = QSE_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
LinkedList (Mmgr* mmgr, qse_size_t mpb_size = 0):
|
||||||
|
Mmged(mmgr), mp(mmgr, QSE_SIZEOF(Node), mpb_size)
|
||||||
{
|
{
|
||||||
this->node_count = 0;
|
this->node_count = 0;
|
||||||
this->head_node = QSE_NULL;
|
this->head_node = QSE_NULL;
|
||||||
|
@ -51,7 +51,8 @@ pkginclude_HEADERS = \
|
|||||||
|
|
||||||
if ENABLE_CXX
|
if ENABLE_CXX
|
||||||
pkginclude_HEADERS += \
|
pkginclude_HEADERS += \
|
||||||
Mmgr.hpp StdMmgr.hpp HeapMmgr.hpp Mmged.hpp SharedPtr.hpp \
|
Mmgr.hpp StdMmgr.hpp HeapMmgr.hpp Mmged.hpp \
|
||||||
|
ScopedPtr.hpp SharedPtr.hpp \
|
||||||
Mpool.hpp Association.hpp LinkedList.hpp HashList.hpp HashTable.hpp \
|
Mpool.hpp Association.hpp LinkedList.hpp HashList.hpp HashTable.hpp \
|
||||||
RedBlackTree.hpp RedBlackTable.hpp \
|
RedBlackTree.hpp RedBlackTable.hpp \
|
||||||
Array.hpp BinaryHeap.hpp
|
Array.hpp BinaryHeap.hpp
|
||||||
|
@ -51,7 +51,8 @@ POST_UNINSTALL = :
|
|||||||
build_triplet = @build@
|
build_triplet = @build@
|
||||||
host_triplet = @host@
|
host_triplet = @host@
|
||||||
@ENABLE_CXX_TRUE@am__append_1 = \
|
@ENABLE_CXX_TRUE@am__append_1 = \
|
||||||
@ENABLE_CXX_TRUE@ Mmgr.hpp StdMmgr.hpp HeapMmgr.hpp Mmged.hpp SharedPtr.hpp \
|
@ENABLE_CXX_TRUE@ Mmgr.hpp StdMmgr.hpp HeapMmgr.hpp Mmged.hpp \
|
||||||
|
@ENABLE_CXX_TRUE@ ScopedPtr.hpp SharedPtr.hpp \
|
||||||
@ENABLE_CXX_TRUE@ Mpool.hpp Association.hpp LinkedList.hpp HashList.hpp HashTable.hpp \
|
@ENABLE_CXX_TRUE@ Mpool.hpp Association.hpp LinkedList.hpp HashList.hpp HashTable.hpp \
|
||||||
@ENABLE_CXX_TRUE@ RedBlackTree.hpp RedBlackTable.hpp \
|
@ENABLE_CXX_TRUE@ RedBlackTree.hpp RedBlackTable.hpp \
|
||||||
@ENABLE_CXX_TRUE@ Array.hpp BinaryHeap.hpp
|
@ENABLE_CXX_TRUE@ Array.hpp BinaryHeap.hpp
|
||||||
@ -93,9 +94,9 @@ am__pkginclude_HEADERS_DIST = alg.h chr.h cp949.h cp950.h dir.h dll.h \
|
|||||||
nwio.h oht.h opt.h path.h pio.h pma.h rbt.h rex.h sck.h sio.h \
|
nwio.h oht.h opt.h path.h pio.h pma.h rbt.h rex.h sck.h sio.h \
|
||||||
sll.h slmb.h str.h task.h time.h tio.h tmr.h tre.h uni.h uri.h \
|
sll.h slmb.h str.h task.h time.h tio.h tmr.h tre.h uni.h uri.h \
|
||||||
utf8.h xma.h Mmgr.hpp StdMmgr.hpp HeapMmgr.hpp Mmged.hpp \
|
utf8.h xma.h Mmgr.hpp StdMmgr.hpp HeapMmgr.hpp Mmged.hpp \
|
||||||
SharedPtr.hpp Mpool.hpp Association.hpp LinkedList.hpp \
|
ScopedPtr.hpp SharedPtr.hpp Mpool.hpp Association.hpp \
|
||||||
HashList.hpp HashTable.hpp RedBlackTree.hpp RedBlackTable.hpp \
|
LinkedList.hpp HashList.hpp HashTable.hpp RedBlackTree.hpp \
|
||||||
Array.hpp BinaryHeap.hpp
|
RedBlackTable.hpp Array.hpp BinaryHeap.hpp
|
||||||
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
|
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
|
||||||
am__vpath_adj = case $$p in \
|
am__vpath_adj = case $$p in \
|
||||||
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
|
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
|
||||||
|
@ -46,10 +46,19 @@ public:
|
|||||||
///
|
///
|
||||||
/// The getMmgr() function returns the memory manager associated.
|
/// The getMmgr() function returns the memory manager associated.
|
||||||
///
|
///
|
||||||
Mmgr* getMmgr () const { return this->mmgr; }
|
Mmgr* getMmgr () const { return this->_mmgr; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Mmgr* mmgr;
|
///
|
||||||
|
/// The setMmgr() function changes the memory manager.
|
||||||
|
/// Changing memory manager requires extra care to be taken
|
||||||
|
/// especially when you have some data allocated with the previous
|
||||||
|
/// manager. for this reason, i put this as a protected function.
|
||||||
|
///
|
||||||
|
void setMmgr(Mmgr* mmgr);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Mmgr* _mmgr;
|
||||||
};
|
};
|
||||||
|
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
|
@ -193,24 +193,4 @@ void* operator new[] (qse_size_t size, QSE::Mmgr* mmgr);
|
|||||||
void operator delete[] (void* ptr, QSE::Mmgr* mmgr);
|
void operator delete[] (void* ptr, QSE::Mmgr* mmgr);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////
|
|
||||||
QSE_BEGIN_NAMESPACE(QSE)
|
|
||||||
/////////////////////////////////
|
|
||||||
|
|
||||||
// Customized deleter for ScopedPtr
|
|
||||||
template <typename T>
|
|
||||||
struct ScopedPtrMmgrDeleter
|
|
||||||
{
|
|
||||||
void operator() (T* ptr, void* arg)
|
|
||||||
{
|
|
||||||
ptr->~T ();
|
|
||||||
::operator delete (ptr, (QSE::Mmgr*)arg);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/////////////////////////////////
|
|
||||||
QSE_END_NAMESPACE(QSE)
|
|
||||||
/////////////////////////////////
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -91,12 +91,17 @@ public:
|
|||||||
typedef typename PairTree::ConstIterator ConstIterator;
|
typedef typename PairTree::ConstIterator ConstIterator;
|
||||||
|
|
||||||
|
|
||||||
RedBlackTable (Mmgr* mmgr = QSE_NULL, qse_size_t mpb_size = 0):
|
RedBlackTable (qse_size_t mpb_size = 0):
|
||||||
Mmged(mmgr), pair_tree (mmgr, mpb_size)
|
Mmged(QSE_NULL), pair_tree(QSE_NULL, mpb_size)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
RedBlackTable (const SelfType& table): Mmged (table), pair_tree (table.pair_tree)
|
RedBlackTable (Mmgr* mmgr, qse_size_t mpb_size = 0):
|
||||||
|
Mmged(mmgr), pair_tree(mmgr, mpb_size)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
RedBlackTable (const SelfType& table): Mmged(table), pair_tree(table.pair_tree)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,10 +319,8 @@ public:
|
|||||||
|
|
||||||
typedef RedBlackTreeComparator<T> DefaultComparator;
|
typedef RedBlackTreeComparator<T> DefaultComparator;
|
||||||
|
|
||||||
RedBlackTree (Mmgr* mmgr = QSE_NULL, qse_size_t mpb_size = 0):
|
private:
|
||||||
Mmged (mmgr),
|
void init_tree (qse_size_t mpb_size)
|
||||||
mp (mmgr, QSE_SIZEOF(Node), mpb_size),
|
|
||||||
node_count (0)
|
|
||||||
{
|
{
|
||||||
#if defined(QSE_REDBLACKTREE_ALLOCATE_NIL)
|
#if defined(QSE_REDBLACKTREE_ALLOCATE_NIL)
|
||||||
// create a nil object. note it doesn't go into the memory pool.
|
// create a nil object. note it doesn't go into the memory pool.
|
||||||
@ -338,6 +336,19 @@ public:
|
|||||||
this->root = this->nil;
|
this->root = this->nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
RedBlackTree (qse_size_t mpb_size = 0):
|
||||||
|
Mmged(QSE_NULL), mp(QSE_NULL, QSE_SIZEOF(Node), mpb_size), node_count(0)
|
||||||
|
{
|
||||||
|
this->init_tree (mpb_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
RedBlackTree (Mmgr* mmgr, qse_size_t mpb_size = 0):
|
||||||
|
Mmged (mmgr), mp (mmgr, QSE_SIZEOF(Node), mpb_size), node_count (0)
|
||||||
|
{
|
||||||
|
this->init_tree (mpb_size);
|
||||||
|
}
|
||||||
|
|
||||||
RedBlackTree (const SelfType& rbt):
|
RedBlackTree (const SelfType& rbt):
|
||||||
Mmged (rbt.getMmgr()),
|
Mmged (rbt.getMmgr()),
|
||||||
mp (rbt.getMmgr(), rbt.mp.getDatumSize(), rbt.mp.getBlockSize()),
|
mp (rbt.getMmgr(), rbt.mp.getDatumSize(), rbt.mp.getBlockSize()),
|
||||||
|
@ -24,10 +24,11 @@
|
|||||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _QSE_SCOPEDPTR_HPP_
|
#ifndef _QSE_CMN_SCOPEDPTR_HPP_
|
||||||
#define _QSE_SCOPEDPTR_HPP_
|
#define _QSE_CMN_SCOPEDPTR_HPP_
|
||||||
|
|
||||||
#include <qse/Uncopyable.hpp>
|
#include <qse/Uncopyable.hpp>
|
||||||
|
#include <qse/cmn/Mmgr.hpp>
|
||||||
|
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
QSE_BEGIN_NAMESPACE(QSE)
|
QSE_BEGIN_NAMESPACE(QSE)
|
||||||
@ -51,6 +52,16 @@ struct ScopedPtrArrayDeleter
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct ScopedPtrMmgrDeleter
|
||||||
|
{
|
||||||
|
void operator() (T* ptr, void* arg)
|
||||||
|
{
|
||||||
|
ptr->~T ();
|
||||||
|
::operator delete (ptr, (QSE::Mmgr*)arg);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/// The ScopedPtr class is a template class that destroys the object the
|
/// The ScopedPtr class is a template class that destroys the object the
|
||||||
/// pointer points to when its destructor is called. You can use this class
|
/// pointer points to when its destructor is called. You can use this class
|
||||||
/// to free a certain resource associated to the pointer when it goes out
|
/// to free a certain resource associated to the pointer when it goes out
|
||||||
@ -58,7 +69,7 @@ struct ScopedPtrArrayDeleter
|
|||||||
///
|
///
|
||||||
/// \code
|
/// \code
|
||||||
/// #include <stdio.h>
|
/// #include <stdio.h>
|
||||||
/// #include <qse/ScopedPtr.hpp>
|
/// #include <qse/cmn/ScopedPtr.hpp>
|
||||||
/// #include <qse/cmn/HeapMmgr.hpp>
|
/// #include <qse/cmn/HeapMmgr.hpp>
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
@ -69,14 +80,6 @@ struct ScopedPtrArrayDeleter
|
|||||||
/// ~X() { printf ("X destructed\n"); }
|
/// ~X() { printf ("X destructed\n"); }
|
||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
/// struct destroy_x_in_mmgr
|
|
||||||
/// {
|
|
||||||
/// void operator() (X* x, void* arg)
|
|
||||||
/// {
|
|
||||||
/// x->~X();
|
|
||||||
/// ::operator delete (x, (QSE::Mmgr*)arg);
|
|
||||||
/// }
|
|
||||||
/// };
|
|
||||||
///
|
///
|
||||||
/// int main ()
|
/// int main ()
|
||||||
/// {
|
/// {
|
||||||
@ -85,7 +88,7 @@ struct ScopedPtrArrayDeleter
|
|||||||
/// {
|
/// {
|
||||||
/// QSE::ScopedPtr<X> x1 (new X);
|
/// QSE::ScopedPtr<X> x1 (new X);
|
||||||
/// QSE::ScopedPtr<X,QSE::ScopedPtrArrayDeleter<X> > x3 (new X[10]);
|
/// QSE::ScopedPtr<X,QSE::ScopedPtrArrayDeleter<X> > x3 (new X[10]);
|
||||||
/// QSE::ScopedPtr<X,destroy_x_in_mmgr> x2 (new(&heap_mmgr) X, &heap_mmgr);
|
/// QSE::ScopedPtr<X,QSE::ScopedPtrMmgrDeleter<X> > x2 (new(&heap_mmgr) X, &heap_mmgr);
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// return 0;
|
/// return 0;
|
||||||
@ -97,7 +100,7 @@ template<typename T, typename DELETER = ScopedPtrDeleter<T> >
|
|||||||
class QSE_EXPORT ScopedPtr: public Uncopyable
|
class QSE_EXPORT ScopedPtr: public Uncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef SharedPtr<T,DELETER> SelfType;
|
typedef ScopedPtr<T,DELETER> SelfType;
|
||||||
|
|
||||||
typedef ScopedPtrDeleter<T> DefaultDeleter;
|
typedef ScopedPtrDeleter<T> DefaultDeleter;
|
||||||
|
|
@ -119,7 +119,7 @@ public:
|
|||||||
|
|
||||||
// must copy the memory manager pointer as the item
|
// must copy the memory manager pointer as the item
|
||||||
// to be copied is allocated using the memory manager of sp.
|
// to be copied is allocated using the memory manager of sp.
|
||||||
this->mmgr = sp.getMmgr();
|
this->setMmgr (sp.getMmgr());
|
||||||
|
|
||||||
this->item = sp.item;
|
this->item = sp.item;
|
||||||
this->item->ref++;
|
this->item->ref++;
|
||||||
|
@ -33,8 +33,15 @@ QSE_BEGIN_NAMESPACE(QSE)
|
|||||||
Mmged::Mmged (Mmgr* mmgr)
|
Mmged::Mmged (Mmgr* mmgr)
|
||||||
{
|
{
|
||||||
if (!mmgr) mmgr = Mmgr::getDFL();
|
if (!mmgr) mmgr = Mmgr::getDFL();
|
||||||
this->mmgr = mmgr;
|
this->_mmgr = mmgr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Mmged::setMmgr (Mmgr* mmgr)
|
||||||
|
{
|
||||||
|
if (!mmgr) mmgr = Mmgr::getDFL();
|
||||||
|
this->_mmgr = mmgr;
|
||||||
|
}
|
||||||
|
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
QSE_END_NAMESPACE(QSE)
|
QSE_END_NAMESPACE(QSE)
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
|
@ -87,7 +87,7 @@ void Mpool::dispose ()
|
|||||||
Block* next = block->next;
|
Block* next = block->next;
|
||||||
|
|
||||||
//::delete[] (qse_uint8_t*)block;
|
//::delete[] (qse_uint8_t*)block;
|
||||||
this->mmgr->dispose ((qse_uint8_t*)block);
|
this->getMmgr()->dispose ((qse_uint8_t*)block);
|
||||||
|
|
||||||
block = next;
|
block = next;
|
||||||
}
|
}
|
||||||
@ -107,7 +107,7 @@ Mpool::Block* Mpool::add_block ()
|
|||||||
|
|
||||||
//Block* block = (Block*)::new qse_uint8_t[
|
//Block* block = (Block*)::new qse_uint8_t[
|
||||||
// QSE_SIZEOF(Block) + this->block_size * this->datum_size];
|
// QSE_SIZEOF(Block) + this->block_size * this->datum_size];
|
||||||
Block* block = (Block*)this->mmgr->allocate (QSE_SIZEOF(Block) + this->block_size * this->datum_size);
|
Block* block = (Block*)this->getMmgr()->allocate (QSE_SIZEOF(Block) + this->block_size * this->datum_size);
|
||||||
if (!block) return QSE_NULL; // this line may not be reached if the allocator raises an exception
|
if (!block) return QSE_NULL; // this line may not be reached if the allocator raises an exception
|
||||||
|
|
||||||
//this->free_list = (Chain*)block->data;
|
//this->free_list = (Chain*)block->data;
|
||||||
|
@ -35,7 +35,7 @@ QSE_BEGIN_NAMESPACE(QSE)
|
|||||||
|
|
||||||
int Sed::open ()
|
int Sed::open ()
|
||||||
{
|
{
|
||||||
sed = qse_sed_open (this->mmgr, QSE_SIZEOF(Sed*));
|
sed = qse_sed_open (this->getMmgr(), QSE_SIZEOF(Sed*));
|
||||||
if (!sed) return -1;
|
if (!sed) return -1;
|
||||||
*(Sed**)QSE_XTN(sed) = this;
|
*(Sed**)QSE_XTN(sed) = this;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user