Remove some dead code, including objectpool & Unicode-only utf8 stuff
This commit is contained in:
parent
1fb5f332e6
commit
900fad8ca4
|
@ -12,11 +12,11 @@ libcore_a_SOURCES = \
|
||||||
displayutil.cpp error.cpp errorbucketimpl.cpp errortable.cpp \
|
displayutil.cpp error.cpp errorbucketimpl.cpp errortable.cpp \
|
||||||
errorutil.cpp fileerror.cpp fileheader.cpp fsservices.cpp \
|
errorutil.cpp fileerror.cpp fileheader.cpp fsservices.cpp \
|
||||||
growheap.cpp hashtable.cpp haval.cpp msystem.cpp ntmbs.cpp \
|
growheap.cpp hashtable.cpp haval.cpp msystem.cpp ntmbs.cpp \
|
||||||
objectpool.cpp refcountobj.cpp serializable.cpp serializer.cpp \
|
refcountobj.cpp serializable.cpp serializer.cpp \
|
||||||
serializerimpl.cpp serializerutil.cpp serstring.cpp \
|
serializerimpl.cpp serializerutil.cpp serstring.cpp \
|
||||||
srefcountobj.cpp srefcounttbl.cpp stdcore.cpp stringutil.cpp \
|
srefcountobj.cpp srefcounttbl.cpp stdcore.cpp stringutil.cpp \
|
||||||
timebomb.cpp timeconvert.cpp tw_signal.cpp twlimits.cpp twlocale.cpp \
|
timebomb.cpp timeconvert.cpp tw_signal.cpp twlimits.cpp twlocale.cpp \
|
||||||
unixexcept.cpp usernotify.cpp usernotifystdout.cpp utf8.cpp \
|
unixexcept.cpp usernotify.cpp usernotifystdout.cpp \
|
||||||
wchar16.cpp
|
wchar16.cpp
|
||||||
|
|
||||||
libcore_a_HEADERS = archive.h charutil.h cmdlineparser.h codeconvert.h \
|
libcore_a_HEADERS = archive.h charutil.h cmdlineparser.h codeconvert.h \
|
||||||
|
@ -24,12 +24,12 @@ libcore_a_HEADERS = archive.h charutil.h cmdlineparser.h codeconvert.h \
|
||||||
displayutil.h error.h errorbucket.h errorbucketimpl.h errorgeneral.h \
|
displayutil.h error.h errorbucket.h errorbucketimpl.h errorgeneral.h \
|
||||||
errortable.h errorutil.h file.h fileerror.h fileheader.h fixedfilebuf.h \
|
errortable.h errorutil.h file.h fileerror.h fileheader.h fixedfilebuf.h \
|
||||||
fsservices.h growheap.h hashtable.h haval.h md5.h msystem.h ntdbs.h \
|
fsservices.h growheap.h hashtable.h haval.h md5.h msystem.h ntdbs.h \
|
||||||
ntmbs.h objectpool.h package.h platform.h refcountobj.h resources.h \
|
ntmbs.h package.h platform.h refcountobj.h resources.h \
|
||||||
serializable.h serializer.h serializerimpl.h serializerutil.h serstring.h \
|
serializable.h serializer.h serializerimpl.h serializerutil.h serstring.h \
|
||||||
sha.h srefcountobj.h srefcounttbl.h stdcore.h stringutil.h tasktimer.h \
|
sha.h srefcountobj.h srefcounttbl.h stdcore.h stringutil.h tasktimer.h \
|
||||||
tchar.h timebomb.h timeconvert.h tw_signal.h twlimits.h twlocale.h \
|
tchar.h timebomb.h timeconvert.h tw_signal.h twlimits.h twlocale.h \
|
||||||
twstringslang.h typed.h types.h unixexcept.h unixfsservices.h upperbound.h \
|
twstringslang.h typed.h types.h unixexcept.h unixfsservices.h upperbound.h \
|
||||||
usernotify.h usernotifystdout.h utf8.h wchar16.h
|
usernotify.h usernotifystdout.h wchar16.h
|
||||||
|
|
||||||
libcore_a_LIBADD = @CORE_CRYPT_O@
|
libcore_a_LIBADD = @CORE_CRYPT_O@
|
||||||
libcore_a_DEPENDENCIES = @CORE_CRYPT_O@
|
libcore_a_DEPENDENCIES = @CORE_CRYPT_O@
|
||||||
|
|
|
@ -118,15 +118,14 @@ am_libcore_a_OBJECTS = file_unix.$(OBJEXT) unixfsservices.$(OBJEXT) \
|
||||||
errorutil.$(OBJEXT) fileerror.$(OBJEXT) fileheader.$(OBJEXT) \
|
errorutil.$(OBJEXT) fileerror.$(OBJEXT) fileheader.$(OBJEXT) \
|
||||||
fsservices.$(OBJEXT) growheap.$(OBJEXT) hashtable.$(OBJEXT) \
|
fsservices.$(OBJEXT) growheap.$(OBJEXT) hashtable.$(OBJEXT) \
|
||||||
haval.$(OBJEXT) msystem.$(OBJEXT) ntmbs.$(OBJEXT) \
|
haval.$(OBJEXT) msystem.$(OBJEXT) ntmbs.$(OBJEXT) \
|
||||||
objectpool.$(OBJEXT) refcountobj.$(OBJEXT) \
|
refcountobj.$(OBJEXT) serializable.$(OBJEXT) \
|
||||||
serializable.$(OBJEXT) serializer.$(OBJEXT) \
|
serializer.$(OBJEXT) serializerimpl.$(OBJEXT) \
|
||||||
serializerimpl.$(OBJEXT) serializerutil.$(OBJEXT) \
|
serializerutil.$(OBJEXT) serstring.$(OBJEXT) \
|
||||||
serstring.$(OBJEXT) srefcountobj.$(OBJEXT) \
|
srefcountobj.$(OBJEXT) srefcounttbl.$(OBJEXT) \
|
||||||
srefcounttbl.$(OBJEXT) stdcore.$(OBJEXT) stringutil.$(OBJEXT) \
|
stdcore.$(OBJEXT) stringutil.$(OBJEXT) timebomb.$(OBJEXT) \
|
||||||
timebomb.$(OBJEXT) timeconvert.$(OBJEXT) tw_signal.$(OBJEXT) \
|
timeconvert.$(OBJEXT) tw_signal.$(OBJEXT) twlimits.$(OBJEXT) \
|
||||||
twlimits.$(OBJEXT) twlocale.$(OBJEXT) unixexcept.$(OBJEXT) \
|
twlocale.$(OBJEXT) unixexcept.$(OBJEXT) usernotify.$(OBJEXT) \
|
||||||
usernotify.$(OBJEXT) usernotifystdout.$(OBJEXT) utf8.$(OBJEXT) \
|
usernotifystdout.$(OBJEXT) wchar16.$(OBJEXT)
|
||||||
wchar16.$(OBJEXT)
|
|
||||||
libcore_a_OBJECTS = $(am_libcore_a_OBJECTS)
|
libcore_a_OBJECTS = $(am_libcore_a_OBJECTS)
|
||||||
AM_V_P = $(am__v_P_@AM_V@)
|
AM_V_P = $(am__v_P_@AM_V@)
|
||||||
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
|
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
|
||||||
|
@ -339,11 +338,11 @@ libcore_a_SOURCES = \
|
||||||
displayutil.cpp error.cpp errorbucketimpl.cpp errortable.cpp \
|
displayutil.cpp error.cpp errorbucketimpl.cpp errortable.cpp \
|
||||||
errorutil.cpp fileerror.cpp fileheader.cpp fsservices.cpp \
|
errorutil.cpp fileerror.cpp fileheader.cpp fsservices.cpp \
|
||||||
growheap.cpp hashtable.cpp haval.cpp msystem.cpp ntmbs.cpp \
|
growheap.cpp hashtable.cpp haval.cpp msystem.cpp ntmbs.cpp \
|
||||||
objectpool.cpp refcountobj.cpp serializable.cpp serializer.cpp \
|
refcountobj.cpp serializable.cpp serializer.cpp \
|
||||||
serializerimpl.cpp serializerutil.cpp serstring.cpp \
|
serializerimpl.cpp serializerutil.cpp serstring.cpp \
|
||||||
srefcountobj.cpp srefcounttbl.cpp stdcore.cpp stringutil.cpp \
|
srefcountobj.cpp srefcounttbl.cpp stdcore.cpp stringutil.cpp \
|
||||||
timebomb.cpp timeconvert.cpp tw_signal.cpp twlimits.cpp twlocale.cpp \
|
timebomb.cpp timeconvert.cpp tw_signal.cpp twlimits.cpp twlocale.cpp \
|
||||||
unixexcept.cpp usernotify.cpp usernotifystdout.cpp utf8.cpp \
|
unixexcept.cpp usernotify.cpp usernotifystdout.cpp \
|
||||||
wchar16.cpp
|
wchar16.cpp
|
||||||
|
|
||||||
libcore_a_HEADERS = archive.h charutil.h cmdlineparser.h codeconvert.h \
|
libcore_a_HEADERS = archive.h charutil.h cmdlineparser.h codeconvert.h \
|
||||||
|
@ -351,12 +350,12 @@ libcore_a_HEADERS = archive.h charutil.h cmdlineparser.h codeconvert.h \
|
||||||
displayutil.h error.h errorbucket.h errorbucketimpl.h errorgeneral.h \
|
displayutil.h error.h errorbucket.h errorbucketimpl.h errorgeneral.h \
|
||||||
errortable.h errorutil.h file.h fileerror.h fileheader.h fixedfilebuf.h \
|
errortable.h errorutil.h file.h fileerror.h fileheader.h fixedfilebuf.h \
|
||||||
fsservices.h growheap.h hashtable.h haval.h md5.h msystem.h ntdbs.h \
|
fsservices.h growheap.h hashtable.h haval.h md5.h msystem.h ntdbs.h \
|
||||||
ntmbs.h objectpool.h package.h platform.h refcountobj.h resources.h \
|
ntmbs.h package.h platform.h refcountobj.h resources.h \
|
||||||
serializable.h serializer.h serializerimpl.h serializerutil.h serstring.h \
|
serializable.h serializer.h serializerimpl.h serializerutil.h serstring.h \
|
||||||
sha.h srefcountobj.h srefcounttbl.h stdcore.h stringutil.h tasktimer.h \
|
sha.h srefcountobj.h srefcounttbl.h stdcore.h stringutil.h tasktimer.h \
|
||||||
tchar.h timebomb.h timeconvert.h tw_signal.h twlimits.h twlocale.h \
|
tchar.h timebomb.h timeconvert.h tw_signal.h twlimits.h twlocale.h \
|
||||||
twstringslang.h typed.h types.h unixexcept.h unixfsservices.h upperbound.h \
|
twstringslang.h typed.h types.h unixexcept.h unixfsservices.h upperbound.h \
|
||||||
usernotify.h usernotifystdout.h utf8.h wchar16.h
|
usernotify.h usernotifystdout.h wchar16.h
|
||||||
|
|
||||||
libcore_a_LIBADD = @CORE_CRYPT_O@
|
libcore_a_LIBADD = @CORE_CRYPT_O@
|
||||||
libcore_a_DEPENDENCIES = @CORE_CRYPT_O@
|
libcore_a_DEPENDENCIES = @CORE_CRYPT_O@
|
||||||
|
|
|
@ -324,28 +324,5 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
// TODO: fill these out
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
// class cMMFileArchive --
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
class cMMFileArchive : public cMemMappedArchive
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
};
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
// class cNetArchive --
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
class cNetArchive : public cArchive
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1,131 +0,0 @@
|
||||||
//
|
|
||||||
// The developer of the original code and/or files is Tripwire, Inc.
|
|
||||||
// Portions created by Tripwire, Inc. are copyright (C) 2000 Tripwire,
|
|
||||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
|
||||||
// reserved.
|
|
||||||
//
|
|
||||||
// This program is free software. The contents of this file are subject
|
|
||||||
// to the terms of the GNU General Public License as published by the
|
|
||||||
// Free Software Foundation; either version 2 of the License, or (at your
|
|
||||||
// option) any later version. You may redistribute it and/or modify it
|
|
||||||
// only in compliance with the GNU General Public License.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful.
|
|
||||||
// However, this program is distributed AS-IS WITHOUT ANY
|
|
||||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
|
||||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
|
||||||
// for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
||||||
// USA.
|
|
||||||
//
|
|
||||||
// Nothing in the GNU General Public License or any other license to use
|
|
||||||
// the code or files shall permit you to use Tripwire's trademarks,
|
|
||||||
// service marks, or other intellectual property without Tripwire's
|
|
||||||
// prior written consent.
|
|
||||||
//
|
|
||||||
// If you have any questions, please contact Tripwire, Inc. at either
|
|
||||||
// info@tripwire.org or www.tripwire.org.
|
|
||||||
//
|
|
||||||
// objectpool.cpp
|
|
||||||
#include "stdcore.h"
|
|
||||||
#include "objectpool.h"
|
|
||||||
#include "debug.h"
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// cBlockLink
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
class cBlockLink
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
cBlockLink(cBlockLink* pNext) : mpNext(pNext) {}
|
|
||||||
cBlockLink* Next() { return mpNext; }
|
|
||||||
private:
|
|
||||||
cBlockLink* mpNext; // pointer to the next link, or NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// cBlockList
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
// ctor, dtor
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
cBlockList::cBlockList() :
|
|
||||||
mpBlocks(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
cBlockList::~cBlockList()
|
|
||||||
{
|
|
||||||
Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Allocate
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
void* cBlockList::Allocate(int size)
|
|
||||||
{
|
|
||||||
char* mem = new char[size + sizeof(cBlockLink)];
|
|
||||||
mpBlocks = new(mem) cBlockLink(mpBlocks);
|
|
||||||
return mem + sizeof(cBlockLink);
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Clear
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
void cBlockList::Clear()
|
|
||||||
{
|
|
||||||
while(mpBlocks)
|
|
||||||
{
|
|
||||||
cBlockLink* pLink = mpBlocks;
|
|
||||||
mpBlocks = mpBlocks->Next();
|
|
||||||
pLink->~cBlockLink();
|
|
||||||
delete [] (char*)(pLink);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// cObjectPoolBase
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
// ctor, dtor
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
cObjectPoolBase::cObjectPoolBase(int objSize, int chunkSize) :
|
|
||||||
mObjectSize(objSize),
|
|
||||||
mChunkSize(chunkSize),
|
|
||||||
mpNextFree(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
cObjectPoolBase::~cObjectPoolBase()
|
|
||||||
{
|
|
||||||
//TODO -- assert that the number of instances left are 0.
|
|
||||||
Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
// AllocNewChunk
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
void cObjectPoolBase::AllocNewChunk()
|
|
||||||
{
|
|
||||||
ASSERT(mpNextFree == 0);
|
|
||||||
|
|
||||||
int size = mObjectSize * mChunkSize;
|
|
||||||
char* pBlock = (char*)mBlockList.Allocate(size);
|
|
||||||
|
|
||||||
char* pLast = pBlock + size - mObjectSize;
|
|
||||||
for(char* pc = pBlock; pc < pLast; pc += mObjectSize)
|
|
||||||
{
|
|
||||||
((cLink*)pc)->mpNext = (cLink*)(pc + mObjectSize);
|
|
||||||
}
|
|
||||||
((cLink*)pLast)->mpNext = 0;
|
|
||||||
|
|
||||||
mpNextFree = (cLink*)pBlock;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -1,140 +0,0 @@
|
||||||
//
|
|
||||||
// The developer of the original code and/or files is Tripwire, Inc.
|
|
||||||
// Portions created by Tripwire, Inc. are copyright (C) 2000 Tripwire,
|
|
||||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
|
||||||
// reserved.
|
|
||||||
//
|
|
||||||
// This program is free software. The contents of this file are subject
|
|
||||||
// to the terms of the GNU General Public License as published by the
|
|
||||||
// Free Software Foundation; either version 2 of the License, or (at your
|
|
||||||
// option) any later version. You may redistribute it and/or modify it
|
|
||||||
// only in compliance with the GNU General Public License.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful.
|
|
||||||
// However, this program is distributed AS-IS WITHOUT ANY
|
|
||||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
|
||||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
|
||||||
// for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
||||||
// USA.
|
|
||||||
//
|
|
||||||
// Nothing in the GNU General Public License or any other license to use
|
|
||||||
// the code or files shall permit you to use Tripwire's trademarks,
|
|
||||||
// service marks, or other intellectual property without Tripwire's
|
|
||||||
// prior written consent.
|
|
||||||
//
|
|
||||||
// If you have any questions, please contact Tripwire, Inc. at either
|
|
||||||
// info@tripwire.org or www.tripwire.org.
|
|
||||||
//
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
// objectpool.h
|
|
||||||
//
|
|
||||||
// cBlockList -- a linked list of blocks of memory
|
|
||||||
// cObjectPoolBase -- a pool of equal-sized objects; constant time allocation
|
|
||||||
#ifndef __OBJECTPOOL_H
|
|
||||||
#define __OBJECTPOOL_H
|
|
||||||
|
|
||||||
class cBlockLink;
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// cBlockList
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
class cBlockList
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
cBlockList();
|
|
||||||
~cBlockList();
|
|
||||||
|
|
||||||
void* Allocate(int size);
|
|
||||||
void Clear(); // releases everything in the block list
|
|
||||||
private:
|
|
||||||
cBlockLink* mpBlocks; // linked list of blocks
|
|
||||||
};
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// cObjectPoolBase
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
class cObjectPoolBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
cObjectPoolBase(int objSize, int chunkSize);
|
|
||||||
~cObjectPoolBase();
|
|
||||||
// NOTE -- dtor is not virtual; therefore it is potentially dangerous to delete a pointer to
|
|
||||||
// this class unless you know for sure the dynamic class type has nothing to clean up.
|
|
||||||
|
|
||||||
void* Alloc ();
|
|
||||||
void Free (void* pObj);
|
|
||||||
void Clear ();
|
|
||||||
//TODO -- add IsPointerValid()
|
|
||||||
private:
|
|
||||||
void AllocNewChunk(); // get another chunk to use...
|
|
||||||
|
|
||||||
struct cLink
|
|
||||||
{
|
|
||||||
cLink* mpNext;
|
|
||||||
};
|
|
||||||
|
|
||||||
cBlockList mBlockList;
|
|
||||||
const int mObjectSize; // how big are the objects?
|
|
||||||
const int mChunkSize; // how big are the chunks we are allocating?
|
|
||||||
cLink* mpNextFree; // the next free object
|
|
||||||
//int mInstanceCount; // number of objects that are currently allocated but not freed.
|
|
||||||
};
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// cObjectPool
|
|
||||||
// Note -- this template only works for classes that are constructed with their
|
|
||||||
// default ctor; I don't know how to extend this model to work for non-default
|
|
||||||
// ctors...
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
template <class T>
|
|
||||||
class cObjectPool : public cObjectPoolBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
cObjectPool(int chunkSize) : cObjectPoolBase(sizeof(T), chunkSize) {}
|
|
||||||
|
|
||||||
T* New () { return new(cObjectPoolBase::Alloc()) T(); }
|
|
||||||
void Delete (T* pObj) { pObj->~T(); Free(pObj); }
|
|
||||||
};
|
|
||||||
|
|
||||||
//#############################################################################
|
|
||||||
// inline implementation
|
|
||||||
//#############################################################################
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Alloc
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
inline void* cObjectPoolBase::Alloc()
|
|
||||||
{
|
|
||||||
if(! mpNextFree)
|
|
||||||
AllocNewChunk();
|
|
||||||
|
|
||||||
cLink* pRtn = mpNextFree;
|
|
||||||
mpNextFree = mpNextFree->mpNext;
|
|
||||||
return pRtn;
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Free
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
inline void cObjectPoolBase::Free(void* pObj)
|
|
||||||
{
|
|
||||||
cLink* pNew = (cLink*)pObj;
|
|
||||||
pNew->mpNext = mpNextFree;
|
|
||||||
mpNextFree = pNew;
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Clear
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
inline void cObjectPoolBase::Clear()
|
|
||||||
{
|
|
||||||
mBlockList.Clear();
|
|
||||||
mpNextFree = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif //__OBJECTPOOL_H
|
|
||||||
|
|
|
@ -1,152 +0,0 @@
|
||||||
//
|
|
||||||
// The developer of the original code and/or files is Tripwire, Inc.
|
|
||||||
// Portions created by Tripwire, Inc. are copyright (C) 2000 Tripwire,
|
|
||||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
|
||||||
// reserved.
|
|
||||||
//
|
|
||||||
// This program is free software. The contents of this file are subject
|
|
||||||
// to the terms of the GNU General Public License as published by the
|
|
||||||
// Free Software Foundation; either version 2 of the License, or (at your
|
|
||||||
// option) any later version. You may redistribute it and/or modify it
|
|
||||||
// only in compliance with the GNU General Public License.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful.
|
|
||||||
// However, this program is distributed AS-IS WITHOUT ANY
|
|
||||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
|
||||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
|
||||||
// for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
||||||
// USA.
|
|
||||||
//
|
|
||||||
// Nothing in the GNU General Public License or any other license to use
|
|
||||||
// the code or files shall permit you to use Tripwire's trademarks,
|
|
||||||
// service marks, or other intellectual property without Tripwire's
|
|
||||||
// prior written consent.
|
|
||||||
//
|
|
||||||
// If you have any questions, please contact Tripwire, Inc. at either
|
|
||||||
// info@tripwire.org or www.tripwire.org.
|
|
||||||
//
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
// utf8.h
|
|
||||||
//
|
|
||||||
#include "stdcore.h"
|
|
||||||
#include "utf8.h" // Required Deps
|
|
||||||
#include "tchar.h"
|
|
||||||
//#include "integ/tss.integ.strings.h"
|
|
||||||
//#include "integ/tss.integ.strings.inl"
|
|
||||||
|
|
||||||
#ifdef _UNICODE
|
|
||||||
|
|
||||||
|
|
||||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
// CLASS UTF8: Member Definitions
|
|
||||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
|
|
||||||
// NOTES: utf8 uses "lazy evaluation" so that members are only allocated
|
|
||||||
// if they are used. However, once they are evaluated, the evaluation results
|
|
||||||
// will be saved so that values may henceforth simply be returned. This
|
|
||||||
// scheme gives the best time vs. space performance possible as the complexity
|
|
||||||
// of each operation is at most, linear.
|
|
||||||
|
|
||||||
|
|
||||||
const char* cUTF8::str() const THROW(std::bad_alloc) // UTF8: Get as Narrow UTF8
|
|
||||||
{
|
|
||||||
if ( mUTF8Str == 0 ) // If mUTF8Str is NULL mUnicodeStr can't be
|
|
||||||
mUTF8Str = cUTF8::allocate( mUnicodeStr );
|
|
||||||
|
|
||||||
return mUTF8Str;
|
|
||||||
}
|
|
||||||
|
|
||||||
const wchar_t* cUTF8::ustr() const THROW(std::bad_alloc) // UTF8: Get as UNICODE NTWCS
|
|
||||||
{
|
|
||||||
if ( mUnicodeStr == 0 )
|
|
||||||
mUnicodeStr = cUTF8::allocate( mUTF8Str ); // If mUnicodeStr is NULL mUTF8WideStr can't be
|
|
||||||
|
|
||||||
return mUnicodeStr;
|
|
||||||
}
|
|
||||||
|
|
||||||
const wchar_t* cUTF8::wstr() const THROW(std::bad_alloc) // UTF8: Get as Wide UTF8
|
|
||||||
{
|
|
||||||
if ( mUTF8WideStr == 0 )
|
|
||||||
{
|
|
||||||
size_t N = ::strlen( str() ); // WARNING: Get strlen NOT mbcslen!!!
|
|
||||||
mUTF8WideStr = new wchar_t[ N + 1 ]; // This may throw bad_alloc to client
|
|
||||||
|
|
||||||
for ( size_t n = 0; n < N; n++ ) // index ordinal, not pointer
|
|
||||||
mUTF8WideStr[n] = wchar_t( BYTE(mUTF8Str[n]) ); // WARNING: First convert to "unsigned char"
|
|
||||||
|
|
||||||
mUTF8WideStr[N] = 0; // add a final NULL
|
|
||||||
}
|
|
||||||
|
|
||||||
return mUTF8WideStr;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// UTF8: UTF8-Unicode Round-trip Conversions
|
|
||||||
|
|
||||||
wchar_t* cUTF8::allocate( const char* in ) THROW( std::bad_alloc )
|
|
||||||
{
|
|
||||||
ASSERT( in /* && TSS_IsValidString( in )*/ ); // Verify Input
|
|
||||||
|
|
||||||
size_t N = ::MultiByteToWideChar( CP_UTF8, 0, in, -1, 0, 0 );
|
|
||||||
wchar_t* out = new wchar_t[ N + 1 ]; // Allocate required size
|
|
||||||
|
|
||||||
|
|
||||||
//--Convert
|
|
||||||
|
|
||||||
out[0] = 0x00; // NOTE: Just in case we fail
|
|
||||||
#ifdef _DEBUG
|
|
||||||
//size_t nWritten =
|
|
||||||
#endif
|
|
||||||
::MultiByteToWideChar( CP_UTF8, 0, in, -1, out, N );
|
|
||||||
out[N] = 0;
|
|
||||||
|
|
||||||
#ifdef _INTEG2 // Verify Output
|
|
||||||
if ( nWritten == 0 )
|
|
||||||
{
|
|
||||||
cDebug d( "cUTF8::allocate" );
|
|
||||||
d.TraceError( "MultiByteToWideChar failed with %x\n", ::GetLastError() );
|
|
||||||
}
|
|
||||||
|
|
||||||
ASSERT( out && TSS_IsValidString( out, nWritten ) );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* cUTF8::allocate( const wchar_t* in ) THROW( std::bad_alloc )
|
|
||||||
{
|
|
||||||
ASSERT( in /*&& TSS_IsValidString( in ) */); // Verify Input
|
|
||||||
|
|
||||||
// Allocate required size
|
|
||||||
size_t N = ::WideCharToMultiByte( CP_UTF8, 0, in, -1,0,0,0,0 );
|
|
||||||
char* out = new char[ N + 1 ];
|
|
||||||
|
|
||||||
|
|
||||||
//--Convert
|
|
||||||
|
|
||||||
out[0] = 0x00; // NOTE: Just in case we fail
|
|
||||||
#ifdef _DEBUG
|
|
||||||
//size_t nWritten =
|
|
||||||
#endif
|
|
||||||
::WideCharToMultiByte( CP_UTF8, 0, in, -1, out, N, 0, 0 );
|
|
||||||
out[N] = 0;
|
|
||||||
|
|
||||||
#ifdef _INTEG2 // Verify Output
|
|
||||||
if ( nWritten == 0 )
|
|
||||||
{
|
|
||||||
cDebug d( "cUTF8::allocate" );
|
|
||||||
d.TraceError( "WideCharToMultiByte failed with %x\n", ::GetLastError() );
|
|
||||||
}
|
|
||||||
|
|
||||||
ASSERT( out /*&& TSS_IsValidString( out, nWritten ) */);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif //_UNICODE
|
|
||||||
|
|
187
src/core/utf8.h
187
src/core/utf8.h
|
@ -1,187 +0,0 @@
|
||||||
//
|
|
||||||
// The developer of the original code and/or files is Tripwire, Inc.
|
|
||||||
// Portions created by Tripwire, Inc. are copyright (C) 2000 Tripwire,
|
|
||||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
|
||||||
// reserved.
|
|
||||||
//
|
|
||||||
// This program is free software. The contents of this file are subject
|
|
||||||
// to the terms of the GNU General Public License as published by the
|
|
||||||
// Free Software Foundation; either version 2 of the License, or (at your
|
|
||||||
// option) any later version. You may redistribute it and/or modify it
|
|
||||||
// only in compliance with the GNU General Public License.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful.
|
|
||||||
// However, this program is distributed AS-IS WITHOUT ANY
|
|
||||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
|
||||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
|
||||||
// for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
||||||
// USA.
|
|
||||||
//
|
|
||||||
// Nothing in the GNU General Public License or any other license to use
|
|
||||||
// the code or files shall permit you to use Tripwire's trademarks,
|
|
||||||
// service marks, or other intellectual property without Tripwire's
|
|
||||||
// prior written consent.
|
|
||||||
//
|
|
||||||
// If you have any questions, please contact Tripwire, Inc. at either
|
|
||||||
// info@tripwire.org or www.tripwire.org.
|
|
||||||
//
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
// utf8.h
|
|
||||||
//
|
|
||||||
|
|
||||||
// UTF8 is used to map UNICODE characters to NTBS targets
|
|
||||||
// that would normally not be able to dealt with. UTF8
|
|
||||||
// ensures symetrical round-trip conversions. In other
|
|
||||||
// words an unmapable UNICODE character converted to UTF8
|
|
||||||
// will always convert back to the same UNICODE value.
|
|
||||||
//
|
|
||||||
// For more information, go to:
|
|
||||||
// mk:@MSITStore:\\SQUID\MSDN%20January%201999\MSDN\kbwindev.chm::/Source/win32sdk/q175392.htm
|
|
||||||
|
|
||||||
#ifndef __UTF8_H
|
|
||||||
#define __UTF8_H
|
|
||||||
|
|
||||||
#include <iostream> // operator<<
|
|
||||||
|
|
||||||
//#ifndef __TSS_INTEG_STRINGS_H
|
|
||||||
//#include "integ/tss.integ.strings.h" // IsValidAddress and IsValidString
|
|
||||||
//#endif
|
|
||||||
#ifndef __DEBUG_H
|
|
||||||
#include "debug.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// convenience macros
|
|
||||||
//
|
|
||||||
// use these when printing a string ( TCHAR* ) to stdout, stderr, of printf-style
|
|
||||||
// function to safely convert the string to something printable
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
#ifdef _UNICODE
|
|
||||||
# define TSS_UTF8( x ) cUTF8( x ).wstr()
|
|
||||||
#else
|
|
||||||
# define TSS_UTF8( x ) x
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _UNICODE // this class is only needed in unicode builds...
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// Entities Declared in this Module
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
class cUTF8;
|
|
||||||
|
|
||||||
std::ostream& operator<<( std::ostream&, const cUTF8& );
|
|
||||||
std::wostream& operator<<( std::wostream&, const cUTF8& );
|
|
||||||
|
|
||||||
|
|
||||||
/// Class Declaration
|
|
||||||
|
|
||||||
#ifdef _THROW_SUPPORTED
|
|
||||||
#define THROW( x ) throw( x )
|
|
||||||
#define THROW_0 throw()
|
|
||||||
#else
|
|
||||||
#define THROW( x )
|
|
||||||
#define THROW_0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//=============================================================================
|
|
||||||
// class cUTF8: Encapsulate UTF8 Encoding
|
|
||||||
//
|
|
||||||
// SYNOPSIS:
|
|
||||||
// Allows unmappable UNICODE characters to be embedded into Narrow strings
|
|
||||||
// and displayable by narrow display streams.
|
|
||||||
//
|
|
||||||
// CONSTRAINTS:
|
|
||||||
// Cannot default or copy construct or assign UTF8 instances. Each UTF8
|
|
||||||
// instance is an exclusive owner of its resources for its life-time.
|
|
||||||
// This cuts down on the amount of redundant allocation and copying that
|
|
||||||
// is required by the class.
|
|
||||||
//=============================================================================
|
|
||||||
|
|
||||||
class cUTF8
|
|
||||||
{
|
|
||||||
/// Interface.
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
cUTF8( const char* ) THROW( std::bad_alloc );
|
|
||||||
cUTF8( const wchar_t* ) THROW( std::bad_alloc );
|
|
||||||
~cUTF8();
|
|
||||||
|
|
||||||
const char* str() const THROW( std::bad_alloc ); // Narrow UTF8
|
|
||||||
const wchar_t* wstr() const THROW( std::bad_alloc ); // Wide UTF8
|
|
||||||
const wchar_t* ustr() const THROW( std::bad_alloc ); // Unicode
|
|
||||||
|
|
||||||
|
|
||||||
/// Implementation.
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
static char* allocate( const wchar_t* ) THROW( std::bad_alloc );
|
|
||||||
static wchar_t* allocate( const char* ) THROW( std::bad_alloc );
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
cUTF8( const cUTF8& ); // Disallow
|
|
||||||
cUTF8& operator=( const cUTF8& ); // Disallow
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
mutable wchar_t* mUnicodeStr; // UNICODE String
|
|
||||||
mutable char* mUTF8Str; // UTF8 Bytes String
|
|
||||||
mutable wchar_t* mUTF8WideStr; // UTF8 Wide Character String
|
|
||||||
};
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// UTF8 Inlines: Members and Global Binary Non-Member Operators
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Create from NTBS UTF8
|
|
||||||
inline cUTF8::cUTF8( const char* psz ) THROW( std::bad_alloc )
|
|
||||||
: mUnicodeStr( cUTF8::allocate( psz ) ),
|
|
||||||
mUTF8Str( 0 ),
|
|
||||||
mUTF8WideStr( 0 )
|
|
||||||
{
|
|
||||||
ASSERT( mUnicodeStr || mUTF8Str );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create from NTWCS UNICODE
|
|
||||||
inline cUTF8::cUTF8( const wchar_t* wsz ) THROW( std::bad_alloc )
|
|
||||||
: mUnicodeStr( 0 ),
|
|
||||||
mUTF8Str( cUTF8::allocate( wsz ) ),
|
|
||||||
mUTF8WideStr( 0 )
|
|
||||||
{
|
|
||||||
ASSERT( mUnicodeStr || mUTF8Str );
|
|
||||||
}
|
|
||||||
|
|
||||||
inline cUTF8::~cUTF8()
|
|
||||||
{
|
|
||||||
delete [] mUnicodeStr; // Delete UNICODE (if exists)
|
|
||||||
delete [] mUTF8Str; // Delete UTF8 (NTBS)
|
|
||||||
delete [] mUTF8WideStr; // Delete UTF8 (NTWCS)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Operators
|
|
||||||
|
|
||||||
inline std::ostream& operator<<( std::ostream& out, const cUTF8& str )
|
|
||||||
{
|
|
||||||
out << str.str();
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::wostream& operator<<( std::wostream& wout, const cUTF8& str )
|
|
||||||
{
|
|
||||||
wout << str.wstr(); // CAUTION: Don't send UNICODE string, it won't display!
|
|
||||||
return wout;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif //_UNICODE
|
|
||||||
|
|
||||||
#endif/*_TSS_UTF8_H*/
|
|
||||||
|
|
|
@ -39,8 +39,6 @@
|
||||||
//#############################################################################
|
//#############################################################################
|
||||||
// cFCONameTblNode
|
// cFCONameTblNode
|
||||||
//#############################################################################
|
//#############################################################################
|
||||||
// uncomment this to allocate fconametblnodes from a pool.
|
|
||||||
//cObjectPoolBase cFCONameTblNode::msAllocator(sizeof(cFCONameTblNode), 1000);
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
@ -46,15 +46,6 @@
|
||||||
#include "core/hashtable.h"
|
#include "core/hashtable.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// uncomment this to allocate fconametblnodes from a pool.
|
|
||||||
/*
|
|
||||||
#ifndef __OBJECTPOOL_H
|
|
||||||
#include "objectpool.h"
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
// end TODO
|
|
||||||
|
|
||||||
|
|
||||||
class cFCONameTbl_i;
|
class cFCONameTbl_i;
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -41,9 +41,6 @@
|
||||||
#include "core/error.h"
|
#include "core/error.h"
|
||||||
#include "core/errorutil.h"
|
#include "core/errorutil.h"
|
||||||
|
|
||||||
//uncomment to allocate fsobjects from a pool
|
|
||||||
//cObjectPoolBase cFSObject::msAllocator(sizeof(cFSObject), 1000);
|
|
||||||
|
|
||||||
// FCO Type information...
|
// FCO Type information...
|
||||||
IMPLEMENT_SERREFCOUNT(cFSObject, _T("FSObject"), 0, 1)
|
IMPLEMENT_SERREFCOUNT(cFSObject, _T("FSObject"), 0, 1)
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,6 @@ growheap_t.cpp \
|
||||||
hashtable_t.cpp \
|
hashtable_t.cpp \
|
||||||
hierdatabase_t.cpp \
|
hierdatabase_t.cpp \
|
||||||
keyfile_t.cpp \
|
keyfile_t.cpp \
|
||||||
objectpool_t.cpp \
|
|
||||||
platform_t.cpp \
|
platform_t.cpp \
|
||||||
policyparser_t.cpp \
|
policyparser_t.cpp \
|
||||||
refcountobj_t.cpp \
|
refcountobj_t.cpp \
|
||||||
|
|
|
@ -126,14 +126,14 @@ am_twtest_OBJECTS = archive_t.$(OBJEXT) blockfile_t.$(OBJEXT) \
|
||||||
genrespeclist_t.$(OBJEXT) genreswitcher_t.$(OBJEXT) \
|
genrespeclist_t.$(OBJEXT) genreswitcher_t.$(OBJEXT) \
|
||||||
growheap_t.$(OBJEXT) hashtable_t.$(OBJEXT) \
|
growheap_t.$(OBJEXT) hashtable_t.$(OBJEXT) \
|
||||||
hierdatabase_t.$(OBJEXT) keyfile_t.$(OBJEXT) \
|
hierdatabase_t.$(OBJEXT) keyfile_t.$(OBJEXT) \
|
||||||
objectpool_t.$(OBJEXT) platform_t.$(OBJEXT) \
|
platform_t.$(OBJEXT) policyparser_t.$(OBJEXT) \
|
||||||
policyparser_t.$(OBJEXT) refcountobj_t.$(OBJEXT) \
|
refcountobj_t.$(OBJEXT) resources_t.$(OBJEXT) \
|
||||||
resources_t.$(OBJEXT) serializer_t.$(OBJEXT) \
|
serializer_t.$(OBJEXT) serializerimpl_t.$(OBJEXT) \
|
||||||
serializerimpl_t.$(OBJEXT) signature_t.$(OBJEXT) \
|
signature_t.$(OBJEXT) srefcountobj_t.$(OBJEXT) \
|
||||||
srefcountobj_t.$(OBJEXT) stdtest.$(OBJEXT) \
|
stdtest.$(OBJEXT) stringencoder_t.$(OBJEXT) \
|
||||||
stringencoder_t.$(OBJEXT) tasktimer_t.$(OBJEXT) \
|
tasktimer_t.$(OBJEXT) tchar_t.$(OBJEXT) test.$(OBJEXT) \
|
||||||
tchar_t.$(OBJEXT) test.$(OBJEXT) textreportviewer_t.$(OBJEXT) \
|
textreportviewer_t.$(OBJEXT) twlocale_t.$(OBJEXT) \
|
||||||
twlocale_t.$(OBJEXT) twutil_t.$(OBJEXT) types_t.$(OBJEXT) \
|
twutil_t.$(OBJEXT) types_t.$(OBJEXT) \
|
||||||
unixfsservices_t.$(OBJEXT) usernotifystdout_t.$(OBJEXT) \
|
unixfsservices_t.$(OBJEXT) usernotifystdout_t.$(OBJEXT) \
|
||||||
wchar16_t.$(OBJEXT)
|
wchar16_t.$(OBJEXT)
|
||||||
twtest_OBJECTS = $(am_twtest_OBJECTS)
|
twtest_OBJECTS = $(am_twtest_OBJECTS)
|
||||||
|
@ -397,7 +397,6 @@ growheap_t.cpp \
|
||||||
hashtable_t.cpp \
|
hashtable_t.cpp \
|
||||||
hierdatabase_t.cpp \
|
hierdatabase_t.cpp \
|
||||||
keyfile_t.cpp \
|
keyfile_t.cpp \
|
||||||
objectpool_t.cpp \
|
|
||||||
platform_t.cpp \
|
platform_t.cpp \
|
||||||
policyparser_t.cpp \
|
policyparser_t.cpp \
|
||||||
refcountobj_t.cpp \
|
refcountobj_t.cpp \
|
||||||
|
|
|
@ -1,114 +0,0 @@
|
||||||
//
|
|
||||||
// The developer of the original code and/or files is Tripwire, Inc.
|
|
||||||
// Portions created by Tripwire, Inc. are copyright (C) 2000 Tripwire,
|
|
||||||
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
|
|
||||||
// reserved.
|
|
||||||
//
|
|
||||||
// This program is free software. The contents of this file are subject
|
|
||||||
// to the terms of the GNU General Public License as published by the
|
|
||||||
// Free Software Foundation; either version 2 of the License, or (at your
|
|
||||||
// option) any later version. You may redistribute it and/or modify it
|
|
||||||
// only in compliance with the GNU General Public License.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful.
|
|
||||||
// However, this program is distributed AS-IS WITHOUT ANY
|
|
||||||
// WARRANTY; INCLUDING THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
|
|
||||||
// FOR A PARTICULAR PURPOSE. Please see the GNU General Public License
|
|
||||||
// for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
||||||
// USA.
|
|
||||||
//
|
|
||||||
// Nothing in the GNU General Public License or any other license to use
|
|
||||||
// the code or files shall permit you to use Tripwire's trademarks,
|
|
||||||
// service marks, or other intellectual property without Tripwire's
|
|
||||||
// prior written consent.
|
|
||||||
//
|
|
||||||
// If you have any questions, please contact Tripwire, Inc. at either
|
|
||||||
// info@tripwire.org or www.tripwire.org.
|
|
||||||
//
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
// objectpool_t
|
|
||||||
|
|
||||||
#include "core/stdcore.h"
|
|
||||||
#include "core/objectpool.h"
|
|
||||||
#include "core/debug.h"
|
|
||||||
#include "twtest/test.h"
|
|
||||||
|
|
||||||
|
|
||||||
// this is the struct we will use for testing purposes
|
|
||||||
struct cDog
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
char c;
|
|
||||||
double d;
|
|
||||||
cDog() : i(53), c('f'), d(3.14) { cDebug d("cDog::cDog"); d.TraceDebug("Dog ctor...\n"); }
|
|
||||||
~cDog() { cDebug d("cDog::~cDog"); d.TraceDebug("Dog dtor...\n"); }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
void TestObjectPool()
|
|
||||||
{
|
|
||||||
int k, j;
|
|
||||||
cDebug d("TestObjectPool");
|
|
||||||
|
|
||||||
// first, just try the growing properties of the pool
|
|
||||||
cObjectPoolBase pool(10, 5);
|
|
||||||
d.TraceDebug("object size = 10, chunk size = 5\n");
|
|
||||||
for(k=0; k < 12; k++)
|
|
||||||
{
|
|
||||||
d.TraceDebug("Allocating...\n");
|
|
||||||
pool.Alloc();
|
|
||||||
}
|
|
||||||
d.TraceDebug("Removing everything...\n");
|
|
||||||
pool.Clear();
|
|
||||||
|
|
||||||
// test the template class
|
|
||||||
cObjectPool<cDog> dogPool(3);
|
|
||||||
std::list<cDog*> lDog;
|
|
||||||
for(j=0; j < 7; j++)
|
|
||||||
{
|
|
||||||
lDog.push_back(dogPool.New());
|
|
||||||
}
|
|
||||||
|
|
||||||
std::list<cDog*>::iterator i;
|
|
||||||
for( i = lDog.begin(); i != lDog.end(); i++)
|
|
||||||
{
|
|
||||||
d.TraceDebug("dog contents: %d %c %lf\n", (*i)->i, (*i)->c, (*i)->d);
|
|
||||||
dogPool.Delete(*i);
|
|
||||||
}
|
|
||||||
lDog.clear();
|
|
||||||
|
|
||||||
// now, do some random insertions and deletions...
|
|
||||||
std::vector<void*> vAlloced;
|
|
||||||
for(k=0; k < 1000; k++)
|
|
||||||
{
|
|
||||||
if(rand() % 3 > 0 )
|
|
||||||
{
|
|
||||||
// alloc
|
|
||||||
void* pNew = pool.Alloc();
|
|
||||||
d.TraceDebug("Allocating %p\n", pNew);
|
|
||||||
vAlloced.push_back(pNew);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// free
|
|
||||||
int randval = rand();
|
|
||||||
int vsize = vAlloced.size();
|
|
||||||
if (vsize)
|
|
||||||
{
|
|
||||||
int idx = randval % vsize;
|
|
||||||
std::vector<void*>::iterator vi = vAlloced.begin() + idx;
|
|
||||||
void* pGone = *vi;
|
|
||||||
d.TraceDebug("Removing %p\n", pGone);
|
|
||||||
pool.Free(pGone);
|
|
||||||
vAlloced.erase(vi);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
d.TraceDebug("Leaving...\n");
|
|
||||||
}
|
|
||||||
|
|
|
@ -114,7 +114,7 @@ void TestCryptoArchive();
|
||||||
void TestFCOSpecAttr();
|
void TestFCOSpecAttr();
|
||||||
void TestCmdLineParser();
|
void TestCmdLineParser();
|
||||||
void TestTaskTimer();
|
void TestTaskTimer();
|
||||||
void TestObjectPool();
|
//void TestObjectPool();
|
||||||
void TestKeyFile();
|
void TestKeyFile();
|
||||||
void TestFCOSetCached();
|
void TestFCOSetCached();
|
||||||
void TestTWUtil();
|
void TestTWUtil();
|
||||||
|
@ -188,7 +188,7 @@ static void Test(int testID)
|
||||||
//case 27: TestFSPropCalc(); break;
|
//case 27: TestFSPropCalc(); break;
|
||||||
case 28: TestFCOSpecImpl(); break;
|
case 28: TestFCOSpecImpl(); break;
|
||||||
case 29: TestHashTable(); break;
|
case 29: TestHashTable(); break;
|
||||||
case 30: TestObjectPool(); break;
|
// case 30: TestObjectPool(); break;
|
||||||
case 31: TestRefCountObj(); break;
|
case 31: TestRefCountObj(); break;
|
||||||
case 32: TestSerializerImpl(); break;
|
case 32: TestSerializerImpl(); break;
|
||||||
case 33: TestSerRefCountObj(); break;
|
case 33: TestSerRefCountObj(); break;
|
||||||
|
|
Loading…
Reference in New Issue