Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template < class Type, uint8_t Len > class my_array
- {
- public:
- Type* data;
- uint8_t length;
- uint8_t pos;
- my_array(){
- data = (Type*) malloc ( sizeof ( Type ) * Len );
- for(uint8_t i=0; i<Len; i++){
- data[i] = 0; //(*(Type*)0);
- };
- length = Len - 1;
- pos = 0;
- };
- ~my_array(){
- pos = 0;
- length = 0;
- free(data);
- };
- uint8_t insert(Type t){
- if( pos == length ){ return 1; };
- data[pos] = t;
- pos++;
- return 0;
- };
- uint8_t remove_last(void){
- if( pos == 0 )return 1;
- pos--;
- data[pos] = 0;
- return 0;
- };
- uint8_t size(void){
- return (pos-1);
- }
- Type& operator[] (uint8_t i)
- {
- if( (i > 0) && (i < length) ){
- return data[i];
- };
- return (*(Type*)0);
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment