avr/cpp/collection/StaticArray.h

Go to the documentation of this file.
00001 /**********************************************************************************************************************\
00002 
00003         C++ library for Atmel AVR microcontrollers
00004         Copyright (C) 2007 Lauri Kirikal, Mikk Leini, MT� TT� Robotiklubi
00005 
00006         This program is free software; you can redistribute it and/or
00007         modify it under the terms of the GNU General Public License
00008         as published by the Free Software Foundation; either version 2
00009         of the License, or (at your option) any later version.
00010 
00011         This program is distributed in the hope that it will be useful,
00012         but WITHOUT ANY WARRANTY; without even the implied warranty of
00013         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014         GNU General Public License for more details.
00015 
00016         You should have received a copy of the GNU General Public License
00017         along with this program; if not, write to the Free Software
00018         Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00019 
00020         See http://creativecommons.org/licenses/GPL/2.0/
00021 
00022         MT� TT� Robotiklubi  http://www.robotiklubi.ee robotiklubi@gmail.com
00023         Lauri Kirikal        laurikirikal@gmail.com
00024         Mikk Leini           mikk.leini@gmail.com
00025 
00026 \**********************************************************************************************************************/
00027 
00028 #ifndef __AVR_CPP_STATIC_ARRAY_H__
00029 #define __AVR_CPP_STATIC_ARRAY_H__
00030 
00031 #include "BaseArray.h"
00032 
00033 
00034 /**********************************************************************************************************************\
00035 
00036         AVRCppLib collection objects
00037 
00038 \**********************************************************************************************************************/
00039 
00040 namespace AVRCpp
00041 {
00042         namespace Collection
00043         {
00044 
00045 
00046 /**********************************************************************************************************************\
00047 
00048         Static array class
00049 
00050         Fixed size list. Supports item adding, inserting and removing within limited size.
00051 
00052 \**********************************************************************************************************************/
00053 
00054 template <typename DataType, typename SizeType, SizeType array_capacity> class StaticArray : public BaseArray<DataType, SizeType, DataType[array_capacity]>
00055 {       
00056         public:
00057         
00061                 StaticArray()
00062                 {                       
00063                         BaseArray<DataType, SizeType, DataType[array_capacity]>();
00064                 }
00065                 
00069                 bool Resize(const SizeType size, const DataType &values = DataType())
00070                 {
00071                         // If new size is larger than maximum capacity then abort
00072                         if (size >= array_capacity) return false;
00073 
00074                         return BaseArray<DataType, SizeType, DataType[array_capacity]>::Resize(size, values);
00075                 }
00076 
00080                 bool Add(const DataType &value)
00081                 {
00082                         // If new size is larger than maximum capacity then abort
00083                         if (this->current_size >= array_capacity) return false;
00084 
00085                         return BaseArray<DataType, SizeType, DataType[array_capacity]>::Add(value);
00086                 }
00087 
00091                 bool Insert(const DataType &value, const SizeType pos)
00092                 {
00093                         // If new size is larger than maximum capacity then abort
00094                         if (this->current_size >= array_capacity) return false;
00095 
00096                         // Check constraints
00097                         if (pos > this->current_size) return false;
00098 
00099                         return BaseArray<DataType, SizeType, DataType[array_capacity]>::Insert(value, pos);
00100                 }
00101 
00105                 bool Remove(const SizeType pos)
00106                 {
00107                         return BaseArray<DataType, SizeType, DataType[array_capacity]>::Remove(pos);
00108                 }
00109 
00113                 SizeType GetCapacity(void)
00114                 {
00115                         return array_capacity;
00116                 }
00117                 
00121                 inline bool IsFull(void)
00122                 {
00123                         return (this->current_size == array_capacity);
00124                 }
00125 
00126 }; // class StaticArray
00127 
00128 
00129 /**********************************************************************************************************************/
00130 
00131         } // namespace Collection
00132 
00133 } // namespace AVRCpp
00134 
00135 
00136 /**********************************************************************************************************************/
00137 
00138 #endif // ifndef __AVR_CPP_STATIC_ARRAY_H__

Generated on Sat Sep 15 23:41:46 2007 for AVR C++ Lib (common) by  doxygen 1.5.2
SourceForge.net Logo MTÜ TTÜ Robotiklubi