datacontainer.h

00001 
00002 /****************************************************************************************
00003                                           datacontainer.h 
00004                                         -------------------
00005     copyright            : (C) 2006 Jean-Luc Perret - Pierre Mahé
00006     email                : jean-luc.perret@unine.ch - pierre.mahe@ensmp.fr
00007  ***************************************************************************************/
00008 
00009 /****************************************************************************************
00010  *                                                                                      *
00011  *      This program is free software; you can redistribute it and/or                   *
00012  *      modify it under the terms of the GNU Lesser General Public                      *
00013  *      License as published by the Free Software Foundation; either                    *
00014  *      version 2.1 of the License, or (at your option) any later version.              *
00015  *                                                                                      *
00016  *      This program is distributed in the hope that it will be useful,                 *
00017  *      but WITHOUT ANY WARRANTY; without even the implied warranty of                  *
00018  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU               *
00019  *      Lesser General Public License for more details.                                 *
00020  *                                                                                      *
00021  *      You should have received a copy of the GNU Lesser General Public                *
00022  *      License along with this library; if not, write to the Free Software             *
00023  *      Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA      *
00024  *                                                                                      *
00025  ****************************************************************************************/
00026 
00027 #ifndef DATACONTAINER_H
00028 #define DATACONTAINER_H
00029 
00030 #include <iostream>
00031 #include <map>
00032 #include <string>
00033 #include <vector>
00034 
00035 using namespace std;
00036 
00037 using std::map;
00038 using std::ostream;
00039 
00040 
00041 #include "descriptor.h"
00042 #include "cerror.h"
00043 
00091 class DataContainer {
00092 public:
00093 
00095 
00096 
00098         DataContainer();
00099 
00102         DataContainer( DataContainer& aDataContainer );
00103         //DataContainer& operator= (const DataContainer& aDataContainer);
00104         
00107         virtual ~DataContainer();
00109 
00110 
00112 
00113 
00116         bool hasStringDescriptor( string aLabel );
00117 
00120         bool hasFloatDescriptor( string aLabel );
00121         
00124         bool hasIntDescriptor( string aLabel );
00125 
00127 
00128 
00130 
00131 
00136         Descriptor< int >* addKindIntDescriptor( string aLabel, int aValue, string aUnit, string aComment );
00137 
00142         Descriptor< int >* addKindIntDescriptor(Descriptor< int>* aDescriptor);
00143 
00148         Descriptor< float >* addKindFloatDescriptor( string aLabel, float aValue, string aUnit, string aComment );
00149 
00154         Descriptor< float >* addKindFloatDescriptor(Descriptor< float>* aDescriptor);
00155 
00160         Descriptor< string >* addKindStringDescriptor( string aLabel, string aValue, string aUnit, string aComment );
00161 
00166         Descriptor< string >* addKindStringDescriptor(Descriptor< string>* aDescriptor);
00167 
00171         Descriptor< int >*  addIntDescriptor( string aLabel, int aValue, string aUnit, string aComment );
00172 
00176         Descriptor< float >*  addFloatDescriptor( string aLabel, float aValue, string aUnit, string aComment );
00177 
00181         Descriptor< string >*  addStringDescriptor( string aLabel, string aValue, string aUnit, string aComment );
00182 
00185         Descriptor< int >* setIntDescriptor(string aLabel, int aValue, string aUnit, string aComment, bool addIfMissing, bool silentError );
00186 
00189         Descriptor< float >* setFloatDescriptor(string aLabel, float aValue, string aUnit, string aComment, bool addIfMissing, bool silentError );
00190 
00193         Descriptor< string >* setStringDescriptor(string aLabel, string aValue, string aUnit, string aComment, bool addIfMissing, bool silentError);
00194 
00195 
00198         Descriptor< int >* getIntDescriptor( string aLabel, bool silentError = true ) throw( CError );
00199 
00200 
00203         long getPossibleValuesInIntDescriptor( string aDescriptorName, vector< int >* );
00204 
00207         Descriptor< float >* getFloatDescriptor( string aLabel, bool silentError = true  ) throw( CError );
00208 
00211         Descriptor< string >* getStringDescriptor( string aLabel, bool silentError = true  ) throw( CError );
00212 
00216         virtual bool deleteDescriptor( string aString, bool found = false );
00217 
00221         void deleteAllDescriptors();
00222 
00228         void addUnknownTypeDescriptor( string aName, string aValue );
00229 
00231 
00232 
00233 
00235 
00236 
00239         map< string, Descriptor< int >* >::iterator beginIntDescriptor(){ return( intDescriptors.begin() ); }
00242         map< string, Descriptor< int >* >::iterator endIntDescriptor(){ return( intDescriptors.end() ); }
00243 
00246         map< string, Descriptor< float >* >::iterator beginFloatDescriptor(){ return( floatDescriptors.begin() ); }
00249         map< string, Descriptor< float >* >::iterator endFloatDescriptor(){ return( floatDescriptors.end() ); }
00250 
00253         map< string, Descriptor< string >* >::iterator beginStringDescriptor(){ return( stringDescriptors.begin() ); }
00256         map< string, Descriptor< string >* >::iterator endStringDescriptor(){ return( stringDescriptors.end() ); }
00257 
00259 
00260 
00261 
00262 
00264 
00265 
00267         void describe() throw( CError );
00268 
00271         void describeShort() throw( CError );
00273 
00274 protected:
00275 
00278         bool flagElement;
00279 
00282         void deleteAllKindDescriptors();
00283 
00284 
00285         // Data container provides two different Descriptors:
00286         //   - kind descriptors which are shared by a group of instances of DataContainers
00287         //   - descriptors which are unique to an instance of this class.
00288 
00289         //   Kind descriptors can be created on the heap by this class, but are never deleted.
00290         //       on the other hand descriptors are fully managed by this class. WARNING:
00291         //       Descriptors are deleted by the destructor of this class so they
00292         //   should not be used by reference from elsewhere.
00293 
00294 
00295         // DESCRIPTORS
00296         // Hash of pointers on Descriptor<> to store properties of an instance of
00297         // this class
00298         // Objects in the hash are created by the add***Descriptor function
00299         // Objects are deleted in the deleteDescriptor or the
00300         // deleteAllDescriptors functions (also called by the destructor)
00301 
00304         map< string, Descriptor< int >* > intDescriptors;
00305 
00308         map< string, Descriptor< float >* > floatDescriptors;
00309        
00312         map< string, Descriptor< string >* > stringDescriptors;
00313 
00314 
00315         // KIND DESCRIPTORS
00316         // Hashes of pointers on Descriptor<> to store properties shared by a group of
00317         // instances of this class. The values of these descriptors are shared among the group
00318         // of instances. Example: the kind descriptor symbol with value H
00319         // is shared among all hydrogen instances of the derived class atom.
00320         //
00321         // Objects in these maps can be created by the function
00322         // addKind***Descriptor( string aLabel, float aValue, string aUnit, string aComment )
00323         // which returns a pointer to the created descriptor.
00324         // An already created descriptor can also be included in the map by the function
00325         // addKind***Descriptor( descriptor& )
00326         
00329         map< string, Descriptor< int >* >* kindIntDescriptors;
00330 
00333         map< string, Descriptor< float >* >* kindFloatDescriptors;
00334 
00337         map< string, Descriptor< string >* >* kindStringDescriptors; // Hash of Desriptor<string>
00338 
00339         // Hashes of pointers on Descriptor<string>
00340         // use when datacontainer Class instances should only contain a reference to a Descriptor
00341         // map< string, Descriptor< int >* > intPDescriptors;
00342         // map< string, Descriptor< float >* > floatPDescriptors;
00343         // map< string, Descriptor< string >* > stringPDescriptors;
00344 
00345 };
00346 #endif

Generated on Wed Nov 28 12:12:51 2007 for ChemCpp by  doxygen 1.4.6