DataBox.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 DataBox.hpp
00024  * @Description DataBox class definition.
00025  * @Status Implementing
00026  * @Version $Id: DataBox.hpp 1 2011-03-04 18:13:18Z jreis $
00027  * @Maintainer Marco Barbosa
00028  */
00029 
00030 
00031 #ifndef __DATASTRUCTURE_DATABOX_H_
00032 #define __DATASTRUCTURE_DATABOX_H_
00033 
00034 #include "DataStructureDescription.hpp"
00035 #include "DataValue.hpp"
00036 #include "DataValueVector.hpp"
00037 
00038 #include "IntegerArray.hpp"
00039 #include "DoubleArray.hpp"
00040 #include "StringArray.hpp"
00041 
00042 
00043 #include <map>
00044 #include <string>
00045 
00046 namespace mermaid
00047 {
00048   namespace support
00049   {
00050     namespace data
00051     {
00052       using boost::shared_ptr;
00053       
00054       
00055       class DataBoxArray; // forward declaration
00056       
00057       
00058       /**
00059        * @Class DataBox DataBox.hpp "DataBox.hpp"
00060        * @Description A DataBox is a place where data can be put and retrieved from.
00061        * @Description This is a smart box, in which you can access data by name.
00062        * @Author Marco Barbosa
00063        */
00064       
00065       class DataBox : public DataValue
00066       {
00067       
00068           friend class DataFactory;
00069           
00070         public:
00071         
00072         
00073           DataBox (const DataBox &dbox);
00074           
00075           DataBox * clone();
00076           
00077           std::string getBoxStructureName() const;
00078           
00079           shared_ptr<DataValue> getValue (std::string valueName) const;
00080           
00081           shared_ptr<DataValueVector> getDataValueVector() const;
00082           
00083           int getInteger (std::string name) const;
00084           shared_ptr<IntegerArray> getIntegerArray (std::string name) const;
00085           
00086           double getDouble (std::string name) const;
00087           shared_ptr<DoubleArray> getDoubleArray (std::string name) const;
00088           
00089           std::string getString (std::string name) const;
00090           shared_ptr<StringArray> getStringArray (std::string name) const;
00091           
00092           shared_ptr<DataBox> getDataBox (std::string name) const;
00093           shared_ptr<DataBoxArray> getDataBoxArray (std::string name) const;
00094           
00095           void setInteger (std::string name, int value);
00096           void setDouble (std::string name, double value);
00097           void setString (std::string name, std::string value);
00098           
00099           void setValueFromString (std::string name, std::string value);
00100           /**
00101            * @Description Method to convert to string
00102            */
00103           virtual operator std::string() const;
00104           void print() const;
00105         private:
00106           //used by DataFactory
00107           DataBox();
00108           DataBox (shared_ptr<DataStructureDescription> dsd);
00109           
00110           //used by constructor
00111           void addInteger (std::string name, int i = 0);
00112           shared_ptr<IntegerArray> addDynamicIntegerArray (std::string name);
00113           shared_ptr<IntegerArray> addStaticIntegerArray (std::string name, int size);
00114           
00115           void addDouble (std::string name, double d = 0.0);
00116           shared_ptr<DoubleArray> addDynamicDoubleArray (std::string name);
00117           shared_ptr<DoubleArray> addStaticDoubleArray (std::string name, int size);
00118           
00119           void addString (std::string name, std::string s = std::string (""));
00120           shared_ptr<StringArray> addDynamicStringArray (std::string name);
00121           shared_ptr<StringArray> addStaticStringArray (std::string name, int size);
00122           
00123           void addDataBox (std::string name, std::string type);
00124           shared_ptr<DataBoxArray> addDynamicDataBoxArray (std::string name, std::string type);
00125           shared_ptr<DataBoxArray> addStaticDataBoxArray (std::string name, std::string type, int size);
00126           
00127           void addDataValue (std::string name, shared_ptr<DataValue> value);
00128           
00129           /**
00130            * @Returns number of read values of the value vector
00131            */
00132           int setDataFromValueVector (shared_ptr<DataValueVector> vv, int startPos = 0);
00133           
00134           //variables to hold the data
00135           shared_ptr<DataStructureDescription> dataStructureDescription_;
00136           shared_ptr<DataValueVector> valueVector_;
00137           std::map<std::string, shared_ptr<DataValue> > nameToPtrMap_;
00138           std::map<shared_ptr<DataValue>, std::string> ptrToNameMap_;
00139       }; // DataBox
00140     } // namespace data
00141   } // namespace support
00142 } // namespace mermaid
00143 
00144 #endif // __DATASTRUCTURE_DATABOX_H_
Generated on Fri Mar 4 22:14:58 2011 for MeRMaID::support by  doxygen 1.6.3