DataArray.hpp

Go to the documentation of this file.
00001 /*
00002 Copyright 2007, 2008, 2009, 2010, 2011 Instituto de Sistemas e Robotica, Instituto Superior Tecnico
00003 
00004 This file is part of MeRMaID.
00005 
00006 MeRMaID is free software: you can redistribute it and/or modify
00007 it under the terms of the GNU Lesser General Public License as published by
00008 the Free Software Foundation, either version 3 of the License, or
00009 (at your option) any later version.
00010 
00011 MeRMaID 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 Lesser General Public License for more details.
00015 
00016 You should have received a copy of the GNU Lesser General Public License
00017 along with MeRMaID.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 
00020 
00021 
00022 /**
00023  * @Filename DataArray.hpp
00024  * @Description DataArray class definition.
00025  * @Status Implementing
00026  * @Version $Id: DataArray.hpp 1 2011-03-04 18:13:18Z jreis $
00027  * @Maintainer Marco Barbosa
00028  */
00029 
00030 #ifndef __DATASTRUCTURE_DATAARRAY_H_
00031 #define __DATASTRUCTURE_DATAARRAY_H_
00032 
00033 #include "DataValue.hpp"
00034 
00035 #include <Exception.hpp>
00036 
00037 #include <vector>
00038 
00039 namespace mermaid
00040 {
00041   namespace support
00042   {
00043     namespace data
00044     {
00045     
00046       using boost::shared_ptr;
00047       using mermaid::support::errorhandling::Exception;
00048       
00049       /**
00050        * @Class DataArray DataArray.hpp "DataArray.hpp"
00051        * @Description Class representing a data value array
00052        * @Author Marco Barbosa
00053        */
00054       template<class T>
00055       class DataArray : public DataValue
00056       {
00057         public:
00058           /**
00059            * @Description Default constructor. This initializes the array as a dynamic array (one whose size may change during time).
00060            */
00061           DataArray() : DataValue() {
00062             isDynamic_ = true;
00063           };
00064           
00065           /**
00066            * @Description Constructor. This initializes the array as a static array (one whose size is fixed during time).
00067            * @Argument size Size of the static array.
00068            */
00069           DataArray (int size) : DataValue() {
00070             isDynamic_ = false;
00071             
00072             for (int i = 0; i < size; i++) {
00073               array_.push_back (shared_ptr<T>());
00074             };
00075           };
00076           
00077           /**
00078            * @Description Getter. Returns a pointer to the object at a specific position in the array.
00079            * @Argument index Position of the array to be accessed.
00080            */
00081           shared_ptr<T>& operator[] (const int index) {
00082             return array_[index];
00083           };
00084           
00085           /**
00086            * @Description Operation that adds a data element at the end of the array. This operation is only valid in dynamic arrays.
00087            * @Argument value Value to be added at the end of the array.
00088            */
00089           void pushBack (shared_ptr<T> value) {
00090             if (isDynamic_ == false) {
00091               throw Exception ("DataArray::pushBack : array is not dynamic");
00092             }
00093             
00094             array_.push_back (value);
00095           };
00096           
00097           /**
00098            * @Description Tests if the array is dynamic or not.
00099            * @Returns True if the array is dynamic, false otherwise.
00100            */
00101           bool isDynamic() {
00102             return isDynamic_;
00103           };
00104           
00105           /**
00106            * @Description Gives the size of the array.
00107            * @Returns Size of the array.
00108            */
00109           unsigned int getSize() {
00110             return array_.size();
00111           };
00112           
00113         protected:
00114           bool isDynamic_;
00115           std::vector<shared_ptr<T> > array_;
00116           
00117       }; // class DataArray
00118     } // namespace data
00119   } // namespace support
00120 } // namespace mermaid
00121 
00122 
00123 #endif // __DATASTRUCTURE_DATAARRAY_H_
Generated on Fri Mar 4 22:14:58 2011 for MeRMaID::support by  doxygen 1.6.3