- C3d aggiornamento delle librerie.
This commit is contained in:
Dario Sassi
2020-09-14 16:42:31 +00:00
parent 555eae9594
commit e8f0fa2d27
332 changed files with 59308 additions and 52918 deletions
+114 -55
View File
@@ -21,25 +21,16 @@
#include <utility>
#include <algorithm>
#if defined( __BORLANDC__ )
#include <alloc.h>
#endif
#ifdef __DEBUG_MEMORY_ALLOCATE_FREE_
#include <typeinfo.h>
#endif // __DEBUG_MEMORY_ALLOCATE_FREE_
FORVARD_DECL_TEMPLATE_TYPENAME( class SArray );
FORVARD_DECL_TEMPLATE_TYPENAME( bool set_array_size ( SArray<Type> &, size_t newSize, bool clear ) );
FORVARD_DECL_TEMPLATE_TYPENAME( Type * add_n_to_array ( SArray<Type> &, size_t n ) );
FORVARD_DECL_TEMPLATE_TYPENAME( bool set_array_size ( SArray<Type> &, size_t newSize, bool clear ) );
FORVARD_DECL_TEMPLATE_TYPENAME( Type * add_n_to_array ( SArray<Type> &, size_t n ) );
FORVARD_DECL_TEMPLATE_TYPENAME( size_t find_in_array ( const SArray<Type> &, const Type & object ) );
FORVARD_DECL_TEMPLATE_TYPENAME( bool fill_array ( SArray<Type> &, size_t fillCount, const Type & fillData ) );
FORVARD_DECL_TEMPLATE_TYPENAME( bool fill_array_zero( SArray<Type> &, size_t fillCount, size_t startIndex ) );
FORVARD_DECL_TEMPLATE_TYPENAME( reader & CALL_DECLARATION operator >> ( reader & in, SArray<Type> & ref ) );
FORVARD_DECL_TEMPLATE_TYPENAME( bool fill_array ( SArray<Type> &, size_t fillCount, const Type & fillData ) );
FORVARD_DECL_TEMPLATE_TYPENAME( bool fill_array_zero( SArray<Type> &, size_t fillCount, size_t startIndex ) );
FORVARD_DECL_TEMPLATE_TYPENAME( reader & CALL_DECLARATION operator >> ( reader & in, SArray<Type> & ref ) );
FORVARD_DECL_TEMPLATE_TYPENAME( writer & CALL_DECLARATION operator << ( writer & out, const SArray<Type> & ref ) );
FORVARD_DECL_TEMPLATE_TYPENAME( reader & CALL_DECLARATION operator >> ( reader & in, SArray<Type> *& ptr ) );
FORVARD_DECL_TEMPLATE_TYPENAME( reader & CALL_DECLARATION operator >> ( reader & in, SArray<Type> *& ptr ) );
FORVARD_DECL_TEMPLATE_TYPENAME( writer & CALL_DECLARATION operator << ( writer & out, const SArray<Type> * ptr ) );
@@ -138,13 +129,13 @@ public:
bool operator == ( const SArray<Type>& w ) const; ///< \ru Оператор равенства. \en Equality operator.
/// \ru Оператор доступа по индексу. \en Access by index operator.
Type & operator []( size_t loc ) const { PRECONDITION( loc < upper ); return parr[loc]; }
Type & operator []( size_t loc ) const;
typedef int (*CompFunc)( const Type *, const Type * ); ///< \ru Шаблон функции сортировки. \en A template of sorting function.
void Sort ( CompFunc comp = CompareSArrayItems<Type> ); ///< \ru Сортировать массив. По умолчанию сортирует в порядке возрастания. \en Sort the array. Sort in ascending order by default.
const Type * GetAddr() const { return parr; } ///< \ru Выдать адрес начала массива. \en Get the address of the beginning of the array.
const Type * GetEndAddr() const { return parr + count; } ///< \ru Выдать указатель конца (следующим за крайним). \en Get a pointer of the end (which follows the last element).
const Type * GetAddr() const { return parr; } ///< \ru Выдать адрес начала массива. \en Get the address of the beginning of the array.
const Type * GetEndAddr() const { return parr + count; } ///< \ru Выдать указатель конца (следующим за крайним). \en Get a pointer of the end (which follows the last element).
/**
\name \ru Унификация с контейнерами STL.
@@ -172,16 +163,17 @@ public:
template <class Iterator>
void assign ( Iterator first, Iterator last ); ///< \ru Присвоить массиву новое содержимое, заменив его текущее содержимое. \en Assign new contents to the array, replacing its current contents.
void assign ( size_t n, const Type & val ) { resize( n, val ); } ///< \ru Присвоить массиву новое содержимое, заменив его текущее содержимое. \en Assign new contents to the array, replacing its current contents.
const Type * begin() const { return parr; } ///< \ru Получить указатель на первый элемент массива. \en Get the pointer to the first array element.
Type * begin() { return parr; } ///< \ru Получить указатель на первый элемент массива. \en Get the pointer to the first array element.
const Type * end() const { return parr + count; } ///< \ru Получить указатель на участок памяти после массива. \en Get the pointer to the piece of memory after the array.
Type * end() { return parr + count; } ///< \ru Получить указатель на участок памяти после массива. \en Get the pointer to the piece of memory after the array.
const Type * cbegin() const { return parr; } ///< \ru Получить указатель на первый элемент массива. \en Get the pointer to the first array element.
const Type * cend() const { return parr + count; } ///< \ru Получить указатель на участок памяти после массива. \en Get the pointer to the piece of memory after the array.
const Type & front() const { PRECONDITION(!empty()); return *parr; }
Type & front() { PRECONDITION(!empty()); return *parr; }
const Type & back() const { PRECONDITION(!empty()); return *(parr+count-1); }
Type & back() { PRECONDITION(!empty()); return *(parr+count-1); }
const Type * begin() const { return parr; } ///< \ru Получить указатель на первый элемент массива. \en Get the pointer to the first array element.
Type * begin() { return parr; } ///< \ru Получить указатель на первый элемент массива. \en Get the pointer to the first array element.
const Type * end() const { return parr + count; } ///< \ru Получить указатель на участок памяти после массива. \en Get the pointer to the piece of memory after the array.
Type * end() { return parr + count; } ///< \ru Получить указатель на участок памяти после массива. \en Get the pointer to the piece of memory after the array.
const Type * cbegin() const { return parr; } ///< \ru Получить указатель на первый элемент массива. \en Get the pointer to the first array element.
const Type * cend() const { return parr + count; } ///< \ru Получить указатель на участок памяти после массива. \en Get the pointer to the piece of memory after the array.
const Type & front() const;
Type & front();
const Type & back() const;
Type & back();
/**
\}
@@ -193,22 +185,22 @@ protected :
size_t AutoDelta() const { return ::KsAutoDelta( count, delta ); } ///< \ru Вычислить автоприращение. \en Calculate autoincrement.
/// \ru Перезахватить память. \en Reallocate memory.
TEMPLATE_FRIEND bool set_array_size TEMPLATE_SUFFIX ( SArray<Type> &, size_t newSize, bool clear );
TEMPLATE_FRIEND bool set_array_size TEMPLATE_SUFFIX ( SArray<Type> &, size_t newSize, bool clear );
/// \ru Добавить памяти под n элментов массива и вернуть указатель на начало выделеного участка памяти. \en Add memory for n elements of the array and return a pointer to the beginning of the selected piece of memory.
TEMPLATE_FRIEND Type * add_n_to_array TEMPLATE_SUFFIX ( SArray<Type> &, size_t n );
TEMPLATE_FRIEND Type * add_n_to_array TEMPLATE_SUFFIX ( SArray<Type> &, size_t n );
/// \ru Найти элемент в массиве. \en Find an element in the array.
TEMPLATE_FRIEND size_t find_in_array TEMPLATE_SUFFIX ( const SArray<Type> &, const Type &object );
TEMPLATE_FRIEND size_t find_in_array TEMPLATE_SUFFIX ( const SArray<Type> &, const Type & object );
/// \ru Заполнить fillCount элементов массива копиями объекта fillData. \en Fill fillCount elements of the array by copies of the object fillData.
TEMPLATE_FRIEND bool fill_array TEMPLATE_SUFFIX ( SArray<Type> &, size_t fillCount, const Type & fillData );
TEMPLATE_FRIEND bool fill_array TEMPLATE_SUFFIX ( SArray<Type> &, size_t fillCount, const Type & fillData );
/// \ru Заполнить fillCount элементов массива нулями. \en Fill fillCount elements of the array by nulls.
TEMPLATE_FRIEND bool fill_array_zero TEMPLATE_SUFFIX ( SArray<Type> &, size_t fillCount, size_t startIndex );
TEMPLATE_FRIEND bool fill_array_zero TEMPLATE_SUFFIX ( SArray<Type> &, size_t fillCount, size_t startIndex );
/// \ru Оператор чтения. \en Read operator.
TEMPLATE_FRIEND reader & CALL_DECLARATION operator >> TEMPLATE_SUFFIX ( reader & in, SArray<Type> & ref );
TEMPLATE_FRIEND reader & CALL_DECLARATION operator >> TEMPLATE_SUFFIX ( reader & in, SArray<Type> & ref );
/// \ru Оператор записи. \en Write operator.
TEMPLATE_FRIEND writer & CALL_DECLARATION operator << TEMPLATE_SUFFIX ( writer & out, const SArray<Type> & ref );
/// \ru Оператор чтения. \en Read operator.
TEMPLATE_FRIEND reader & CALL_DECLARATION operator >> TEMPLATE_SUFFIX ( reader & in, SArray<Type> *& ptr );
TEMPLATE_FRIEND reader & CALL_DECLARATION operator >> TEMPLATE_SUFFIX ( reader & in, SArray<Type> *& ptr );
/// \ru Оператор записи. \en Write operator.
TEMPLATE_FRIEND writer & CALL_DECLARATION operator << TEMPLATE_SUFFIX ( writer & out, const SArray<Type> * ptr );
@@ -298,6 +290,55 @@ inline SArray<Type>::SArray( const std::vector<Type> & o )
}
}
//------------------------------------------------------------------------------
// \ru Оператор доступа по индексу. \en Access by index operator.
// ---
template <class Type>
inline Type & SArray<Type>::operator []( size_t loc ) const
{
return parr[loc];
}
//------------------------------------------------------------------------------
// \ru Доступ к первому элементу. \en Access to th first element.
// ---
template <class Type>
inline const Type & SArray<Type>::front() const
{
PRECONDITION( !empty() );
return *parr;
}
//------------------------------------------------------------------------------
// \ru Доступ к первому элементу. \en Access to th first element.
// ---
template <class Type>
inline Type & SArray<Type>::front()
{
PRECONDITION( !empty() );
return *parr;
}
//------------------------------------------------------------------------------
// \ru Доступ к последнему элементу. \en Access to th last element.
// ---
template <class Type>
inline const Type & SArray<Type>::back() const
{
PRECONDITION( !empty() );
return *( parr + count - 1 );
}
//------------------------------------------------------------------------------
// \ru Доступ к последнему элементу. \en Access to th last element.
// ---
template <class Type>
inline Type &SArray<Type>::back()
{
PRECONDITION( !empty() );
return *( parr + count - 1 );
}
//------------------------------------------------------------------------------
// \ru Указать новый размер массива. \en Set the new size of an array.
@@ -407,7 +448,7 @@ inline Type * SArray<Type>::Add( const Type & ent )
template <class Type>
inline Type * SArray<Type>::AddAfter( const Type & ent, size_t index ) {
PRECONDITION( index < count );
if ( CatchMemory() ) {
if ( index < count && CatchMemory() ) {
memmove( parr + index + 2, parr + index + 1, sizeof(Type)*(count - index - 1) );
count++;
@@ -424,7 +465,7 @@ inline Type * SArray<Type>::AddAfter( const Type & ent, size_t index ) {
template <class Type>
inline Type * SArray<Type>::InsertInd( size_t index, const Type & ent ) {
PRECONDITION( index <= count );
if ( CatchMemory() ) { // \ru добавить памяти, если все использовано \en add memory if whole allocated memory is used
if ( index <= count && CatchMemory() ) { // \ru добавить памяти, если все использовано \en add memory if whole allocated memory is used
if ( index >= count )
index = count;
@@ -446,7 +487,7 @@ inline Type * SArray<Type>::InsertInd( size_t index, const Type & ent ) {
template <class Type>
inline Type * SArray<Type>::InsertInd( size_t index ) {
PRECONDITION( index <= count );
if ( CatchMemory() ) { // \ru добавить памяти, если все использовано \en add memory if whole allocated memory is used
if ( index <= count && CatchMemory() ) { // \ru добавить памяти, если все использовано \en add memory if whole allocated memory is used
// \ru передвинем вправо все элементы массива с последнего до указанного \en move to the right all elements of the array from the last to the specified one
memmove( parr + index + 1, parr + index, (count - index) * sizeof(Type) );
@@ -506,7 +547,7 @@ template <class Type>
inline void SArray<Type>::RemoveInd( size_t idx )
{
// RemoveInd( idx, idx+1 );
if ( parr ) {
if ( parr && idx < count ) {
Type * ptr = parr + idx;
Remove( ptr, ptr+1 );
}
@@ -526,7 +567,7 @@ void SArray<Type>::insert( Iterator pos, const Type & e )
}
if ( begin() ) {
const ptrdiff_t k = std::distance( (Iterator)begin(), pos );
if ( k >= 0 && k <= count )
if ( k >= 0 && k <= (ptrdiff_t)count )
InsertInd( k, e );
}
}
@@ -541,7 +582,7 @@ void SArray<Type>::erase( Iterator pos )
{
if ( begin() ) {
const ptrdiff_t k = std::distance( (Iterator)begin(), pos );
if ( k >= 0 && k < count )
if ( k >= 0 && k < (ptrdiff_t)count )
RemoveInd( k );
}
}
@@ -557,7 +598,7 @@ void SArray<Type>::erase( Iterator first, Iterator last )
const ptrdiff_t k1 = std::distance( (Iterator)begin(), first );
const ptrdiff_t k2 = std::distance( (Iterator)begin(), last );
if ( k1 >= 0 && k1 < k2 && k2 <= count ) {
if ( k1 >= 0 && k1 < k2 && k2 <= (ptrdiff_t)count ) {
RemoveInd( k1, k2 );
}
}
@@ -581,12 +622,14 @@ template <class Type>
inline void SArray<Type>::Remove( Type * firstItr, Type * lastItr )
{
PRECONDITION( firstItr >= parr && firstItr < lastItr && (lastItr - parr) <= (ptrdiff_t)count );
ptrdiff_t cpyCount = (parr + count) - lastItr;
if ( cpyCount > 0 ) {
memmove( static_cast<void *>(firstItr), static_cast<const void *>(lastItr), cpyCount*sizeof(Type) );
if ( firstItr >= parr && firstItr < lastItr ) {
ptrdiff_t copyCount = ( parr + count ) - lastItr;
if ( copyCount >= 0 ) {
if ( copyCount > 0 )
memmove( static_cast<void *>( firstItr ), static_cast<const void *>( lastItr ), copyCount * sizeof( Type ) );
count -= ( lastItr - firstItr );
}
}
if ( lastItr - firstItr > 0 )
count -= (lastItr-firstItr);
}
@@ -735,7 +778,7 @@ void SArray<Type>::assign( Iterator first, Iterator last )
{
const ptrdiff_t newCount = std::distance( first, last );
if ( set_array_size(*this, newCount, true) ) {
PRECONDITION( newCount <= upper && count == 0 );
PRECONDITION( newCount <= (ptrdiff_t)upper && count == 0 );
for ( ; first != last; ++first, ++count ) {
parr[count] = *first;
}
@@ -798,7 +841,7 @@ bool set_array_size( SArray<Type> & arr, size_t newSize, bool clear )
arr.upper = newSize;
#ifdef __REALLOC_ARRAYS_STATISTIC_
::ReallocArrayStatistic( oldParr, oldSize * sizeOfType, arr.parr, newSize * sizeOfType, 0/*SArray*/ );
REALLOC_ARRAY_STATISTICS( oldParr, oldSize * sizeOfType, arr.parr, newSize * sizeOfType, 0/*SArray*/ );
#endif // __REALLOC_ARRAYS_STATISTIC_
}
catch ( const std::bad_alloc & ) {
@@ -883,17 +926,33 @@ size_t find_in_array( const SArray<Type> & arr, const Type & object ) {
//-------------------------------------------------------------------------------
// \ru оператор сравнения двух массивов \en an operator of two arrays comparison
// \ru Оператор сравнения двух массивов. \en An operator of two arrays comparison.
/**
\details
\ru Осуществляется поэлементной стравнение с возможностью перегрузки
операции сравния с помощью метода IsEqualSArrayItems.
\en An element-by-element comparison is performed with the ability to redefine the
comparison operation using the overloading global function IsEqualSArrayItems.
*/
// ---
template <class Type>
inline bool SArray<Type>::operator == ( const SArray<Type> & w ) const {
inline bool SArray<Type>::operator == ( const SArray<Type> & w ) const
{
if ( count != w.count )
return false;
/*
При размещении в памяти с выравниванием не равным 1, между элементами массива
возможно появление "дырок" заполненного случайным мусором, т.к. сравнивать этот мусор
нам незачем, будем сравнивать содержимое массивов поэлементно (через оператор == или
путем перегрузки IsEqualSArrayItems).
// \ru OV K6 При размещении в памяти с выравниванием не равным 1, между элементами массива \en OV K6 While the memory allocation with alignment which is not equal 1 between elements of the array
// \ru возможно появление "дырок" заполненного случайным мусором, т.к. сравнивать этот мусор \en may appear "holes" filled by random trash, since there is not reason to compare this trash
// \ru нам незачем, будем сравнивать содержимое массивов поэлементно (через оператор == объекта) \en we will compare the content of arrays element by element (using the operator == of an object)
for ( size_t i = 0; i < count; i++ ) {
While the memory allocation with alignment which is not equal 1 between elements of
the array may appear "holes" filled by random trash, since there is not reason to
compare this trash we will compare the content of arrays element by element
(using the operator == of an object or by overloading the func IsEqualSArrayItems).
*/
for ( size_t i = 0; i < count; i++ )
{
if ( !::IsEqualSArrayItems( (*this)[i], w[i] ) )
return false;
}