00001 /// @addtogroup unifexp 00002 /// @{ 00003 00004 ///////////////////////////////////////////////////////////////////////////// 00005 /// 00006 /// @file parttypes.h 00007 /// 00008 /// This file contains the definition of a class which gathers all the 00009 /// available partition types and allows to select a partition class object 00010 /// by its name. 00011 /// 00012 /// @author Pawel Pilarczyk 00013 /// 00014 ///////////////////////////////////////////////////////////////////////////// 00015 00016 // Copyright (C) 2007 by Pawel Pilarczyk. 00017 // 00018 // This file is part of my research program package. This is free software; 00019 // you can redistribute it and/or modify it under the terms of the GNU 00020 // General Public License as published by the Free Software Foundation; 00021 // either version 2 of the License, or (at your option) any later version. 00022 // 00023 // This software is distributed in the hope that it will be useful, 00024 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00025 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00026 // GNU General Public License for more details. 00027 // 00028 // You should have received a copy of the GNU General Public License along 00029 // with this software; see the file "license.txt". If not, write to the 00030 // Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 00031 // MA 02111-1307, USA. 00032 00033 // Started on August 22, 2007. Last revision: August 22, 2007. 00034 00035 #ifndef _parttypes_h_ 00036 #define _parttypes_h_ 00037 00038 // some standard C++ headers 00039 #include <vector> 00040 #include <string> 00041 #include <iostream> 00042 00043 // the abstract partition type header 00044 #include "parttype.h" 00045 00046 // all the available partition type headers 00047 #include "partunif.h" 00048 #include "partsegm.h" 00049 #include "partcrit.h" 00050 #include "partderiv.h" 00051 00052 // ADD YOUR HEADERS HERE (and don't forget to add your objects below) 00053 00054 00055 00056 namespace unifexp { 00057 00058 // -------------------------------------------------- 00059 // ---------------- partition types ----------------- 00060 // -------------------------------------------------- 00061 00062 /// This class gathers all the available partition types and allows 00063 /// to select a partition class object by its name. 00064 template <class numType> 00065 class partTypes 00066 { 00067 public: 00068 /// The constructor. 00069 partTypes (); 00070 00071 /// The destructor. 00072 ~partTypes (); 00073 00074 /// Retrieves a pointer to a partition object with the given name. 00075 /// Returns 0 if such an object cannot be found. 00076 partType<numType> *get (const std::string &name) const; 00077 00078 /// Fills in a vector of text strings with the names 00079 /// of all the available partition objects. 00080 void getNames (std::vector<std::string> &names) const; 00081 00082 private: 00083 /// The copy constructor is not allowed. 00084 partTypes (const partTypes<numType> &); 00085 00086 /// The assignment operator is not allowed. 00087 partTypes<numType> &operator = (const partTypes<numType> &); 00088 00089 /// A vector of all the map objects to choose from. 00090 /// The objects must be created with the 'new' operator. 00091 /// They are automatically deallocated by the destructor. 00092 std::vector<partType<numType> *> objects; 00093 00094 }; /* class partTypes */ 00095 00096 // -------------------------------------------------- 00097 00098 template <class numType> 00099 inline partTypes<numType>::partTypes () 00100 { 00101 // add objects of all map types 00102 objects. push_back (new partUniform<numType> ()); 00103 objects. push_back (new partSegmented<numType> ()); 00104 objects. push_back (new partCritical<numType> ()); 00105 objects. push_back (new partDerivative<numType> ()); 00106 00107 // ADD YOUR OBJECTS HERE 00108 00109 00110 return; 00111 } /* partTypes::partTypes */ 00112 00113 template <class numType> 00114 inline partTypes<numType>::~partTypes () 00115 { 00116 for (typename std::vector<partType<numType> *>::iterator iter = 00117 objects. begin (); iter != objects. end (); ++ iter) 00118 { 00119 delete *iter; 00120 } 00121 return; 00122 } /* partTypes::~partTypes */ 00123 00124 template <class numType> 00125 inline partTypes<numType>::partTypes (const partTypes<numType> &) 00126 { 00127 throw "Copy constructor not implemented for the partitions class."; 00128 return; 00129 } /* partTypes::partTypes */ 00130 00131 template <class numType> 00132 inline partTypes<numType> &partTypes<numType>::operator = 00133 (const partTypes<numType> &) 00134 { 00135 throw "Assignment operator not implemented " 00136 "for the partitions class."; 00137 return *this; 00138 } /* partTypes::operator = */ 00139 00140 template <class numType> 00141 inline partType<numType> *partTypes<numType>::get (const std::string &name) 00142 const 00143 { 00144 for (typename std::vector<partType<numType> *>::const_iterator 00145 iter = objects. begin (); iter != objects. end (); ++ iter) 00146 { 00147 if ((*iter) -> name () == name) 00148 return *iter; 00149 } 00150 return 0; 00151 } /* partTypes::get */ 00152 00153 template <class numType> 00154 inline void partTypes<numType>::getNames (std::vector<std::string> &names) 00155 const 00156 { 00157 for (typename std::vector<partType<numType> *>::const_iterator 00158 iter = objects. begin (); iter != objects. end (); ++ iter) 00159 { 00160 names. push_back ((*iter) -> name ()); 00161 } 00162 return; 00163 } /* partTypes::getNames */ 00164 00165 00166 } // namespace unifexp 00167 00168 #endif // _parttypes_h_ 00169 00170 /// @} 00171