|
From: Frank V. C. <fr...@us...> - 2001-02-24 16:26:59
|
Update of /cvsroot/corelinux/clfw/src/libs/clfw
In directory usw-pr-cvs1:/tmp/cvs-serv4932/src/libs/clfw
Modified Files:
Array.cpp
Log Message:
133863 Added behavior (partial) to Array
Index: Array.cpp
===================================================================
RCS file: /cvsroot/corelinux/clfw/src/libs/clfw/Array.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** Array.cpp 2001/02/24 04:32:31 1.1
--- Array.cpp 2001/02/24 16:28:07 1.2
***************
*** 27,30 ****
--- 27,36 ----
#endif
+ #if !defined(__METASPACE_HPP)
+ #include <MetaSpace.hpp>
+ #endif
+
+ #include <cstring>
+
namespace corelinux
{
***************
*** 37,42 ****
:
Collection(),
theSizeRestriction( 0 ),
! theEntites( NULLPTR ),
theCount( 0 ),
theRemaining( 0 )
--- 43,49 ----
:
Collection(),
+ Synchronized(),
theSizeRestriction( 0 ),
! theEntities( NULLPTR ),
theCount( 0 ),
theRemaining( 0 )
***************
*** 52,57 ****
:
Collection(),
theSizeRestriction( 0 ),
! theEntites( NULLPTR ),
theCount( 0 ),
theRemaining( 0 )
--- 59,65 ----
:
Collection(),
+ Synchronized(),
theSizeRestriction( 0 ),
! theEntities( NULLPTR ),
theCount( 0 ),
theRemaining( 0 )
***************
*** 76,87 ****
ArrayCref aArray
) const
{
! return Collection::operator ==(aArray);
}
//
! // Assignment operator
//
ArrayRef Array::operator=
(
--- 84,243 ----
ArrayCref aArray
) const
+ {
+ return ( this == &aArray );
+ }
+
+ //
+ // Return the number of elements in the array
+ //
+
+ CountCref Array::size( void ) const
{
! return theCount;
}
//
! // Get indexed entity methods
//
+ FrameworkEntityPtr Array::operator []( Index offset ) const
+ throw (BoundsException)
+ {
+ GUARD;
+ if( offset >= theCount )
+ {
+ throw BoundsException( LOCATION );
+ }
+ else
+ {
+ ; // continue
+ }
+
+ return theEntities[offset];
+ }
+
+ FrameworkEntityPtr Array::getElementAt( Index offset ) const
+ throw (BoundsException)
+ {
+ return (*this)[offset];
+ }
+
+ //
+ // Get indexed entity class
+ //
+
+ MetaClassPtr Array::getElementClassAt( Index offset ) const
+ throw (BoundsException)
+ {
+ FrameworkEntityPtr aEP( (*this)[offset] );
+ return MetaSpace::getClassForType( aEP->getType() );
+ }
+
+ //
+ // Add an entity to the array
+ //
+
+ ArrayRef Array::operator=( FrameworkEntityPtr anEntity )
+ throw (NullPointerException,BoundsException)
+ {
+ if( anEntity == NULLPTR )
+ {
+ throw NullPointerException( LOCATION );
+ }
+ else if( this->checkBoundsForAdd() == false )
+ {
+ throw BoundsException( LOCATION );
+ }
+ else
+ {
+ GUARD;
+ this->increaseArraySize();
+ theEntities[theCount] = anEntity;
+ this->increaseOccupancy();
+ }
+ return ( *this );
+ }
+
+ //
+ // Appending entities
+ //
+
+ void Array::put( FrameworkEntityPtr anEntity )
+ throw (NullPointerException,BoundsException)
+ {
+ (*this)=anEntity;
+ }
+
+ void Array::putBack( FrameworkEntityPtr anEntity )
+ throw (NullPointerException,BoundsException)
+ {
+ (*this)=anEntity;
+ }
+
+ void Array::putFront( FrameworkEntityPtr anEntity )
+ throw (NullPointerException,BoundsException)
+ {
+ putAt(0,anEntity);
+ }
+
+ void Array::putAt( Index offset, FrameworkEntityPtr anEntity )
+ throw (NullPointerException,BoundsException)
+ {
+ if( anEntity == NULLPTR )
+ {
+ throw NullPointerException( LOCATION );
+ }
+ else if( checkBoundsForAdd() == false )
+ {
+ throw BoundsException( LOCATION );
+ }
+ else
+ {
+ GUARD;
+ this->increaseArraySize();
+ this->shiftForInsert( offset );
+ theEntities[offset] = anEntity;
+ this->increaseOccupancy();
+ }
+ }
+
+ FrameworkEntityPtr Array::removeAt( Index offset )
+ throw (BoundsException)
+ {
+ FrameworkEntityPtr aPtr( NULLPTR );
+
+ if( offset >= theCount )
+ {
+ throw BoundsException( LOCATION );
+ }
+ else
+ {
+ GUARD;
+ aPtr = theEntities[offset];
+ this->shiftForRemove( offset );
+ this->decreaseOccupancy();
+ }
+
+ return aPtr;
+ }
+
+ /// Remove first entity in array
+
+ FrameworkEntityPtr Array::removeAtFront( void )
+ {
+ return (this->removeAt( 0 ));
+ }
+
+ /// Remove last entity in array
+
+ FrameworkEntityPtr Array::removeAtEnd( void )
+ {
+ return (this->removeAt( theCount-1 ));
+ }
+
+ //
+ // Assignment operator for Array Reference
+ //
+
ArrayRef Array::operator=
(
***************
*** 91,94 ****
--- 247,251 ----
if( this != &aArray )
{
+ GUARD;
}
else
***************
*** 99,102 ****
--- 256,399 ----
}
+ //
+ // Assignment operator for Array Pointer
+ //
+
+ ArrayRef Array::operator=
+ (
+ ArrayCptr aArray
+ )
+ throw (NullPointerException)
+ {
+ if( aArray == NULLPTR )
+ {
+ throw NullPointerException( LOCATION );
+ }
+ else
+ {
+ if( this != aArray )
+ {
+ GUARD;
+ }
+ else
+ {
+ ; // do nothing
+ }
+ }
+
+ return ( *this );
+ }
+
+ // Consume
+
+ void Array::increaseOccupancy( Count additions )
+ {
+ theCount += additions;
+ theRemaining -= additions;
+ }
+
+ // Relieve
+
+ void Array::decreaseOccupancy( Count removals )
+ {
+ theCount -= removals;
+ theRemaining += removals;
+ }
+
+ //
+ // Bounds checker
+ //
+
+ bool Array::checkBoundsForAdd( Count increment )
+ {
+ bool canDo( true );
+
+ if( theRemaining == 0 || increment > theRemaining )
+ {
+ UnsignedInteger aR = getSizeRestriction();
+
+ if( aR.getValue() != 0 &&
+ ( theCount >= aR.getValue() ||
+ theCount+increment > aR.getValue() )
+ )
+ {
+ canDo = false;
+ }
+ else
+ {
+ ; // we can always grow
+ }
+ }
+ else
+ {
+ ; // we have space in the current block
+ }
+
+ return canDo;
+ }
+
+ //
+ // Auto increase mechanism
+ //
+
+ void Array::increaseArraySize( Count increment )
+ {
+ if( increment > theRemaining )
+ {
+ Count growth = (theCount+increment)+theCount/2;
+ FrameworkEntityPtr *newArray = new FrameworkEntityPtr[growth];
+
+ for( Count x=0; x<theCount ; ++x )
+ {
+ newArray[x] = theEntities[x];
+ }
+
+ if( theEntities != NULLPTR )
+ {
+ delete [] theEntities;
+ }
+ else
+ {
+ ; // do nothing
+ }
+
+ theEntities = newArray;
+ theRemaining = growth - theCount;
+ }
+ else
+ {
+ ; // still room
+ }
+ }
+
+ //
+ // Move the members for insertion
+ //
+
+ void Array::shiftForInsert( Index position, Count increment )
+ {
+ size_t sizeMove = (theCount - position)*sizeof(FrameworkEntityPtr);
+ memmove
+ (
+ &theEntities[position],
+ &theEntities[position+increment],
+ sizeMove
+ );
+ }
+
+ //
+ // Move the members for removal
+ //
+
+ void Array::shiftForRemove( Index position, Count increment )
+ {
+ size_t sizeMove = (theCount - increment)*sizeof(FrameworkEntityPtr);
+ memmove
+ (
+ &theEntities[position+increment],
+ &theEntities[position],
+ sizeMove
+ );
+ }
//! version for the Array MetaType
***************
*** 116,124 ****
CLOSE_METATYPE_PARENT;
! //! We define our property data descriptor
DEFINE_CLASSINSTANCE_DESCRIPTOR(Array, UnsignedInteger,UnsignedInteger, SizeRestriction );
! //! We construct the values reference
OPEN_INSTANCEDATA( Array )
--- 413,421 ----
CLOSE_METATYPE_PARENT;
! // We define our property data descriptor
DEFINE_CLASSINSTANCE_DESCRIPTOR(Array, UnsignedInteger,UnsignedInteger, SizeRestriction );
! // We construct the values reference
OPEN_INSTANCEDATA( Array )
|