voltando a versao de n aberturas e fechamentos de sockets data 19/09

Dependencies:   EthernetInterface NTPClient mbed-rtos mbed EALib

Fork of header_main_publish by VZTECH

Committer:
klauss
Date:
Sat Sep 20 11:27:47 2014 +0000
Revision:
19:ab2088e0dec6
Parent:
4:de46f0d9b14d
colinas_02

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 0:4d17cd9c8f9d 12 void Vector::add( Object * e){
klauss 0:4d17cd9c8f9d 13 this->objects = ( Object ** )realloc( this->objects, sizeof ( Object * ) * ++this->elements );
klauss 0:4d17cd9c8f9d 14 this->objects[ this->elements - 1 ] = e;
klauss 0:4d17cd9c8f9d 15 }
klauss 0:4d17cd9c8f9d 16
klauss 0:4d17cd9c8f9d 17 Object * Vector::get_element( int position ){
klauss 0:4d17cd9c8f9d 18 return( position > -1 && position < this->elements ) ? (Object *) * ( this->objects + position ) : NULL;
klauss 0:4d17cd9c8f9d 19 }
klauss 0:4d17cd9c8f9d 20
klauss 0:4d17cd9c8f9d 21 void Vector::remove_element( int position ){
klauss 4:de46f0d9b14d 22 debug_msg(" Removendo elemento %d", position );
klauss 0:4d17cd9c8f9d 23 if( position > -1 && position < this->elements ){
klauss 0:4d17cd9c8f9d 24 if( position == 0 && this->elements == 1 ) {
klauss 0:4d17cd9c8f9d 25 this->elements = 0;
klauss 0:4d17cd9c8f9d 26 free( this->objects );
klauss 0:4d17cd9c8f9d 27 this->objects = NULL;
klauss 0:4d17cd9c8f9d 28 }else{
klauss 0:4d17cd9c8f9d 29 this->objects[ position ] = this->objects[ --this->elements ];
klauss 4:de46f0d9b14d 30 this->objects = ( Object ** )realloc( this->objects, sizeof ( Object * ) * this->elements );
klauss 0:4d17cd9c8f9d 31 }
klauss 0:4d17cd9c8f9d 32 }
klauss 4:de46f0d9b14d 33 debug_msg(" remocao bem sucedida" );
klauss 0:4d17cd9c8f9d 34 }
klauss 0:4d17cd9c8f9d 35
klauss 0:4d17cd9c8f9d 36 int Vector::find_element( Object * e ){
klauss 0:4d17cd9c8f9d 37 for( int i = 0; i < this->elements; i++ )
klauss 0:4d17cd9c8f9d 38 if( this->objects[ i ] == e ) return ( i );
klauss 0:4d17cd9c8f9d 39 return ( -3 );
klauss 0:4d17cd9c8f9d 40 }
klauss 0:4d17cd9c8f9d 41
klauss 0:4d17cd9c8f9d 42 //Object * Vector::find_element( int ext, int port ){
klauss 0:4d17cd9c8f9d 43 // for( int i = 0; i < this->elements; i++ ){
klauss 0:4d17cd9c8f9d 44 // if( this->objects[ i ]->get_ext() == ext &&
klauss 0:4d17cd9c8f9d 45 // this->objects[ i ]->get_port() == port ) return( this->objects[ i ] );
klauss 0:4d17cd9c8f9d 46 // }
klauss 0:4d17cd9c8f9d 47 // return( NULL );
klauss 0:4d17cd9c8f9d 48 //}
klauss 0:4d17cd9c8f9d 49
klauss 0:4d17cd9c8f9d 50 int Vector::size(){ return this->elements; }