--- trunk/src/utils/GenericData.hpp 2004/09/24 04:16:43 2 +++ trunk/src/utils/GenericData.hpp 2005/01/12 22:41:40 246 @@ -1,174 +1,264 @@ -#ifndef __GENERICDATA_H__ -#define __GENERICDATA_H__ + /* + * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. + * + * The University of Notre Dame grants you ("Licensee") a + * non-exclusive, royalty free, license to use, modify and + * redistribute this software in source and binary code form, provided + * that the following conditions are met: + * + * 1. Acknowledgement of the program authors must be made in any + * publication of scientific results based in part on use of the + * program. An acceptable form of acknowledgement is citation of + * the article in which the program was described (Matthew + * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher + * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented + * Parallel Simulation Engine for Molecular Dynamics," + * J. Comput. Chem. 26, pp. 252-271 (2005)) + * + * 2. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 3. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * This software is provided "AS IS," without a warranty of any + * kind. All express or implied conditions, representations and + * warranties, including any implied warranty of merchantability, + * fitness for a particular purpose or non-infringement, are hereby + * excluded. The University of Notre Dame and its licensors shall not + * be liable for any damages suffered by licensee as a result of + * using, modifying or distributing the software or its + * derivatives. In no event will the University of Notre Dame or its + * licensors be liable for any lost revenue, profit or data, or for + * direct, indirect, special, consequential, incidental or punitive + * damages, however caused and regardless of the theory of liability, + * arising out of the use of or inability to use software, even if the + * University of Notre Dame has been advised of the possibility of + * such damages. + */ + +/** + * @file GenericData.hpp + * @brief + * @author tlin + * @date 09/20/2004 + * @time 9:30am + * @version 1.0 + */ + +#ifndef UTIL_GENERICDATA_HPP +#define UTIL_GENERICDATA_HPP -#include +#include #include #include +namespace oopse{ -#define ZCONSTIME_ID "ZCONSTIME" -#define ZCONSPARADATA_ID "ZCONSPARA" -#define ZCONSFILENAME_ID "ZCONSFILENAME" -#define ZCONSTOL_ID "ZCONSTOL" -#define ZCONSFORCEPOLICY_ID "ZCONSFORCEPOLICY" -#define ZCONSGAP_ID "ZCONSGAP" -#define ZCONSFIXTIME_ID "ZCONSFIXTIME" -#define ZCONSUSINGSMD_ID "ZCONSUSINGSMD" + /** + * @ class GenericData GenericData.hpp "utils/GenericData.hpp" + * @brief Base class for generic data which is associated with an id + */ + class GenericData{ + public: + GenericData() : id_("UndefinedGenericData"){} -#define CHIVALUE_ID "CHIVALUE" -#define INTEGRALOFCHIDT_ID "INTEGRALOFCHIDT" -#define ETAVALUE_ID "ETAVALUE" + GenericData(const std::string& id) { setID(id); } -using namespace std; -//////////////////////////////////////////////////////////////////////////////// -//Declaration of GenericData -//////////////////////////////////////////////////////////////////////////////// -class GenericData -{ - public: - GenericData(); - GenericData(const GenericData& rhs) { id = rhs.getID(); } - GenericData& operator =(const GenericData& rhs); - virtual ~GenericData() {} + /** virtual destructor */ + virtual ~GenericData() {} - const string& getID() const { return id; } - void setID(const string& rhs) { id = rhs; } - protected: - string id; -}; + /** + * Returns the id of this generic data + * + * @return the id of this generic data + * + * @see #setID + */ + const std::string getID() const { return id_; } -/** - * Something we can improve it here is to use template - */ -//////////////////////////////////////////////////////////////////////////////// -//Declaration of IntData -//////////////////////////////////////////////////////////////////////////////// -class IntData : public GenericData{ + /** + * Sets the id of this generic data + * + * @param id the id to be set + * + * @see #getID + */ + void setID(const std::string& id) { id_ = id; } - public: + + private: + GenericData(const GenericData&); + GenericData& operator=(GenericData&); + std::string id_; - double getData() { return data; } - void setData(int rhs) { data = rhs; } + }; - protected: - int data; -}; + /** + * @class SimpleTypeData + * @brief SimpleTypeData class is a POD repository class + * @warning ElemDataType must be copy constructible, and copy assignable + */ + template class SimpleTypeData : public GenericData{ -//////////////////////////////////////////////////////////////////////////////// -//Declaration of DoubleData -//////////////////////////////////////////////////////////////////////////////// -class DoubleData : public GenericData{ + public: + SimpleTypeData() : GenericData(), data_(ElemDataType()) {} + SimpleTypeData(const std::string& id) : GenericData(id), data_(ElemDataType()) {} + SimpleTypeData(const std::string&id , const ElemDataType& data) : GenericData(id), data_(data) {} + template + SimpleTypeData(const SimpleTypeData& s) { + data_ = s.getData(); + } - public: + SimpleTypeData& operator =(const SimpleTypeData& s) { + if (this == &s) + return *this; + + data_ = s.getData(); + return *this; + } + + template + SimpleTypeData& operator =(const SimpleTypeData& s) { + data_ = s.getData(); + return *this; + } + + /** Returns POD data */ + const ElemDataType& getData() const {return data_;} + ElemDataType& getData() {return data_;} + /** + * Sets POD data + * @data POD data to be set + */ + void setData(const ElemDataType& data) { data_ = data; } - double getData() { return data; } - void setData(double rhs) { data = rhs; } + private: + ElemDataType data_; + }; - protected: - double data; -}; + /** BoolGenericData is a generic data type contains a bool variable */ + typedef SimpleTypeData BoolGenericData; -//////////////////////////////////////////////////////////////////////////////// -//Declaration of StringData -//////////////////////////////////////////////////////////////////////////////// -class StringData : public GenericData{ + /** IntGenericData is a generic data type contains an integer variable */ + typedef SimpleTypeData IntGenericData; - public: - const string& getData() const { return data; } - void setData(const string& rhs) { data = rhs; } - protected: - string data; -}; + /** FloatGenericData is a generic data type contains a float variable */ + typedef SimpleTypeData FloatGenericData; -//////////////////////////////////////////////////////////////////////////////// -//Declaration of BoolData -//////////////////////////////////////////////////////////////////////////////// -class BoolData : public GenericData{ - public: - bool getData() const { return data; } - void setData(const bool rhs) { data = rhs; } - protected: - bool data; + /** DoubleGenericData is a generic data type contains a double variable */ + typedef SimpleTypeData DoubleGenericData; + + /** + * @typedef StringGenericData + * A generic data type contains a std::string variable + * + * @code + * StringGenericData* s = new StringGenericData("MyStringGenericData"); + * PropertyMap propMap; + * GenericData* gdata; + * + * s->setData("OOPSE"); + * propMap->addProperty(s); + * + * gdata = propMap->getPropertyByName("MyStringGenericData"); + * if (gdata != NULL){ + * s = dynamic_cast(gdata); + * if (s != NULL) + * std::cout << s->getData() << std::endl; + * } + * + * @endcode + */ + typedef SimpleTypeData StringGenericData; -}; + /** + * @class STLContainerTypeData + * @brief STL container type generic data which is associated with an id + * + * @template ContainerType + * @template ElemDataType + */ + template > class ContainerType, + typename ElemDataType > + class STLContainerTypeData : public GenericData, public ContainerType{ + public: + typedef STLContainerTypeData SelfType; + typedef ContainerType STLContainerType; -//////////////////////////////////////////////////////////////////////////////// -//Declaration of ZConsParaData -//////////////////////////////////////////////////////////////////////////////// -struct ZConsParaItem { - int zconsIndex; - bool havingZPos; - double zPos; - double kRatio; - bool havingCantVel; - double cantVel; -}; + STLContainerTypeData(const std::string& id) + : GenericData(id), ContainerType () {} + + STLContainerTypeData(const SelfType& s) : SelfType(s){} -class ZConsParaData : public GenericData{ + SelfType& operator =(const SelfType& s){ + if (this == &s) + return *this; - public: - ZConsParaData(); - void addItem(ZConsParaItem& item) {data.push_back(item);} - vector* getData() {return &data;} - void setData(vector& theData) {data = theData;} - void sortByIndex(); - bool isIndexUnique(); + STLContainerType::operator=(s); + return *this; + } + }; - private: - vector data; - }; + /** + * @typedef IntVectorGenericData + * A generic data type contains a std::vector variable. + */ + typedef STLContainerTypeData IntVectorGenericData; -class ZConsParaSortCriterion{ - public: - bool operator ()(const ZConsParaItem& item1, const ZConsParaItem& item2){ - return item1.zconsIndex < item2.zconsIndex; - } + /** + * @typedef IntVectorGenericData + * A generic data type contains a std::vector variable. + */ + typedef STLContainerTypeData FloatVectorGenericData; -}; + /** + * @typedef IntVectorGenericData + * A generic data type contains a std::vector variable. + */ + typedef STLContainerTypeData DoubleVectorGenericData; -//////////////////////////////////////////////////////////////////////////////// -//Declaration of IntData -//////////////////////////////////////////////////////////////////////////////// -class DoubleArrayData : public GenericData{ + /** + * @typedef StringVectorGenericData + * A generic data type contains a std::vector variable. + * + * @code + * StringVectorGenericData* sv = new StringVectorGenericData("MyStringVector"); + * GenericData* gdata; + * PropertyMap propMap; + * std::vector::iterator iter; + * + * sv->push_back("Hello World"); + * sv->push_back("OOPSE"); + * + * propMap.addProperty(sv); + * + * gdata = propMap.getPropertyByName("MyStringVector"); + * + * if (gdata != NULL){ + * + * sv = dynamic_cast(gdata); + * + * if (sv != NULL){ + * for (iter = sv->begin(); iter != sv->end(); ++ iter) + * std::cout << *iter << std::endl; + * } + * } + * @endcode + */ + typedef STLContainerTypeData StringVectorGenericData; - public: - vector getData() const { return data; } - void setData(double* source, int num){ - data.clear(); - for(int i = 0; i < num; i++) - data.push_back(source[i]); - } - protected: - vector data; -}; + /** + * @typedef IntVectorGenericData + * A generic data type contains a std::list > variable. + */ + typedef STLContainerTypeData > IntVectorListGenericData; + +#define CHIVALUE_ID "CHIVALUE" +#define INTEGRALOFCHIDT_ID "INTEGRALOFCHIDT" +#define ETAVALUE_ID "ETAVALUE" -//////////////////////////////////////////////////////////////////////////////// -//Declaration of AtomData -//////////////////////////////////////////////////////////////////////////////// -struct AtomInfo : public GenericData{ - public: - string AtomType; - double pos[3]; - double dipole[3]; -}; - -class AtomData : public GenericData{ - public: - ~AtomData(); - void addAtomInfo(AtomInfo* info) {data.push_back(info);} - void clearAllAtomInfo(); - AtomInfo* beginAtomInfo(vector::iterator& i){ - i = data.begin(); - return i != data.end()? *i : NULL; - } - AtomInfo* nextAtomInfo(vector::iterator& i){ - ++i; - return i != data.end()? *i: NULL; - } - vector getData() {return data;} - int getSize() {return data.size();} - protected: - vector data; -}; - -#endif +} // namespace oopse +#endif //UTIL _GENERICDATA_HPP