Modularizando o src
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
Diff: vector.cpp
- Revision:
- 87:679ee0d594a9
- Parent:
- 74:81c47fff88a5
- Child:
- 89:0fe315117b00
diff -r bf7b0d4c3232 -r 679ee0d594a9 vector.cpp --- a/vector.cpp Mon Jan 05 12:43:12 2015 +0000 +++ b/vector.cpp Tue Jan 06 16:37:03 2015 +0000 @@ -9,9 +9,15 @@ if( this->objects != NULL ) free( this->objects ); } -void Vector::add( Object * e){ - this->objects = ( Object ** )realloc( this->objects, sizeof ( Object * ) * ++this->elements ); - this->objects[ this->elements - 1 ] = e; +void Vector::add( Object * e ){ + if( e != NULL ){ + this->objects = ( Object ** )realloc( this->objects, sizeof ( Object * ) * ++this->elements ); + if ( this->objects == NULL ){ + memory_is_over = true; + }else{ + this->objects[ this->elements - 1 ] = e; + } + } } Object * Vector::get_element( int position ){ @@ -28,15 +34,23 @@ }else{ this->objects[ position ] = this->objects[ --this->elements ]; this->objects = ( Object ** )realloc( this->objects, sizeof ( Object * ) * this->elements ); + if( this->objects == NULL ) memory_is_over = true; } } if( debug_vector ) debug_msg( "Removed" ); } int Vector::find_element( Object * e ){ - for( int i = 0; i < this->elements; i++ ) - if( this->objects[ i ] == e ) return ( i ); - return ( -3 ); + if( e != NULL ) + { + for( int i = 0; i < this->elements; i++ ) + if( this->objects[ i ] == e ) return ( i ); + return ( -3 ); + } + else + { + return ( -1 ); + } } //Object * Vector::find_element( int ext, int port ){