![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Modularizando o src
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
vector.cpp@74:81c47fff88a5, 2014-11-24 (annotated)
- Committer:
- klauss
- Date:
- Mon Nov 24 16:43:16 2014 +0000
- Revision:
- 74:81c47fff88a5
- Parent:
- 29:7246460b73f8
- Child:
- 87:679ee0d594a9
validando organiza??o de arquivos | ainda em desenvolvimento.
Who changed what in which revision?
User | Revision | Line number | New 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 | 29:7246460b73f8 | 22 | if( debug_vector ) debug_msg( "Removing element %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 | 29:7246460b73f8 | 33 | if( debug_vector ) debug_msg( "Removed" ); |
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; } |