Modularizando o src

Dependencies:   EALib EthernetInterface_vz mbed-rtos mbed

Fork of header_main_colinas_V0-20-09-14 by VZTECH

Committer:
klauss
Date:
Tue Jan 06 16:37:03 2015 +0000
Revision:
87:679ee0d594a9
Parent:
74:81c47fff88a5
Child:
89:0fe315117b00
rx buffer resized

Who changed what in which revision?

UserRevisionLine numberNew contents of line
klauss 0:4d17cd9c8f9d 1 #include "vector.h"
klauss 0:4d17cd9c8f9d 2
klauss 0:4d17cd9c8f9d 3 Vector::Vector(){
klauss 0:4d17cd9c8f9d 4 this->objects = NULL;
klauss 0:4d17cd9c8f9d 5 this->elements = 0;
klauss 0:4d17cd9c8f9d 6 }
klauss 0:4d17cd9c8f9d 7
klauss 0:4d17cd9c8f9d 8 Vector::~Vector(){
klauss 0:4d17cd9c8f9d 9 if( this->objects != NULL ) free( this->objects );
klauss 0:4d17cd9c8f9d 10 }
klauss 0:4d17cd9c8f9d 11
klauss 87:679ee0d594a9 12 void Vector::add( Object * e ){
klauss 87:679ee0d594a9 13 if( e != NULL ){
klauss 87:679ee0d594a9 14 this->objects = ( Object ** )realloc( this->objects, sizeof ( Object * ) * ++this->elements );
klauss 87:679ee0d594a9 15 if ( this->objects == NULL ){
klauss 87:679ee0d594a9 16 memory_is_over = true;
klauss 87:679ee0d594a9 17 }else{
klauss 87:679ee0d594a9 18 this->objects[ this->elements - 1 ] = e;
klauss 87:679ee0d594a9 19 }
klauss 87:679ee0d594a9 20 }
klauss 0:4d17cd9c8f9d 21 }
klauss 0:4d17cd9c8f9d 22
klauss 0:4d17cd9c8f9d 23 Object * Vector::get_element( int position ){
klauss 0:4d17cd9c8f9d 24 return( position > -1 && position < this->elements ) ? (Object *) * ( this->objects + position ) : NULL;
klauss 0:4d17cd9c8f9d 25 }
klauss 0:4d17cd9c8f9d 26
klauss 0:4d17cd9c8f9d 27 void Vector::remove_element( int position ){
klauss 29:7246460b73f8 28 if( debug_vector ) debug_msg( "Removing element %d", position );
klauss 0:4d17cd9c8f9d 29 if( position > -1 && position < this->elements ){
klauss 0:4d17cd9c8f9d 30 if( position == 0 && this->elements == 1 ) {
klauss 0:4d17cd9c8f9d 31 this->elements = 0;
klauss 0:4d17cd9c8f9d 32 free( this->objects );
klauss 0:4d17cd9c8f9d 33 this->objects = NULL;
klauss 0:4d17cd9c8f9d 34 }else{
klauss 0:4d17cd9c8f9d 35 this->objects[ position ] = this->objects[ --this->elements ];
klauss 4:de46f0d9b14d 36 this->objects = ( Object ** )realloc( this->objects, sizeof ( Object * ) * this->elements );
klauss 87:679ee0d594a9 37 if( this->objects == NULL ) memory_is_over = true;
klauss 0:4d17cd9c8f9d 38 }
klauss 0:4d17cd9c8f9d 39 }
klauss 29:7246460b73f8 40 if( debug_vector ) debug_msg( "Removed" );
klauss 0:4d17cd9c8f9d 41 }
klauss 0:4d17cd9c8f9d 42
klauss 0:4d17cd9c8f9d 43 int Vector::find_element( Object * e ){
klauss 87:679ee0d594a9 44 if( e != NULL )
klauss 87:679ee0d594a9 45 {
klauss 87:679ee0d594a9 46 for( int i = 0; i < this->elements; i++ )
klauss 87:679ee0d594a9 47 if( this->objects[ i ] == e ) return ( i );
klauss 87:679ee0d594a9 48 return ( -3 );
klauss 87:679ee0d594a9 49 }
klauss 87:679ee0d594a9 50 else
klauss 87:679ee0d594a9 51 {
klauss 87:679ee0d594a9 52 return ( -1 );
klauss 87:679ee0d594a9 53 }
klauss 0:4d17cd9c8f9d 54 }
klauss 0:4d17cd9c8f9d 55
klauss 0:4d17cd9c8f9d 56 //Object * Vector::find_element( int ext, int port ){
klauss 0:4d17cd9c8f9d 57 // for( int i = 0; i < this->elements; i++ ){
klauss 0:4d17cd9c8f9d 58 // if( this->objects[ i ]->get_ext() == ext &&
klauss 0:4d17cd9c8f9d 59 // this->objects[ i ]->get_port() == port ) return( this->objects[ i ] );
klauss 0:4d17cd9c8f9d 60 // }
klauss 0:4d17cd9c8f9d 61 // return( NULL );
klauss 0:4d17cd9c8f9d 62 //}
klauss 0:4d17cd9c8f9d 63
klauss 0:4d17cd9c8f9d 64 int Vector::size(){ return this->elements; }