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 mbed
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 if( position > -1 && position < this->elements ){ 00023 if( position == 0 && this->elements == 1 ) { 00024 this->elements = 0; 00025 free( this->objects ); 00026 this->objects = NULL; 00027 }else{ 00028 this->objects[ position ] = this->objects[ --this->elements ]; 00029 this->objects = ( Object ** )realloc( this->objects, sizeof ( Object * ) * this->elements ); 00030 } 00031 } 00032 } 00033 00034 int Vector::find_element( Object * e ){ 00035 for( int i = 0; i < this->elements; i++ ) 00036 if( this->objects[ i ] == e ) return ( i ); 00037 return ( -3 ); 00038 } 00039 00040 //Object * Vector::find_element( int ext, int port ){ 00041 // for( int i = 0; i < this->elements; i++ ){ 00042 // if( this->objects[ i ]->get_ext() == ext && 00043 // this->objects[ i ]->get_port() == port ) return( this->objects[ i ] ); 00044 // } 00045 // return( NULL ); 00046 //} 00047 00048 int Vector::size(){ return this->elements; }
Generated on Fri Jul 22 2022 09:19:18 by
1.7.2