Commits

Anonymous committed 5d110fc

parallel modify

  • Participants
  • Parent commits a5de784

Comments (0)

Files changed (23)

File sal/inc/osl/interlck2.h

+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org.  If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _OSL_INTERLOCK_H_
+#define _OSL_INTERLOCK_H_
+
+#include <sal/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef sal_Int32 oslInterlockedCount;
+
+/** Increments the count variable addressed by pCount. 
+	@param Address of counter variable
+	@return The result of the operation is zero, the value of the count variable.
+*/
+oslInterlockedCount SAL_CALL _osl_incrementInterlockedCount_(oslInterlockedCount* pCount);
+
+/** Decrement the count variable addressed by pCount. 
+	@param Address of counter variable
+	@return The result of the operation is the new value is of the count variable.
+*/
+oslInterlockedCount SAL_CALL _osl_decrementInterlockedCount_(oslInterlockedCount* pCount);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif	/* _OSL_INTERLOCK_H_ */
+
+

File sal/inc/osl/mutex_parallel.h

+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: mutex_parallel.h,v $
+ * $Revision: 1.9 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org.  If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _mutex_parallel_h_
+#define _mutex_parallel_h_
+
+#include <osl/mutex.h>
+#include <sal/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+sal_Bool SAL_CALL osl_registerParallel(const sal_uInt32 parentThreadId);
+sal_Bool SAL_CALL osl_unRegisterParallel(const sal_uInt32 parentThreadId);
+
+sal_Bool SAL_CALL osl_isParallel();
+void SAL_CALL osl_enterStructSection();
+void SAL_CALL osl_leaveStructSection();
+
+oslMutex* SAL_CALL osl_getParallelMutex(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#define OSL_ISPARALLEL() osl_isParallel()
+
+#define OSL_ENTER_PARALLEL_MUTEX()	osl_acquireMutex(*osl_getParallelMutex())
+#define OSL_LEAVE_PARALLEL_MUTEX()	osl_releaseMutex(*osl_getParallelMutex())
+
+#endif	/* _mutex_parallel_h_ */

File sal/inc/osl/mutex_parallel.hxx

+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: mutex_parallel.hxx,v $
+ * $Revision: 1.14 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org.  If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _OSL_MUTEX_PARALLEL_HXX_
+#define _OSL_MUTEX_PARALLEL_HXX_
+
+#include <osl/mutex.hxx>
+#include <osl/mutex_parallel.h>
+
+#ifdef __cplusplus
+namespace osl
+{  
+	static Mutex * GetParallelMutex()
+	{
+			return (Mutex *)osl_getParallelMutex();
+	}
+	
+	class StructGuard
+	{
+	private:
+		StructGuard(StructGuard &);
+        void operator =(StructGuard &);
+	public:
+		StructGuard()
+		{ osl_enterStructSection();	}
+		~StructGuard()
+		{ osl_leaveStructSection();	}
+	};
+}	
+#define PARALLEL_GUARD() \
+		osl::MutexGuard	_parallelGuard_(osl::GetParallelMutex())
+		
+#define PARALLEL_CLEARABLE_GUARD() \
+		osl::ClearableMutexGuard _parallelClearableGuard_(osl::GetParallelMutex())
+
+#define PARALLEL_RESETTABLE_GUARD() \
+		osl::ResettableMutexGuard _parallelResettableGuard_(osl::GetParallelMutex())
+
+#define STRUCT_GUARD() \
+		osl::StructGuard _structGuard
+		
+#endif  /* __cplusplus */
+#endif	/* _OSL_MUTEX_HXX_ */

File sal/inc/osl/mutex_weak.h

+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: mutex_parallel.h,v $
+ * $Revision: 1.9 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org.  If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _mutex_weak_h_
+#define _mutex_weak_h_
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void SAL_CALL osl_enterWeakSection();
+void SAL_CALL osl_leaveWeakSection();
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif	/* _mutex_weak_h_ */

File sal/osl/w32/mutex_parallel.cxx

+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: mutex_parallel.c,v $
+ * $Revision: 1.6 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org.  If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#include "system.h"
+#include "mutex_win.h"
+#include <sal/types.h>
+#include <osl/mutex_parallel.h>
+/*****************************************************************************/
+/* mutex_win.h */
+/*****************************************************************************/
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct _oslMutexImpl {
+	CRITICAL_SECTION	m_Mutex;
+	int 				m_Locks;
+	DWORD				m_Owner;
+	DWORD				m_Requests;
+} oslMutexImpl;
+
+static BOOL (WINAPI *lpfTryEnterCriticalSection)(LPCRITICAL_SECTION)
+	= (BOOL (WINAPI *)(LPCRITICAL_SECTION))0xFFFFFFFF;
+
+static CRITICAL_SECTION MutexLock;
+static CRITICAL_SECTION ParallelMutexLock;
+static CRITICAL_SECTION MemoryMutexLock;
+static CRITICAL_SECTION CountMutexLock;
+static CRITICAL_SECTION StructMutexLock;
+static CRITICAL_SECTION WeakMutexLock;
+
+void SAL_CALL osl_enterParallelSection()
+{
+	EnterCriticalSection(&ParallelMutexLock);
+}
+void SAL_CALL osl_leaveParallelSection()
+{
+	LeaveCriticalSection(&ParallelMutexLock);
+}
+
+void SAL_CALL osl_enterMemorySection()
+{
+	EnterCriticalSection(&MemoryMutexLock);
+}
+void SAL_CALL osl_leaveMemorySection()
+{
+	LeaveCriticalSection(&MemoryMutexLock);
+}
+
+void osl_enterCountCritical()
+{
+	EnterCriticalSection(&CountMutexLock);
+}
+void osl_leaveCountCritical()
+{
+	LeaveCriticalSection(&CountMutexLock);
+}
+
+void SAL_CALL osl_enterStructSection()
+{
+	EnterCriticalSection(&StructMutexLock);
+}
+void SAL_CALL osl_leaveStructSection()
+{
+	LeaveCriticalSection(&StructMutexLock);
+}
+
+void SAL_CALL osl_enterWeakSection()
+{
+	EnterCriticalSection(&WeakMutexLock);
+}
+void SAL_CALL osl_leaveWeakSection()
+{
+	LeaveCriticalSection(&WeakMutexLock);
+}
+/*****************************************************************************/
+/* _osl_createMutex_  this method be used for g_Mutex and g_ParallelMutex */
+/*****************************************************************************/
+oslMutex SAL_CALL _osl_createMutex_(void)
+{
+	oslMutexImpl *pMutexImpl;
+	/* Window 95 does not support "TryEnterCriticalSection" */
+
+	if (lpfTryEnterCriticalSection ==
+				(BOOL (WINAPI *)(LPCRITICAL_SECTION))0xFFFFFFFF)
+	{
+		OSVERSIONINFO VersionInformation = 
+		{
+			sizeof(OSVERSIONINFO),
+			0, 
+	    	0, 
+	    	0,
+	    	0, 
+	    	"",
+		};
+		/* ts: Window 98 does not support "TryEnterCriticalSection" but export the symbol !!!
+		   calls to that symbol always returns FALSE */
+		if (
+			GetVersionEx(&VersionInformation) &&
+			(VersionInformation.dwPlatformId == VER_PLATFORM_WIN32_NT)
+		   )
+		{
+			lpfTryEnterCriticalSection = (BOOL (WINAPI *)(LPCRITICAL_SECTION))
+					GetProcAddress(GetModuleHandle("KERNEL32"),
+								   "TryEnterCriticalSection");
+		}
+		else
+		{
+			lpfTryEnterCriticalSection = (BOOL (WINAPI *)(LPCRITICAL_SECTION))NULL;
+		}
+		InitializeCriticalSection(&MutexLock);
+		InitializeCriticalSection(&ParallelMutexLock);
+		InitializeCriticalSection(&MemoryMutexLock);
+		InitializeCriticalSection(&CountMutexLock);
+		InitializeCriticalSection(&StructMutexLock);
+		InitializeCriticalSection(&WeakMutexLock);
+	}
+
+	pMutexImpl= (oslMutexImpl*)calloc(sizeof(oslMutexImpl), 1);
+
+	OSL_ASSERT(pMutexImpl); /* alloc successful? */
+
+	InitializeCriticalSection(&pMutexImpl->m_Mutex);
+
+	return (oslMutex)pMutexImpl;
+}
+/*****************************************************************************/
+/* _osl_destroyMutex_ this method be used for g_Mutex and g_ParallelMutex */
+/*****************************************************************************/
+void SAL_CALL _osl_destroyMutex_(oslMutex Mutex)
+{
+	oslMutexImpl *pMutexImpl = (oslMutexImpl *)Mutex;
+
+	if (pMutexImpl)
+	{
+		DeleteCriticalSection(&pMutexImpl->m_Mutex);
+		free(pMutexImpl);
+	}
+}
+
+/*****************************************************************************/
+/* _osl_acquireMutex_ */
+/*****************************************************************************/
+sal_Bool SAL_CALL _osl_acquireMutex_(oslMutexImpl *pMutexImpl)
+{	 
+	OSL_ASSERT(pMutexImpl);
+
+	if (lpfTryEnterCriticalSection == NULL)
+	{
+		EnterCriticalSection(&MutexLock);
+		pMutexImpl->m_Requests++;
+		LeaveCriticalSection(&MutexLock);
+
+		EnterCriticalSection(&pMutexImpl->m_Mutex);
+
+		EnterCriticalSection(&MutexLock);
+		pMutexImpl->m_Requests--;
+		if (pMutexImpl->m_Locks++ == 0)
+			pMutexImpl->m_Owner = GetCurrentThreadId();
+		LeaveCriticalSection(&MutexLock);
+	}
+	else
+		EnterCriticalSection(&pMutexImpl->m_Mutex);
+
+	return sal_True;
+}
+
+/*****************************************************************************/
+/* _osl_tryToAcquireMutex_ */
+/*****************************************************************************/
+sal_Bool SAL_CALL _osl_tryToAcquireMutex_(oslMutexImpl *pMutexImpl)
+{
+	sal_Bool 	 ret = sal_False;
+
+	OSL_ASSERT(pMutexImpl);
+
+	if (lpfTryEnterCriticalSection != NULL)
+		return (sal_Bool)(lpfTryEnterCriticalSection(&pMutexImpl->m_Mutex) != FALSE);
+	else
+	{
+		EnterCriticalSection(&MutexLock);
+
+		if ( ((pMutexImpl->m_Requests == 0) && (pMutexImpl->m_Locks == 0)) ||
+			 (pMutexImpl->m_Owner == GetCurrentThreadId()) )
+			ret = _osl_acquireMutex_(pMutexImpl);
+
+		LeaveCriticalSection(&MutexLock);
+	}
+
+	return ret;
+}
+
+/*****************************************************************************/
+/* _osl_releaseMutex_ */
+/*****************************************************************************/
+sal_Bool SAL_CALL _osl_releaseMutex_(oslMutexImpl *pMutexImpl)
+{
+	
+	if( NULL == pMutexImpl )
+	{
+		OSL_ASSERT(pMutexImpl);
+	}
+	if (lpfTryEnterCriticalSection == NULL)
+	{
+		EnterCriticalSection(&MutexLock);
+
+		if (--(pMutexImpl->m_Locks) == 0)
+			pMutexImpl->m_Owner = 0;
+
+		LeaveCriticalSection(&MutexLock);
+	}
+
+	LeaveCriticalSection(&pMutexImpl->m_Mutex);
+
+	return sal_True;
+}
+
+/*****************************************************************************/
+/* mutex_parallel.h */
+/*****************************************************************************/
+
+#define PARALLEL_COUNT 10
+
+static sal_uInt32 ParallelThread[PARALLEL_COUNT];
+void _initParallelThread_()
+{
+	sal_uInt32 i = 0;
+	for(; i < PARALLEL_COUNT ; i ++ )
+	{
+		ParallelThread[i] = 0;
+	}
+}
+/* osl_isParallel */
+sal_Bool SAL_CALL osl_isParallel()
+{
+	sal_Bool bParallel = sal_False;
+	osl_enterParallelSection();
+	sal_uInt32 id = GetCurrentThreadId();
+	int i = 0;
+	while(i < PARALLEL_COUNT &&  ParallelThread[i] )
+	{
+		if( id == ParallelThread[i] )
+		{	
+			bParallel = sal_True;
+			break;
+		}
+		i ++;
+	}
+	osl_leaveParallelSection();	
+	return bParallel;
+}
+/* osl_registerParallel */
+sal_Bool SAL_CALL osl_registerParallel
+(const sal_uInt32 /*parentThreadId*/)
+{
+	osl_enterParallelSection();	
+	sal_Bool _bRegisted = sal_False;
+	sal_uInt32 _threadId = GetCurrentThreadId();
+	int i = 0;
+	while(i < PARALLEL_COUNT &&  ParallelThread[i] )
+	{
+		if( ParallelThread[i] == _threadId )
+		{	
+			_bRegisted = sal_True;
+			break;
+		}
+		i ++;
+	}	
+	OSL_ASSERT( i < PARALLEL_COUNT );
+	if( !_bRegisted && i < PARALLEL_COUNT )
+	{
+		ParallelThread[i] = _threadId;
+		_bRegisted = sal_True;
+	}else
+	{
+		_bRegisted = sal_False;	
+	}
+	osl_leaveParallelSection();
+	return _bRegisted;
+}
+/* osl_unRegisterParallel */
+sal_Bool SAL_CALL osl_unRegisterParallel
+(const sal_uInt32 /*parentThreadId*/)
+{
+	osl_enterParallelSection();
+	sal_Bool _unRegisted = sal_False;
+	sal_uInt32 _threadId = GetCurrentThreadId();
+	int i = 0;
+	while(i < PARALLEL_COUNT &&  ParallelThread[i] )
+	{
+		if( ParallelThread[i] == _threadId )
+		{	
+			_unRegisted = sal_True;
+			break;
+		}
+		i ++;
+	}	
+	OSL_ASSERT( i < PARALLEL_COUNT );
+	if( _unRegisted && i < PARALLEL_COUNT )
+	{
+		while(i < PARALLEL_COUNT )
+		{	
+			if( i+1 < PARALLEL_COUNT )
+				ParallelThread[i] = ParallelThread[i+1];
+			else
+				ParallelThread[i] = 0;
+				
+			if( ++i == PARALLEL_COUNT || !ParallelThread[i])
+				break;
+		}
+	}	
+	osl_leaveParallelSection();
+	return sal_True;
+}
+
+
+/* initialized in dllentry.c */
+oslMutex g_ParallelMutex;
+
+oslMutex * SAL_CALL osl_getParallelMutex(void)
+{
+	return &g_ParallelMutex;
+}
+#ifdef __cplusplus
+}
+#endif

