Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface NTPClient mbed-rtos_old mbed
Fork of header_main_public by
vector.cpp
00001 #include "vector.h" 00002 00003 Vector::Vector(){ 00004 this->objects = NULL; 00005 this->elements = 0; 00006 } 00007 00008 Vector::~Vector(){ 00009 if( this->objects != NULL ) free( this->objects ); 00010 } 00011 00012 void Vector::add( Object * e){ 00013 this->objects = ( Object ** )realloc( this->objects, sizeof ( Object * ) * ++this->elements ); 00014 this->objects[ this->elements - 1 ] = e; 00015 } 00016 00017 Object * Vector::get_element( int position ){ 00018 return( position > -1 && position < this->elements ) ? (Object *) * ( this->objects + position ) : NULL; 00019 } 00020 00021 void Vector::remove_element( int position ){ 00022 debug_msg(" Removendo elemento %d", position ); 00023 if( position > -1 && position < this->elements ){ 00024 if( position == 0 && this->elements == 1 ) { 00025 this->elements = 0; 00026 free( this->objects ); 00027 this->objects = NULL; 00028 }else{ 00029 this->objects[ position ] = this->objects[ --this->elements ]; 00030 this->objects = ( Object ** )realloc( this->objects, sizeof ( Object * ) * this->elements ); 00031 } 00032 } 00033 debug_msg(" remocao bem sucedida" ); 00034 } 00035 00036 int Vector::find_element( Object * e ){ 00037 for( int i = 0; i < this->elements; i++ ) 00038 if( this->objects[ i ] == e ) return ( i ); 00039 return ( -3 ); 00040 } 00041 00042 //Object * Vector::find_element( int ext, int port ){ 00043 // for( int i = 0; i < this->elements; i++ ){ 00044 // if( this->objects[ i ]->get_ext() == ext && 00045 // this->objects[ i ]->get_port() == port ) return( this->objects[ i ] ); 00046 // } 00047 // return( NULL ); 00048 //} 00049 00050 int Vector::size(){ return this->elements; }
Generated on Sat Jul 16 2022 08:57:54 by
1.7.2