File sal/osl/w32/mutex_win.h

+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: mutex_win.h,v $
+ * $Revision: 1.6 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org.  If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _MUTEX_WIN_H__
+#define _MUTEX_WIN_H__
+
+#include <osl/mutex.h>
+#include <osl/diagnose.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+	Implementation notes:
+	The void* hidden by oslMutex points to a WIN32
+	CRITICAL_SECTION structure.
+*/
+typedef struct _oslMutexImpl oslMutexImpl;
+
+oslMutex SAL_CALL _osl_createMutex_(void);
+
+void SAL_CALL _osl_destroyMutex_(oslMutex Mutex);
+
+sal_Bool SAL_CALL _osl_acquireMutex_(oslMutexImpl *pMutexImpl);
+
+sal_Bool SAL_CALL _osl_tryToAcquireMutex_(oslMutexImpl *pMutexImpl);
+
+sal_Bool SAL_CALL _osl_releaseMutex_(oslMutexImpl *pMutexImpl);
+
+void SAL_CALL _initParallelThread_();
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif

File svl/inc/cntnrsrt_critical.hxx

+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: cntnrsrt_critical.hxx,v $
+ * $Revision: 1.5 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org.  If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _CNTRSRT_CRITICAL_HXX
+#define _CNTRSRT_CRITICAL_HXX
+
+#if 0
+***********************************************************************
+*
+*	Hier folgt die Beschreibung fuer die exportierten Makros:
+*
+*		DECLARE_CONTAINER_SORT( ClassName, Type )
+*		IMPL_CONTAINER_SORT( ClassName, Type, SortFunc )
+*
+*		Definiert eine von ContainerCritical abgeleitete Klasse "ClassName",
+*		in der die Elemente des Typs "Type" sortiert enthalten sind.
+*		Dazu muss einer Funktion "SortFunc" definiert sein, die als
+*		Paramter zwei "const Type&" erwartet und 0 zurueckgibt, wenn
+*		beide gleich sind, -1 wenn der erste Paramter kleiner ist als
+* 		der zweite und +1 wenn der erste Paramter groesser ist als
+*		der zweite.
+*
+*		Die Zugriffs-Methoden entsprechen in etwa denen der ContainerCritical-
+*		Klasse, mit Ausnahme von Insert, DeleteAndDestroy und Seek_Entry,
+*		der den SV-Pointer-Arrays entsprechen.
+*
+*		DECLARE_CONTAINER_SORT_DEL( ClassName, Type )
+*		IMPL_CONTAINER_SORT( ClassName, Type, SortFunc )
+*
+*		Wie DECLARE_CONTAINER_SORT, nur dass beim Aufruf des Destruktors
+*		alle im Conatiner vorhandenen Objekte geloescht werden.
+*
+#endif
+
+#include <tools/contnr_critical.hxx>
+
+template<class nm, class Type>
+BOOL Critical_Insert(nm* pN, Type* pObj)
+{
+	BOOL result = false;
+	{STRUCT_GUARD();
+	
+		result = pN->_insert_(pObj);
+	}
+	return result;
+}
+template<class nm, class Type>
+Type* Critical_Remove(nm* pN, ULONG nPos )
+{
+	Type* pResult = NULL;
+	{STRUCT_GUARD();
+	
+		pResult = pN->_remove_(nPos);
+	}
+	return pResult;
+}
+template<class nm, class Type>
+Type* Critical_Remove(nm* pN, Type* pObj )
+{
+	Type* pResult = NULL;
+	{STRUCT_GUARD();
+	
+		pResult = pN->_remove_(pObj);
+	}
+	return pResult;
+};
+template<class nm>
+void DeleteAndDestroy_Critical(nm* pM, ULONG nPos)
+{
+	{STRUCT_GUARD();
+	
+		pM->_deleteAndDestroy_(nPos);
+	}
+};
+template<class nm>
+void DeleteAndDestroy_Critical(nm* pM)
+{
+	{STRUCT_GUARD();
+	
+		pM->_deleteAndDestroy_();
+	}
+};
+template<class nm, class Type>
+Type* Critical_GetObject(const nm* pM, ULONG nPos)
+{
+	Type* pResult = NULL;
+	{STRUCT_GUARD();
+	
+		pResult = pM->_getObject_(nPos);
+	}
+	return pResult;
+}
+template<class nm, class Type>
+BOOL Critical_Seek_Entry(const nm* pM, const Type* pT, ULONG nPos)
+{
+	BOOL result = false;
+	{STRUCT_GUARD();
+	
+		result = pN->_seek_Entry_(pT, nPos);
+	}
+	return result;
+}
+template<class nm, class Type>
+ULONG Critical_GetPos(const nm* pM, const Type* pObj )
+{ 
+	ULONG result = 0;
+	{STRUCT_GUARD();
+	
+		result = pM->_getPos_(pObj);
+	}
+	return result;
+}
+
+
+#define DECLARE_CONTAINER_SORT_COMMON_CRITICAL( ClassName, Type )			\
+	ClassName( const ClassName& );											\
+    ClassName& operator =( const ClassName& );								\
+public:                                       								\
+	using ContainerCritical::Count;                    						\
+																			\
+	ClassName( USHORT  InitSize, USHORT  ReSize ) :							\
+		ContainerCritical( CONTAINER_MAXBLOCKSIZE, InitSize, ReSize )	{}	\
+																			\
+    BOOL Insert( Type* pObj ){	return 	Critical_Insert(this, pObj);	}	\
+    BOOL _insert_( Type* pObj );											\
+							   												\	
+	Type*Remove( ULONG nPos ) 												\
+		{ return Critical_Remove(this, nPos ); }							\
+	Type* _remove_( ULONG nPos ) 											\
+		{ return (Type *)ContainerCritical::_remove_( nPos ); }				\
+																			\
+	Type *Remove( Type* pObj ){ return Critical_Remove(this, pObj ); }		\
+	Type *_remove_( Type* pObj );											\
+							   												\
+	void DeleteAndDestroy( ULONG nPos )	{ Critical_DeleteAndDestroy(this, nPos ); }\
+	void _deleteAndDestroy_( ULONG nPos )									\
+	{                                  										\
+		Type *pObj = _remove_( nPos );   									\
+		if( pObj )                     										\
+			delete pObj;               										\
+	}                                  										\
+							   												\
+	void DeleteAndDestroy( ){ Critical_DeleteAndDestroy(this); }			\
+	void _deleteAndDestroy_()												\
+		{ while( Count() ) _deleteAndDestroy_( 0 ); }						\
+																			\
+    Type* GetObject( ULONG nPos ) const{ return Critical_GetObject(this, nPos ); }\
+    Type* _getObject_( ULONG nPos ) const									\
+		{ return (Type *)ContainerCritical::_getObject_( nPos ); }			\
+																			\
+	Type* operator[]( ULONG nPos ) const 									\
+		{ return GetObject(nPos); }											\
+																			\
+	BOOL Seek_Entry( const Type *pObj, ULONG* pPos ) const 					\
+		{ return Critical_Seek_Entry(this, pObj, pPos);		}				\
+	BOOL _seek_Entry_( const Type *pObj, ULONG* pPos ) const;				\
+																			\
+	ULONG GetPos( const Type* pObj ) const;									\
+		{ return Critical_GetPos(this, pObj);		}						\
+	ULONG _getPos_( const Type* pObj ) const;								\
+
+
+#define DECLARE_CONTAINER_SORT_CRITICAL( ClassName, Type )							\
+class ClassName : private ContainerCritical											\
+{																			\
+	DECLARE_CONTAINER_SORT_COMMON_CRITICAL( ClassName, Type )						\
+	~ClassName() {} 														\
+};																			\
+
+
+#define DECLARE_CONTAINER_SORT_DEL_CRITICAL( ClassName, Type )							\
+class ClassName : private ContainerCritical											\
+{																			\
+	DECLARE_CONTAINER_SORT_COMMON_CRITICAL( ClassName, Type )							\
+	~ClassName() { DeleteAndDestroy(); }									\
+};																			\
+
+
+#define IMPL_CONTAINER_SORT_CRITICAL( ClassName, Type, SortFunc )					\
+BOOL ClassName::_insert_( Type *pObj )                                        \
+{                                                                           \
+	ULONG nPos;                                                             \
+	BOOL bExist = _seek_Entry_( pObj, &nPos );                                \
+	if( !bExist )                                                           \
+		ContainerCritical::_insert_( pObj, nPos );                                    \
+	return !bExist;                                                         \
+}                                                                           \
+																			\
+Type *ClassName::_remove_( Type* pObj )                                       \
+{                                                                           \
+	ULONG nPos;                                                             \
+	if( _seek_Entry_( pObj, &nPos ) )                                         \
+		return _remove_( nPos );                                              \
+	else                                                                    \
+		return 0;                                                           \
+}                                                                           \
+																			\
+ULONG ClassName::_getPos_( const Type* pObj ) const                           \
+{                                                                           \
+	ULONG nPos;                                                             \
+	if( _seek_Entry_( pObj, &nPos ) )                                         \
+		return nPos;                                                        \
+	else                                                                    \
+		return CONTAINER_ENTRY_NOTFOUND;                                    \
+}                                                                           \
+																			\
+BOOL ClassName::_seek_Entry_( const Type* pObj, ULONG* pPos ) const           \
+{                                                                           \
+	register ULONG nO  = _count_(),                                           \
+			nM,                                                             \
+			nU = 0;                                                         \
+	if( nO > 0 )                                                            \
+	{                                                                       \
+		nO--;                                                               \
+		while( nU <= nO )                                                   \
+		{                                                                   \
+			nM = nU + ( nO - nU ) / 2;                                      \
+			int nCmp = SortFunc( *_getObject_(nM), *pObj );				    \
+																			\
+			if( 0 == nCmp )                              					\
+			{                                                               \
+				if( pPos ) *pPos = nM;                                      \
+				return TRUE;                                                \
+			}                                                               \
+			else if( nCmp < 0 )                       						\
+				nU = nM + 1;                                                \
+			else if( nM == 0 )                                              \
+			{                                                               \
+				if( pPos ) *pPos = nU;                                      \
+				return FALSE;                                               \
+			}                                                               \
+			else                                                            \
+				nO = nM - 1;                                                \
+		}                                                                   \
+	}                                                                       \
+	if( pPos ) *pPos = nU;                                                  \
+	return FALSE;                                                           \
+}                                                                           \
+
+#endif

File svl/inc/svl/svarray2.hxx

+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: svarray.hxx,v $
+ * $Revision: 1.4 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org.  If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _SVARRAY2_HXX
+#define _SVARRAY2_HXX
+
+#if 0
+***********************************************************************
+*
+*	Hier folgt die Beschreibung fuer die exportierten Makros:
+*
+*		SV_DECL_VARARR_CRITICAL(nm, AE, IS, GS)
+*		SV_IMPL_VARARR_CRITICAL( nm, AE )
+*			definiere/implementiere ein Array das einfache Objecte
+*			enthaelt. (Sie werden im Speicher verschoben, koennen also
+*			z.B. keine String sein)
+*
+*		SV_DECL_OBJARR_CRITICAL(nm, AE, IS, GS)
+*		SV_IMPL_OBJARR_CRITICAL( nm, AE )
+*			definiere/implementiere ein Array das Objecte enthaelt.
+*			(Hier koennen es auch Strings sein)
+*
+*
+*		SV_DECL_PTRARR_CRITICAL(nm, AE, IS, GS)
+*		SV_IMPL_PTRARR_CRITICAL(nm, AE)
+*			definiere/implementiere ein Array das Pointer haelt. Diese
+*			werden von aussen angelegt und zerstoert. Das IMPL-Makro
+*			wird nur benoetigt, wenn die DeleteAndDestroy Methode genutzt
+*			wird, diese loescht dann die Pointer und ruft deren Destruktoren
+*
+*		SV_DECL_PTRARR_DEL_CRITICAL(nm, AE, IS, GS)
+*		SV_IMPL_PTRARR_CRITICAL(nm, AE)
+*			definiere/implementiere ein Array das Pointer haelt. Diese
+*			werden von aussen angelegt und im Destructor zerstoert.
+*
+*
+*		SV_DECL_PTRARR_SORT_CRITICAL(nm, AE, IS, GS)
+*		SV_IMPL_PTRARR_SORT_CRITICAL( nm,AE )
+*			defieniere/implementiere ein Sort-Array mit Pointern, das nach
+*			Pointern sortiert ist. Basiert auf einem PTRARR
+*
+*		SV_DECL_PTRARR_SORT_DEL_CRITICAL(nm, AE, IS, GS)
+*		SV_IMPL_PTRARR_SORT_CRITICAL( nm,AE )
+*			defieniere/implementiere ein Sort-Array mit Pointern, das nach
+*			Pointern sortiert ist. Basiert auf einem PTRARR_DEL
+*
+*		SV_DECL_PTRARR_SORT_CRITICAL(nm, AE, IS, GS)
+*		SV_IMPL_OP_PTRARR_SORT_CRITICAL( nm,AE )
+*			defieniere/implementiere ein Sort-Array mit Pointern, das nach
+*			Objecten sortiert ist. Basiert auf einem PTRARR.
+*			Sortierung mit Hilfe der Object-operatoren "<" und "=="
+*
+*		SV_DECL_PTRARR_SORT_DEL_CRITICAL(nm, AE, IS, GS)
+*		SV_IMPL_OP_PTRARR_SORT_CRITICAL( nm,AE )
+*			defieniere/implementiere ein Sort-Array mit Pointern, das nach
+*			Objecten sortiert ist. Basiert auf einem PTRARR_DEL.
+*			Sortierung mit Hilfe der Object-operatoren "<" und "=="
+*
+*		SV_DECL_VARARR_SORT_CRITICAL(nm, AE, IS, GS)
+*		SV_IMPL_VARARR_SORT_CRITICAL( nm,AE )
+*			defieniere/implementiere ein Sort-Array mit einfachen Objecten.
+*			Basiert auf einem VARARR.
+*			Sortierung mit Hilfe der Object-operatoren "<" und "=="
+*
+* JP 23.12.94 neu:
+*		SV_DECL_PTRARR_STACK_CRITICAL(nm, AE, IS, GS)
+*			ein Stack mit einem PtrArray als Grundlage.
+*
+* JP 09.10.96:  vordefinierte Arrays:
+*	VarArr:		SvBools, SvULongs, SvUShorts, SvLongs, SvShorts
+*	PtrArr:		SvStrings, SvStringsDtor
+*	SortArr:	SvStringsSort, SvStringsSortDtor,
+*				SvStringsISort, SvStringsISortDtor
+***********************************************************************
+#endif
+
+#include "svl/svldllapi.h"
+#include <svl/svarry2_critical.hxx>
+
+#ifndef INCLUDED_STRING_H
+#include <string.h> 	// memmove()
+#define INCLUDED_STRING_H
+#endif
+
+#ifndef INCLUDED_LIMITS_H
+#include <limits.h> 	// USHRT_MAX
+#define INCLUDED_LIMITS_H
+#endif
+#include <rtl/alloc.h>
+#include <tools/solar.h>
+
+class String;
+
+#ifndef CONCAT
+#define CONCAT(x,y) x##y
+#endif
+
+class DummyType2;
+inline void* operator new( size_t, DummyType2* pPtr )
+{
+	return pPtr;
+}
+inline void operator delete( void*, DummyType2* ) {}
+
+#if defined(PRODUCT)
+
+#define _SVVARARR_DEF_GET_OP_INLINE_CRITICAL( nm, ArrElem ) \
+ArrElem& operator[](USHORT nP) const { return *(pData+nP); }\
+\
+void _insert_( const nm * pI, USHORT nP,\
+			 USHORT nS = 0, USHORT nE = USHRT_MAX )\
+{\
+	if( USHRT_MAX == nE ) \
+		nE = pI->nA; \
+	if( nS < nE ) \
+		_insert_( (const ArrElem*)pI->pData+nS, (USHORT)nE-nS, nP );\
+}\
+\
+void Insert( const nm * pI, USHORT nP,\
+			 USHORT nS = 0, USHORT nE = USHRT_MAX )\
+{\
+	Critical_Insert(this, pI, nP, nS, nE);	\
+}	\
+
+
+#define _SVVARARR_IMPL_GET_OP_INLINE_CRITICAL( nm, ArrElem )
+
+#else
+
+#define _SVVARARR_DEF_GET_OP_INLINE_CRITICAL( nm,ArrElem )\
+ArrElem& operator[](USHORT nP) const;\
+void _insert_( const nm * pI, USHORT nP,\
+			 USHORT nS = 0, USHORT nE = USHRT_MAX );	\
+void Insert( const nm *pI, USHORT nP,\
+				USHORT nS = 0, USHORT nE = USHRT_MAX )\
+{\
+	Critical_Insert(this, pI, nP, nS, nE);	\
+}	\
+
+#define _SVVARARR_IMPL_GET_OP_INLINE_CRITICAL( nm, ArrElem )\
+ArrElem& nm::operator[](USHORT nP) const\
+{\
+	DBG_ASSERT( pData && nP < nA,"Op[]");\
+	return *(pData+nP);\
+}\
+void nm::_insert_( const nm *pI, USHORT nP, USHORT nStt, USHORT nE)\
+{\
+	DBG_ASSERT(nP<=nA,"Ins,Ar[Start.End]");\
+	if( USHRT_MAX == nE ) \
+		nE = pI->nA; \
+	if( nStt < nE ) \
+		_insert_( (const ArrElem*)pI->pData+nStt, (USHORT)nE-nStt, nP );\
+}
+
+#endif
+
+#define _SV_DECL_VARARR_GEN_CRITICAL(nm, AE, IS, GS, AERef, vis )\
+typedef BOOL (*FnForEach_##nm)( const AERef, void* );\
+class vis nm\
+{\
+protected:\
+	AE    *pData;\
+	USHORT nFree;\
+	USHORT nA;\
+\
+	void _resize(size_t n);\
+\
+public:\
+	nm( USHORT= IS, BYTE= GS );\
+	~nm() { rtl_freeMemory( pData ); }\
+\
+	_SVVARARR_DEF_GET_OP_INLINE_CRITICAL(nm, AE )\
+	AE* _getObject_(USHORT nP) const{	return (pData+nP);	}	\
+	AERef GetObject(USHORT nP) const {	return *((AE*)Critical_GetObject(this, nP));  } \
+\
+	void _insert_( const AERef aE, USHORT nP );	\
+	void Insert( const AERef aE, USHORT nP ){	Critical_Insert(this, aE, nP);  }\
+	void _insert_( const AE *pE, USHORT nL, USHORT nP );\
+	void Insert( const AE *pE, USHORT nL, USHORT nP ){	Critical_Insert(this, pE, nL, nP);  }\
+	void _remove_( USHORT nP, USHORT nL = 1 );\
+	void Remove( USHORT nP, USHORT nL = 1 ){	Critical_Remove(this, nP, nL);  }\
+	void _replace_( const AERef aE, USHORT nP );\
+	void Replace( const AERef aE, USHORT nP ){	Critical_Replace(this, aE, nP);  }\
+	void _replace_( const AE *pE, USHORT nL, USHORT nP );\
+	void Replace( const AE *pE, USHORT nL, USHORT nP ){	Critical_Replace(this, pE, nL, nP);  }\
+	USHORT _count_() const { return nA; }	\
+	USHORT Count() const { return Critical_Count(this); }\
+	const AE* _getData_() const { return (const AE*)pData; }\
+	const AE* GetData() const { return (const AE*)Critical_GetData(this); }\
+\
+	void _forEach_1(void*  fnForEach, void* pArgs = 0 )\
+	{\
+		_forEach_( (CONCAT( FnForEach_, nm ))fnForEach, pArgs );\
+	}\
+	void _forEach_( CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
+	{\
+		_forEach_( 0, nA, fnForEach, pArgs );\
+	}\
+	void ForEach( CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
+	{\
+		Critical_ForEach(this, (void*)fnForEach, pArgs );\
+	}\
+	void _forEach_1( USHORT nS, USHORT nE, \
+					 void* fnForEach, void* pArgs = 0 )\
+	{\
+		_forEach_( nS, nE, (CONCAT( FnForEach_, nm ))fnForEach, pArgs );\
+	}\
+	void ForEach( USHORT nS, USHORT nE, \
+					CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
+	{\
+		Critical_ForEach( this, nS, nE, fnForEach, pArgs );\
+	}\
+	void _forEach_( USHORT nStt, USHORT nE, \
+			CONCAT( FnForEach_, nm ) fnCall, void* pArgs = 0 );\
+	void _ForEach( USHORT nStt, USHORT nE, \
+			CONCAT( FnForEach_, nm ) fnCall, void* pArgs = 0 )\
+	{	\
+		Critical_ForEach(this, nStt, nE, (void*)fnCall, pArgs);	\
+	}	\
+\
+
+#define _SV_DECL_VARARR_CRITICAL(nm, AE, IS, GS ) \
+_SV_DECL_VARARR_GEN_CRITICAL(nm, AE, IS, GS, AE & )
+#define _SV_DECL_VARARR_PLAIN_CRITICAL(nm, AE, IS, GS ) \
+_SV_DECL_VARARR_GEN_CRITICAL(nm, AE, IS, GS, AE )
+
+#define SV_DECL_VARARR_GEN_CRITICAL(nm, AE, IS, GS, AERef, vis )\
+_SV_DECL_VARARR_GEN_CRITICAL(nm, AE, IS, GS, AERef, vis )\
+private:\
+nm( const nm& );\
+nm& operator=( const nm& );\
+};
+
+#define SV_DECL_VARARR_CRITICAL(nm, AE, IS, GS ) \
+SV_DECL_VARARR_GEN_CRITICAL(nm, AE, IS, GS, AE &, )
+#define SV_DECL_VARARR_PLAIN_CRITICAL(nm, AE, IS, GS ) \
+SV_DECL_VARARR_GEN_CRITICAL(nm, AE, IS, GS, AE, )
+
+#define SV_DECL_VARARR_VISIBILITY_CRITICAL(nm, AE, IS, GS, vis ) \
+SV_DECL_VARARR_GEN_CRITICAL(nm, AE, IS, GS, AE &, vis )
+
+#define SV_DECL_VARARR_PLAIN_VISIBILITY_CRITICAL(nm, AE, IS, GS, vis ) \
+SV_DECL_VARARR_GEN_CRITICAL(nm, AE, IS, GS, AE, vis )
+
+#define SV_IMPL_VARARR_GEN_CRITICAL( nm, AE, AERef )\
+nm::nm( USHORT nInit, BYTE )\
+	: pData (0),\
+	  nFree (nInit),\
+	  nA    (0)\
+{\
+	if( nInit )\
+	{\
+		pData = (AE*)(rtl_allocateMemory(sizeof(AE) * nInit));\
+		DBG_ASSERT( pData, "CTOR, allocate");\
+	}\
+}\
+\
+void nm::_resize (size_t n)\
+{\
+	USHORT nL = ((n < USHRT_MAX) ? USHORT(n) : USHRT_MAX);\
+	AE* pE = (AE*)(rtl_reallocateMemory (pData, sizeof(AE) * nL));\
+	if ((pE != 0) || (nL == 0))\
+	{\
+		pData = pE;\
+		nFree = nL - nA;\
+	}\
+}\
+\
+void nm::_insert_( const AERef aE, USHORT nP )\
+{\
+	DBG_ASSERT(nP <= nA && nA < USHRT_MAX, "Ins 1");\
+	if (nFree < 1)\
+		_resize (nA + ((nA > 1) ? nA : 1));\
+	if( pData && nP < nA )\
+		memmove( pData+nP+1, pData+nP, (nA-nP) * sizeof( AE ));\
+	*(pData+nP) = (AE&)aE;\
+	++nA; --nFree;\
+}\
+\
+void nm::_insert_( const AE* pE, USHORT nL, USHORT nP )\
+{\
+	DBG_ASSERT(nP<=nA && ((long)nA+nL)<USHRT_MAX,"Ins n");\
+	if (nFree < nL)\
+		_resize (nA + ((nA > nL) ? nA : nL));\
+	if( pData && nP < nA )\
+		memmove( pData+nP+nL, pData+nP, (nA-nP) * sizeof( AE ));\
+	if( pE )\
+		memcpy( pData+nP, pE, nL * sizeof( AE ));\
+	nA = nA + nL; nFree = nFree - nL;\
+}\
+\
+void nm::_replace_( const AERef aE, USHORT nP )\
+{\
+	if( nP < nA )\
+		*(pData+nP) = (AE&)aE;\
+}\
+\
+void nm::_replace_( const AE *pE, USHORT nL, USHORT nP )\
+{\
+	if( pE && nP < nA )\
+	{\
+		if( nP + nL < nA )\
+			memcpy( pData + nP, pE, nL * sizeof( AE ));\
+		else if( nP + nL < nA + nFree )\
+		{\
+			memcpy( pData + nP, pE, nL * sizeof( AE ));\
+            nP = nP + (nL - nA); \
+            nFree = nP;\
+		}\
+		else \
+		{\
+			USHORT nTmpLen = nA + nFree - nP; \
+			memcpy( pData + nP, pE, nTmpLen * sizeof( AE ));\
+			nA = nA + nFree; \
+			nFree = 0; \
+			_insert_( pE + nTmpLen, nL - nTmpLen, nA );\
+		}\
+	}\
+}\
+\
+void nm::_remove_( USHORT nP, USHORT nL )\
+{\
+	if( !nL )\
+		return;\
+	DBG_ASSERT( nP < nA && nP + nL <= nA,"Del");\
+	if( pData && nP+1 < nA )\
+		memmove( pData+nP, pData+nP+nL, (nA-nP-nL) * sizeof( AE ));\
+	nA = nA - nL; nFree = nFree + nL;\
+	if (nFree > nA)\
+		_resize (nA);\
+}\
+\
+void nm::_forEach_( USHORT nStt, USHORT nE, \
+			CONCAT( FnForEach_, nm ) fnCall, void* pArgs )\
+{\
+	if( nStt >= nE || nE > nA )\
+		return;\
+	for( ; nStt < nE && (*fnCall)( *(const AE*)(pData+nStt), pArgs ); nStt++)\
+		;\
+}\
+\
+_SVVARARR_IMPL_GET_OP_INLINE_CRITICAL(nm, AE )\
+
+#define SV_IMPL_VARARR_CRITICAL( nm, AE ) \
+SV_IMPL_VARARR_GEN_CRITICAL( nm, AE, AE & )
+#define SV_IMPL_VARARR_PLAIN_CRITICAL( nm, AE ) \
+SV_IMPL_VARARR_GEN_CRITICAL( nm, AE, AE )
+
+#if defined(PRODUCT)
+
+#define _SVOBJARR_DEF_GET_OP_INLINE_CRITICAL( nm,ArrElem )\
+ArrElem& operator[](USHORT nP) const { return *(pData+nP); }\
+\
+void _insert_( const nm * pI, USHORT nP,\
+			 USHORT nS = 0, USHORT nE = USHRT_MAX )\
+{\
+	if( USHRT_MAX == nE ) \
+		nE = pI->nA; \
+	if( nS < nE ) \
+		_insert_( (const ArrElem*)pI->pData+nS, (USHORT)nE-nS, nP );\
+}\
+\
+void Insert( const nm * pI, USHORT nP,\
+			 USHORT nS = 0, USHORT nE = USHRT_MAX )\
+{\
+	Critical_Insert(this, pI, nP, nS, nE);	\
+}	\
+
+#define _SVOBJARR_IMPL_GET_OP_INLINE_CRITICAL( nm, ArrElem )
+
+#else
+
+#define _SVOBJARR_DEF_GET_OP_INLINE_CRITICAL( nm,ArrElem ) \
+ArrElem& operator[](USHORT nP) const;\
+void _insert_( const nm * pI, USHORT nP,\
+			 USHORT nS = 0, USHORT nE = USHRT_MAX ); \
+void Insert( const nm *pI, USHORT nP,\
+				USHORT nS = 0, USHORT nE = USHRT_MAX )\
+{\
+	Critical_Insert(this, pI, nP, nS, nE);	\
+}	\
+
+#define _SVOBJARR_IMPL_GET_OP_INLINE_CRITICAL( nm, ArrElem )\
+ArrElem& nm::operator[](USHORT nP) const\
+{\
+	DBG_ASSERT( pData && nP < nA,"Op[]");\
+	return *(pData+nP);\
+}\
+void nm::Insert( const nm *pI, USHORT nP, USHORT nStt, USHORT nE )\
+{\
+	DBG_ASSERT( nP <= nA,"Ins,Ar[Start.End]");\
+	if( USHRT_MAX == nE ) \
+		nE = pI->nA; \
+	if( nStt < nE ) \
+		Insert( (const ArrElem*)pI->pData+nStt, (USHORT)nE-nStt, nP );\
+}
+
+#endif
+
+#define _SV_DECL_OBJARR_CRITICAL(nm, AE, IS, GS)\
+typedef BOOL (*FnForEach_##nm)( const AE&, void* );\
+class nm\
+{\
+protected:\
+	AE    *pData;\
+	USHORT nFree;\
+	USHORT nA;\
+\
+	void _resize(size_t n);\
+	void _destroy();\
+\
+public:\
+	nm( USHORT= IS, BYTE= GS );\
+	~nm() { _destroy(); }\
+\
+	_SVOBJARR_DEF_GET_OP_INLINE_CRITICAL(nm,AE)\
+	AE* _getObject_(USHORT nP) const{	return (pData+nP);	}	\
+	AE& GetObject(USHORT nP) const const {	return *((AE*)Critical_GetObject(this, nP));  } \
+\
+	void _insert_( const AE&aE, USHORT nP );	\
+	void Insert( const AE &aE, USHORT nP ){	Critical_Insert(this, aE, nP);  }\
+	void _insert_( const AE *pE, USHORT nL, USHORT nP );\
+	void Insert( const AE *pE, USHORT nL, USHORT nP ){	Critical_Insert(this, pE, nL, nP);  }\
+	void _remove_( USHORT nP, USHORT nL = 1 );\
+	void Remove( USHORT nP, USHORT nL = 1 ){	Critical_Remove(this, nP, nL);  }\
+	USHORT _count_() const { return nA; }	\
+	USHORT Count() const { return Critical_Count(this); }\
+	const AE* _getData_() const { return (const AE*)pData; }\
+	const AE* GetData() const { return (const AE*)Critical_GetData(this); }\
+\
+	void _forEach_1(void*  fnForEach, void* pArgs = 0 )\
+	{\
+		_forEach_( (CONCAT( FnForEach_, nm ))fnForEach, pArgs );\
+	}\
+	void _forEach_( CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
+	{\
+		_forEach_( 0, nA, fnForEach, pArgs );\
+	}\
+	void ForEach( CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
+	{\
+		_ForEach( 0, nA, fnForEach, pArgs );\
+	}\
+	void _forEach_1( USHORT nS, USHORT nE, \
+					 void* fnForEach, void* pArgs = 0 )\
+	{\
+		_forEach_( nS, nE, (CONCAT( FnForEach_, nm ))fnForEach, pArgs );\
+	}\
+	void ForEach( USHORT nS, USHORT nE, \
+					CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
+	{\
+		Critical_ForEach( this, nS, nE, fnForEach, pArgs );\
+	}\
+	void _forEach_( USHORT nStt, USHORT nE, \
+			CONCAT( FnForEach_, nm ) fnCall, void* pArgs = 0 );\
+\
+	void _ForEach( USHORT nStt, USHORT nE, \
+			CONCAT( FnForEach_, nm ) fnCall, void* pArgs = 0 )\
+	{	\
+		Critical_ForEach(this, nStt, nE, (void*)fnCall, pArgs);	\
+	}	\
+\
+
+#define SV_DECL_OBJARR_CRITICAL(nm, AE, IS, GS)\
+_SV_DECL_OBJARR_CRITICAL(nm, AE, IS, GS)\
+private:\
+nm( const nm& );\
+nm& operator=( const nm& );\
+};
+
+#define SV_IMPL_OBJARR_CRITICAL( nm, AE )\
+nm::nm( USHORT nInit, BYTE )\
+	: pData (0),\
+	  nFree (nInit),\
+	  nA    (0)\
+{\
+	if( nInit )\
+	{\
+		pData = (AE*)(rtl_allocateMemory(sizeof(AE) * nInit));\
+		DBG_ASSERT( pData, "CTOR, allocate");\
+	}\
+}\
+\
+void nm::_destroy()\
+{\
+	if(pData)\
+	{\
+		AE* pTmp=pData;\
+		for(USHORT n=0; n < nA; n++,pTmp++ )\
+		{\
+			pTmp->~AE();\
+		}\
+		_rtl_freeMemory_(pData);\
+		pData = 0;\
+	}\
+}\
+\
+void nm::_resize (size_t n)\
+{\
+	USHORT nL = ((n < USHRT_MAX) ? USHORT(n) : USHRT_MAX);\
+	AE* pE = (AE*)(_rtl_reallocateMemory_ (pData, sizeof(AE) * nL));\
+	if ((pE != 0) || (nL == 0))\
+	{\
+		pData = pE;\
+		nFree = nL - nA;\
+	}\
+}\
+\
+void nm::_insert_( const AE &aE, USHORT nP )\
+{\
+	DBG_ASSERT( nP <= nA && nA < USHRT_MAX,"Ins 1");\
+	if (nFree < 1)\
+		_resize (nA + ((nA > 1) ? nA : 1));\
+	if( pData && nP < nA )\
+		memmove( pData+nP+1, pData+nP, (nA-nP) * sizeof( AE ));\
+	AE* pTmp = pData+nP;\
+	new( (DummyType2*) pTmp ) AE( (AE&)aE );\
+	++nA; --nFree;\
+}\
+\
+void nm::_insert_( const AE* pE, USHORT nL, USHORT nP )\
+{\
+	DBG_ASSERT(nP<=nA && ((long)nA+nL) < USHRT_MAX, "Ins n");\
+	if (nFree < nL)\
+		_resize (nA + ((nA > nL) ? nA : nL));\
+	if( pData && nP < nA )\
+		memmove( pData+nP+nL, pData+nP, (nA-nP) * sizeof( AE ));\
+	if( pE )\
+	{\
+		AE* pTmp = pData+nP;\
+		for( USHORT n = 0; n < nL; n++, pTmp++, pE++)\
+		{\
+			 new( (DummyType2*) pTmp ) AE( (AE&)*pE );\
+		}\
+	}\
+	nA = nA + nL; nFree = nFree - nL;\
+}\
+\
+void nm::_remove_( USHORT nP, USHORT nL )\
+{\
+	if( !nL )\
+		return;\
+	DBG_ASSERT( nP < nA && nP + nL <= nA,"Del");\
+	AE* pTmp=pData+nP;\
+	USHORT nCtr = nP;\
+	for(USHORT n=0; n < nL; n++,pTmp++,nCtr++)\
+	{\
+		if( nCtr < nA )\
+			pTmp->~AE();\
+	}\
+	if( pData && nP+1 < nA )\
+		memmove( pData+nP, pData+nP+nL, (nA-nP-nL) * sizeof( AE ));\
+	nA = nA - nL; nFree = nFree + nL;\
+	if (nFree > nA) \
+		_resize (nA);\
+}\
+\
+void nm::_forEach_( USHORT nStt, USHORT nE, \
+			CONCAT( FnForEach_, nm ) fnCall, void* pArgs )\
+{\
+	if( nStt >= nE || nE > nA )\
+		return;\
+	for( ; nStt < nE && (*fnCall)( *(pData+nStt), pArgs ); nStt++)\
+		;\
+}\
+\
+_SVOBJARR_IMPL_GET_OP_INLINE_CRITICAL(nm, AE)\
+
+#define _SV_DECL_PTRARR_DEF_GEN_CRITICAL( nm, AE, IS, GS, AERef, vis )\
+_SV_DECL_VARARR_GEN_CRITICAL( nm, AE, IS, GS, AERef, vis)\
+USHORT _getPos_( const AERef aE ) const;\
+USHORT GetPos( const AERef aE ) const{	return Critical_GetPos(this, aE);	}\
+};
+
+#define _SV_DECL_PTRARR_DEF_CRITICAL( nm, AE, IS, GS, vis )\
+_SV_DECL_PTRARR_DEF_GEN_CRITICAL( nm, AE, IS, GS, AE &, vis )
+#define _SV_DECL_PTRARR_DEF_PLAIN_CRITICAL( nm, AE, IS, GS, vis )\
+_SV_DECL_PTRARR_DEF_GEN_CRITICAL( nm, AE, IS, GS, AE, vis )
+
+#define SV_DECL_PTRARR_GEN_CRITICAL(nm, AE, IS, GS, Base, AERef, VPRef, vis )\
+typedef BOOL (*FnForEach_##nm)( const AERef, void* );\
+class vis nm: public Base \
+{\
+public:\
+	nm( USHORT nIni=IS, BYTE nG=GS )\
+		: Base(nIni,nG) {}\
+	void _insert_( const nm *pI, USHORT nP, \
+			USHORT nS = 0, USHORT nE = USHRT_MAX ) {\
+		Base::_insert_((const Base*)pI, nP, nS, nE);\
+	}\
+	void Insert( const nm *pI, USHORT nP, \
+			USHORT nS = 0, USHORT nE = USHRT_MAX ) {\
+		Base::_insert_((const Base*)pI, nP, nS, nE);\
+	}\
+	void _insert_( const AERef aE, USHORT nP ) {\
+		Base::_insert_( (const VPRef )aE, nP );\
+	}\
+	void Insert( const AERef aE, USHORT nP ) {\
+		Base::Insert( (const VPRef )aE, nP );\
+	}\
+	void _insert_( const AE *pE, USHORT nL, USHORT nP ) {\
+		Base::_insert_( (const VoidPtr*)pE, nL, nP );\
+	}\
+	void Insert( const AE *pE, USHORT nL, USHORT nP ) {\
+		Base::Insert( (const VoidPtr*)pE, nL, nP );\
+	}\
+	void _replace_( const AERef aE, USHORT nP ) {\
+		Base::_replace_( (const VPRef)aE, nP );\
+	}\
+	void Replace( const AERef aE, USHORT nP ) {\
+		Base::Replace( (const VPRef)aE, nP );\
+	}\
+	void _replace_( const AE *pE, USHORT nL, USHORT nP ) {\
+		Base::_replace_( (const VoidPtr*)pE, nL, nP );\
+	}\
+	void Replace( const AE *pE, USHORT nL, USHORT nP ) {\
+		Base::Replace( (const VoidPtr*)pE, nL, nP );\
+	}\
+	void _remove_( USHORT nP, USHORT nL = 1) {\
+		Base::_remove_(nP,nL);\
+	}\
+	void Remove( USHORT nP, USHORT nL = 1) {\
+		Base::Remove(nP,nL);\
+	}\
+	const AE* _getData_() const {\
+		return (const AE*)Base::_getData_();\
+	}\
+	const AE* GetData() const {\
+		return (const AE*)Base::GetData();\
+	}\
+	void _forEach_( CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
+	{\
+		Base::_forEach_( (FnForEach_##Base)fnForEach, pArgs );\
+	}\
+	void ForEach( CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
+	{\
+		_ForEach( 0, nA, (FnForEach_##Base)fnForEach, pArgs );\
+	}\
+	void _forEach_( USHORT nS, USHORT nE, \
+					CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
+	{\
+		Base::_forEach_( nS, nE, (FnForEach_##Base)fnForEach, pArgs );\
+	}\
+	void ForEach( USHORT nS, USHORT nE, \
+					CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
+	{\
+		_ForEach( nS, nE, (FnForEach_##Base)fnForEach, pArgs );\
+	}\
+	AE operator[]( USHORT nP )const  { \
+		return (AE)Base::operator[](nP); }\
+	AE _getObject_(USHORT nP) const { \
+		return (AE)Base::_getObject_(nP); }\
+	AE GetObject(USHORT nP) const { \
+		return (AE)Base::GetObject(nP); }\
+	\
+	USHORT _getPos_( const AERef aE ) const { \
+		return Base::_getPos_((const VPRef)aE);\
+	}\
+	USHORT GetPos( const AERef aE ) const { \
+		return Base::GetPos((const VPRef)aE);\
+	}\
+	void _deleteAndDestroy_( USHORT nP, USHORT nL=1 );\
+	void DeleteAndDestroy( USHORT nP, USHORT nL=1 ){	Critical_DeleteAndDestroy(this, nP, nL);	}\
+private:\
+	nm( const nm& );\
+	nm& operator=( const nm& );\
+};
+
+#define SV_DECL_PTRARR_CRITICAL(nm, AE, IS, GS )\
+SV_DECL_PTRARR_GEN_CRITICAL(nm, AE, IS, GS, SvPtrarrCritical, AE &, VoidPtr &, )
+#define SV_DECL_PTRARR_PLAIN_CRITICAL(nm, AE, IS, GS )\
+SV_DECL_PTRARR_GEN_CRITICAL(nm, AE, IS, GS, SvPtrarrPlainCritical, AE, VoidPtr, )
+
+#define SV_DECL_PTRARR_VISIBILITY_CRITICAL(nm, AE, IS, GS, vis )\
+SV_DECL_PTRARR_GEN_CRITICAL(nm, AE, IS, GS, SvPtrarrCritical, AE &, VoidPtr &, vis )
+#define SV_DECL_PTRARR_PLAIN_VISIBILITY_CRITICAL(nm, AE, IS, GS, vis )\
+SV_DECL_PTRARR_GEN_CRITICAL(nm, AE, IS, GS, SvPtrarrPlainCritical, AE, VoidPtr, vis )
+
+#define SV_DECL_PTRARR_DEL_GEN_CRITICAL(nm, AE, IS, GS, Base, AERef, VPRef, vis )\
+typedef BOOL (*FnForEach_##nm)( const AERef, void* );\
+class vis nm: public Base \
+{\
+public:\
+	nm( USHORT nIni=IS, BYTE nG=GS )\
+		: Base(nIni,nG) {}\
+	~nm() { DeleteAndDestroy( 0, Count() ); }\
+	void _insert_( const nm *pI, USHORT nP, \
+			USHORT nS = 0, USHORT nE = USHRT_MAX ) {\
+		Base::_insert_((const Base*)pI, nP, nS, nE);\
+	}\
+	void Insert( const nm *pI, USHORT nP, \
+			USHORT nS = 0, USHORT nE = USHRT_MAX ) {\
+		Base::Insert((const Base*)pI, nP, nS, nE);\
+	}\
+	void _insert_( const AERef aE, USHORT nP ) {\
+		Base::_insert_((const VPRef)aE, nP );\
+	}\
+	void Insert( const AERef aE, USHORT nP ) {\
+		Base::Insert((const VPRef)aE, nP );\
+	}\
+	void _insert_( const AE *pE, USHORT nL, USHORT nP ) {\
+		Base::_insert_( (const VoidPtr *)pE, nL, nP );\
+	}\
+	void Insert( const AE *pE, USHORT nL, USHORT nP ) {\
+		Base::Insert( (const VoidPtr *)pE, nL, nP );\
+	}\
+	void _replace_( const AERef aE, USHORT nP ) {\
+		Base::_replace_( (const VPRef)aE, nP );\
+	}\
+	void Replace( const AERef aE, USHORT nP ) {\
+		Base::Replace( (const VPRef)aE, nP );\
+	}\
+	void _replace_( const AE *pE, USHORT nL, USHORT nP ) {\
+		Base::_replace_( (const VoidPtr*)pE, nL, nP );\
+	}\
+	void Replace( const AE *pE, USHORT nL, USHORT nP ) {\
+		Base::Replace( (const VoidPtr*)pE, nL, nP );\
+	}\
+	void _remove_( USHORT nP, USHORT nL = 1) {\
+		Base::_remove_(nP,nL);\
+	}\
+	void Remove( USHORT nP, USHORT nL = 1) {\
+		Base::Remove(nP,nL);\
+	}\
+	const AE* _getData_() const {\
+		return (const AE*)Base::_getData_();\
+	}\
+	const AE* GetData() const {\
+		return (const AE*)Base::GetData();\
+	}\
+	void _forEach_( CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
+	{\
+		Base::_forEach_( 0, nA, (FnForEach_##Base)fnForEach, pArgs );\
+	}\
+	void ForEach( CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
+	{\
+		_ForEach( 0, nA, (FnForEach_##Base)fnForEach, pArgs );\
+	}\
+	void _forEach_( USHORT nS, USHORT nE, \
+					CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
+	{\
+		Base::_forEach_( nS, nE, (FnForEach_##Base)fnForEach, pArgs );\
+	}\
+	void ForEach( USHORT nS, USHORT nE, \
+					CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
+	{\
+		_ForEach( nS, nE, (FnForEach_##Base)fnForEach, pArgs );\
+	}\
+	AE operator[]( USHORT nP )const  { \
+		return (AE)Base::operator[](nP); }\
+	AE _getObject_( USHORT nP )const  { \
+		return (AE)Base::_getObject_(nP); }\
+	\
+	AE GetObject( USHORT nP )const  { \
+		return (AE)Base::GetObject(nP); }\
+	\
+	USHORT _getPos_( const AERef aE ) const { \
+		return Base::_getPos_((const VPRef)aE);\
+	} \
+	USHORT GetPos( const AERef aE ) const { \
+		return Base::GetPos((const VPRef)aE);\
+	} \
+	\
+	void _deleteAndDestroy_( USHORT nP, USHORT nL=1 );\
+	void DeleteAndDestroy( USHORT nP, USHORT nL=1 ){	Critical_DeleteAndDestroy(this, nP, nL);	}\
+private:\
+	nm( const nm& );\
+	nm& operator=( const nm& );\
+};
+
+#define SV_DECL_PTRARR_DEL_CRITICAL(nm, AE, IS, GS )\
+SV_DECL_PTRARR_DEL_GEN_CRITICAL(nm, AE, IS, GS, SvPtrarrCritical, AE &, VoidPtr &, )
+#define SV_DECL_PTRARR_DEL_PLAIN_CRITICAL(nm, AE, IS, GS )\
+SV_DECL_PTRARR_DEL_GEN_CRITICAL(nm, AE, IS, GS, SvPtrarrPlainCritical, AE, VoidPtr, )
+
+#define SV_DECL_PTRARR_DEL_VISIBILITY_CRITICAL(nm, AE, IS, GS, vis )\
+SV_DECL_PTRARR_DEL_GEN_CRITICAL(nm, AE, IS, GS, SvPtrarrCritical, AE &, VoidPtr &, vis)
+#define SV_DECL_PTRARR_DEL_PLAIN_VISIBILITY_CRITICAL(nm, AE, IS, GS, vis )\
+SV_DECL_PTRARR_DEL_GEN_CRITICAL(nm, AE, IS, GS, SvPtrarrPlainCritical, AE, VoidPtr, vis)
+
+#define SV_IMPL_PTRARR_GEN_CRITICAL(nm, AE, Base)\
+void nm::_deleteAndDestroy_( USHORT nP, USHORT nL )\
+{ \
+	if( nL ) {\
+		DBG_ASSERT( nP < nA && nP + nL <= nA,"Del");\
+		for( USHORT n=nP; n < nP + nL; n++ ) \
+			delete *((AE*)pData+n); \
+		_remove_( nP, nL ); \
+	} \
+}
+
+#define SV_IMPL_PTRARR_CRITICAL(nm, AE )\
+SV_IMPL_PTRARR_GEN_CRITICAL(nm, AE, SvPtrarrCritical )
+#define SV_IMPL_PTRARR_PLAIN_CRITICAL(nm, AE )\
+SV_IMPL_PTRARR_GEN_CRITICAL(nm, AE, SvPtrarrPlainCritical )
+
+typedef void* VoidPtr;
+_SV_DECL_PTRARR_DEF_CRITICAL( SvPtrarrCritical, VoidPtr, 0, 1, SVL_DLLPUBLIC )
+_SV_DECL_PTRARR_DEF_PLAIN_CRITICAL( SvPtrarrPlainCritical, VoidPtr, 0, 1, SVL_DLLPUBLIC )
+
+// SORTARR - Begin
+
+#ifdef __MWERKS__
+#define __MWERKS__PRIVATE public
+#else
+#define __MWERKS__PRIVATE private
+#endif
+
+#define _SORT_CLASS_DEF_CRITICAL(nm, AE, IS, GS, vis)\
+typedef BOOL (*FnForEach_##nm)( const AE&, void* );\
+class vis nm : __MWERKS__PRIVATE nm##_SAR \
+{\
+public:\
+	nm(USHORT nSize = IS, BYTE nG = GS)\
+		: nm##_SAR(nSize,nG) {}\
+	void _insert_( const nm *pI, USHORT nS, USHORT nE);\
+	void Insert( const nm *pI, USHORT nS=0, USHORT nE=USHRT_MAX )\
+	{	Critical_Insert(this, pI, nS, nE);	}	\
+	\
+	BOOL _insert_( const AE& aE );\
+	BOOL Insert( const AE& aE )\
+	{	return Critical_Insert(this, aE);	}	\
+	\
+	BOOL _insert_( const AE& aE, USHORT& rP );\
+	BOOL Insert( const AE& aE, USHORT& rP )\
+	{	return Critical_Insert2(this, aE, rP);	}	\
+	\
+	void _insert_( const AE *pE, USHORT nL );\
+	void Insert( const AE *pE, USHORT nL )\
+	{	Critical_Insert(this, pE, nL);	}	\
+	\
+	void _remove_( USHORT nP, USHORT nL = 1 );\
+	void Remove( USHORT nP, USHORT nL = 1 )	\
+	{	Critical_Remove(this, nP, nL);	}	\
+	\
+	void _remove2_( const AE& aE, USHORT nL = 1 );\
+	void Remove( const AE& aE, USHORT nL = 1 )	\
+	{	Critical_Remove2(this, aE, nL);	}	\
+	\
+	USHORT _count_() const  {   return nm##_SAR::_count_();	}\
+	USHORT Count() const  {   return nm##_SAR::Count();	}\
+	const AE* _getData_() const { return (const AE*)nm##_SAR::_getData_(); }\
+	const AE* GetData() const { return (const AE*)nm##_SAR::GetData(); }\
+\
+// Das Ende stehe im DECL-Makro !!! /
+
+#define _SV_SEEK_PTR_CRITICAL(nm,AE)\
+BOOL nm::_seek_Entry_( const AE aE, USHORT* pP ) const\
+{\
+	register USHORT nO  = nm##_SAR::_count_(),\
+			nM, \
+			nU = 0;\
+	if( nO > 0 )\
+	{\
+		nO--;\
+		register long rCmp = (long)aE;\
+		while( nU <= nO )\
+		{\
+			nM = nU + ( nO - nU ) / 2;\
+			if( (long)*(pData + nM) == rCmp )\
+			{\
+				if( pP ) *pP = nM;\
+				return TRUE;\
+			}\
+			else if( (long)*(pData+ nM) < (long)aE  )\
+				nU = nM + 1;\
+			else if( nM == 0 )\
+			{\
+				if( pP ) *pP = nU;\
+				return FALSE;\
+			}\
+			else\
+				nO = nM - 1;\
+		}\
+	}\
+	if( pP ) *pP = nU;\
+	return FALSE;\
+}
+
+#define _SV_SEEK_PTR_TO_OBJECT_CRITICAL( nm,AE )\
+BOOL nm::_seek_Entry_( const AE aE, USHORT* pP ) const\
+{\
+	register USHORT nO  = nm##_SAR::_count_(),\
+			nM, \
+			nU = 0;\
+	if( nO > 0 )\
+	{\
+		nO--;\
+		while( nU <= nO )\
+		{\
+			nM = nU + ( nO - nU ) / 2;\
+			if( *(*((AE*)pData + nM)) == *(aE) )\
+			{\
+				if( pP ) *pP = nM;\
+				return TRUE;\
+			}\
+			else if( *(*((AE*)pData + nM)) < *(aE) )\
+				nU = nM + 1;\
+			else if( nM == 0 )\
+			{\
+				if( pP ) *pP = nU;\
+				return FALSE;\
+			}\
+			else\
+				nO = nM - 1;\
+		}\
+	}\
+	if( pP ) *pP = nU;\
+	return FALSE;\
+}
+
+#define _SV_SEEK_OBJECT_CRITICAL( nm,AE )\
+BOOL nm::_seek_Entry_( const AE & aE, USHORT* pP ) const\
+{\
+	register USHORT nO  = nm##_SAR::_count_(),\
+			nM, \
+			nU = 0;\
+	if( nO > 0 )\
+	{\
+		nO--;\
+		while( nU <= nO )\
+		{\
+			nM = nU + ( nO - nU ) / 2;\
+			if( *(pData + nM) == aE )\
+			{\
+				if( pP ) *pP = nM;\
+				return TRUE;\
+			}\
+			else if( *(pData + nM) < aE )\
+				nU = nM + 1;\
+			else if( nM == 0 )\
+			{\
+				if( pP ) *pP = nU;\
+				return FALSE;\
+			}\
+			else\
+				nO = nM - 1;\
+		}\
+	}\
+	if( pP ) *pP = nU;\
+	return FALSE;\
+}
+
+#define _SV_IMPL_SORTAR_ALG_CRITICAL(nm, AE)\
+void nm::_insert_( const nm * pI, USHORT nS, USHORT nE )\
+{\
+	if( USHRT_MAX == nE )\
+		nE = pI->_count_();\
+	USHORT nP;\
+	const AE * pIArr = pI->_getData_();\
+	for( ; nS < nE; ++nS )\
+	{\
+		if( ! _seek_Entry_( *(pIArr+nS), &nP) )\
+				nm##_SAR::_insert_( *(pIArr+nS), nP );\
+		if( ++nP >= _count_() )\
+		{\
+			nm##_SAR::_insert_( pI, nP, nS+1, nE );\
+			nS = nE;\
+		}\
+	}\
+}\
+\
+BOOL nm::_insert_( const AE & aE )\
+{\
+	USHORT nP;\
+	BOOL bExist;\
+    bExist = _seek_Entry_( aE, &nP );\
+	if( ! bExist )\
+		nm##_SAR::_insert_( aE, nP );\
+	return !bExist;\
+}\
+BOOL nm::_insert_( const AE & aE, USHORT& rP )\
+{\
+	BOOL bExist;\
+    bExist = _seek_Entry_( aE, &rP );\
+	if( ! bExist )\
+		nm##_SAR::_insert_( aE, rP );\
+	return !bExist;\
+}\
+void nm::_insert_( const AE* pE, USHORT nL)\
+{\
+	USHORT nP;\
+	for( USHORT n = 0; n < nL; ++n )\
+		if( ! _seek_Entry_( *(pE+n), &nP ))\
+			nm##_SAR::_insert_( *(pE+n), nP );\
+}\
+void nm::_remove_( USHORT nP, USHORT nL )\
+{\
+	if( nL )\
+		nm##_SAR::_remove_( nP, nL);\
+}\
+\
+void nm::_remove2_( const AE &aE, USHORT nL )\
+{\
+	USHORT nP;\
+	if( nL && _seek_Entry_( aE, &nP ) )   \
+		nm##_SAR::_remove_( nP, nL);\
+}\
+
+#if defined(TCPP)
+
+#define _SORTARR_BLC_CASTS_CRITICAL(nm, AE )\
+	BOOL _insert_(  AE &aE ) {\
+		return _insert_( (const AE&)aE );\
+	}\
+	BOOL Insert(  AE &aE ) {\
+		return Insert( (const AE&)aE );\
+	}\
+	USHORT _getPos_( AE& aE ) const { \
+		return SvPtrarrCritical::_getPos_((const VoidPtr&)aE);\
+	}\
+	USHORT GetPos( AE& aE ) const { \
+		return SvPtrarrCritical::GetPos((const VoidPtr&)aE);\
+	}\
+	void _remove2_( AE& aE, USHORT nL = 1 ) { \
+		_remove2_( (const AE&) aE, nL	);\
+	}\
+	void Remove( AE& aE, USHORT nL = 1 ) { \
+		Remove( (const AE&) aE, nL	);\
+	}
+
+#else
+
+#define _SORTARR_BLC_CASTS_CRITICAL(nm, AE )\
+	USHORT _getPos_( const AE& aE ) const { \
+		return SvPtrarrCritical::_getPos_((const VoidPtr&)aE);\
+	}\
+	USHORT GetPos( const AE& aE ) const { \
+		return SvPtrarrCritical::GetPos((const VoidPtr&)aE);\
+	}
+
+#endif
+
+#define _SV_DECL_PTRARR_SORT_ALG_CRITICAL(nm, AE, IS, GS, vis)\
+SV_DECL_PTRARR_VISIBILITY_CRITICAL(nm##_SAR, AE, IS, GS, vis)\
+_SORT_CLASS_DEF_CRITICAL(nm, AE, IS, GS, vis)\
+	AE operator[](USHORT nP) const {\
+		return nm##_SAR::operator[]( nP );\
+	}\
+	AE GetObject(USHORT nP) const {\
+		return nm##_SAR::GetObject( nP );\
+	}\
+	BOOL _seek_Entry_( const AE aE, USHORT* pP = 0 ) const;	\
+	BOOL Seek_Entry( const AE aE, USHORT* pP = 0 ) const\
+	{	return Critical_Seek_Entry(this, aE, pP);	}	\
+	void ForEach( CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
+	{\
+		_ForEach( 0, nA, (FnForEach_SvPtrarrCritical)fnForEach, pArgs );\
+	}\
+	void ForEach( USHORT nS, USHORT nE, \
+					CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
+	{\
+		_ForEach( nS, nE, (FnForEach_SvPtrarrCritical)fnForEach, pArgs );\
+	}\
+	void _deleteAndDestroy_( USHORT nP, USHORT nL=1 );	\
+	void DeleteAndDestroy( USHORT nP, USHORT nL=1 ) 	\
+	{	Critical_DeleteAndDestroy(this, nP, nL);	}	\
+	_SORTARR_BLC_CASTS_CRITICAL(nm, AE )\
+\
+// Das Ende stehe im DECL-Makro !!! /
+
+#define _SV_DECL_PTRARR_SORT_CRITICAL(nm, AE, IS, GS, vis)\
+_SV_DECL_PTRARR_SORT_ALG_CRITICAL(nm, AE, IS, GS, vis)\
+private:\
+	nm( const nm& );\
+	nm& operator=( const nm& );\
+};
+
+#define SV_DECL_PTRARR_SORT_CRITICAL(nm, AE, IS, GS)\
+_SV_DECL_PTRARR_SORT_CRITICAL(nm, AE, IS, GS, )
+
+#define SV_DECL_PTRARR_SORT_VISIBILITY_CRITICAL(nm, AE, IS, GS, vis)\
+_SV_DECL_PTRARR_SORT_CRITICAL(nm, AE, IS, GS, vis)
+                                                                                                                             
+
+#define _SV_DECL_PTRARR_SORT_DEL_CRITICAL(nm, AE, IS, GS, vis)\
+_SV_DECL_PTRARR_SORT_ALG_CRITICAL(nm, AE, IS, GS, vis)\
+	~nm() { DeleteAndDestroy( 0, Count() ); }\
+private:\
+	nm( const nm& );\
+	nm& operator=( const nm& );\
+};
+
+#define SV_DECL_PTRARR_SORT_DEL_CRITICAL(nm, AE, IS, GS)\
+_SV_DECL_PTRARR_SORT_DEL_CRITICAL(nm, AE, IS, GS, )
+
+#define SV_DECL_PTRARR_SORT_DEL_VISIBILITY_CRITICAL(nm, AE, IS, GS, vis)\
+_SV_DECL_PTRARR_SORT_DEL_CRITICAL(nm, AE, IS, GS, vis)
+
+#define _SV_DECL_VARARR_SORT_CRITICAL(nm, AE, IS, GS, vis)\
+SV_DECL_VARARR_VISIBILITY_CRITICAL(nm##_SAR, AE, IS, GS, vis)\
+_SORT_CLASS_DEF_CRITICAL(nm, AE, IS, GS, vis) \
+	const AE& operator[](USHORT nP) const {\
+		return nm##_SAR::operator[]( nP );\
+	}\
+	const AE& GetObject(USHORT nP) const {\
+		return nm##_SAR::GetObject( nP );\
+	}\
+	BOOL _seek_Entry_( const AE & aE, USHORT* pP = 0 ) const;\
+	BOOL Seek_Entry( const AE & aE, USHORT* pP = 0 ) const\
+	{\
+		return Critical_Seek_Entry(this, aE, pP);\
+	}\
+	void ForEach( CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
+	{\
+		_ForEach( 0, nA, (FnForEach_##nm##_SAR)fnForEach, pArgs );\
+	}\
+	void ForEach( USHORT nS, USHORT nE, \
+					CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
+	{\
+		_ForEach( nS, nE, (FnForEach_##nm##_SAR)fnForEach, pArgs );\
+	}\
+private:\
+	nm( const nm& );\
+	nm& operator=( const nm& );\
+};
+
+#define SV_DECL_VARARR_SORT_CRITICAL(nm, AE, IS, GS)\
+_SV_DECL_VARARR_SORT_CRITICAL(nm, AE, IS, GS,)
+
+#define SV_DECL_VARARR_SORT_VISIBILITY_CRITICAL(nm, AE, IS, GS, vis)\
+_SV_DECL_VARARR_SORT_CRITICAL(nm, AE, IS, GS, vis)
+
+#define SV_IMPL_PTRARR_SORT_CRITICAL( nm,AE )\
+_SV_IMPL_SORTAR_ALG_CRITICAL( nm,AE )\
+	void nm::_deleteAndDestroy_( USHORT nP, USHORT nL ) { \
+		if( nL ) {\
+			DBG_ASSERT( nP < nA && nP + nL <= nA, "ERR_VAR_DEL" );\
+			for( USHORT n=nP; n < nP + nL; n++ ) \
+				delete *((AE*)pData+n); \
+			SvPtrarrCritical::_remove_( nP, nL ); \
+		} \
+	} \
+_SV_SEEK_PTR_CRITICAL( nm, AE )
+
+//# 
+#define SV_IMPL_OP_PTRARR_SORT_CRITICAL( nm,AE )\
+SV_IMPL_PTRARR_CRITICAL(nm##_SAR, AE ) \