| 1 | /* | 
| 2 | * Copyright (C) 2000-2004  Object Oriented Parallel Simulation Engine (OOPSE) project | 
| 3 | * | 
| 4 | * Contact: oopse@oopse.org | 
| 5 | * | 
| 6 | * This program is free software; you can redistribute it and/or | 
| 7 | * modify it under the terms of the GNU Lesser General Public License | 
| 8 | * as published by the Free Software Foundation; either version 2.1 | 
| 9 | * of the License, or (at your option) any later version. | 
| 10 | * All we ask is that proper credit is given for our work, which includes | 
| 11 | * - but is not limited to - adding the above copyright notice to the beginning | 
| 12 | * of your source code files, and to any copyright notice that you may distribute | 
| 13 | * with programs based on this work. | 
| 14 | * | 
| 15 | * This program is distributed in the hope that it will be useful, | 
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
| 18 | * GNU Lesser General Public License for more details. | 
| 19 | * | 
| 20 | * You should have received a copy of the GNU Lesser General Public License | 
| 21 | * along with this program; if not, write to the Free Software | 
| 22 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. | 
| 23 | * | 
| 24 | */ | 
| 25 |  | 
| 26 | /** | 
| 27 | * @file PropertyMap.hpp | 
| 28 | * @author tlin | 
| 29 | * @date 09/21/2004 | 
| 30 | * @time 9:20am | 
| 31 | * @version 1.0 | 
| 32 | */ | 
| 33 |  | 
| 34 | #ifndef UTIL_PROPERTYMAP_HPP | 
| 35 | #define UTIL_PROPERTYMAP_HPP | 
| 36 |  | 
| 37 | #include <map> | 
| 38 | #include <string> | 
| 39 | #include <vector> | 
| 40 |  | 
| 41 | #include <GenericData.hpp> | 
| 42 |  | 
| 43 | namespace oopse{ | 
| 44 |  | 
| 45 | /** | 
| 46 | * @class PropertyMap | 
| 47 | * PropertyMap class maintains a list of GenericData. Type of Property is actually GenericData. | 
| 48 | */ | 
| 49 | class PropertyMap{ | 
| 50 | public: | 
| 51 |  | 
| 52 | /** trivial constructor */ | 
| 53 | PropertyMap(); | 
| 54 |  | 
| 55 | /** | 
| 56 | * Virtual Destructor responsible for deleting all of the generc data in PropertyMap | 
| 57 | */ | 
| 58 | virtual ~PropertyMap(); | 
| 59 |  | 
| 60 | /** | 
| 61 | * Adds property into property map | 
| 62 | * | 
| 63 | * @param genData GenericData to be added into PropertyMap | 
| 64 | * | 
| 65 | * @see #removeProperty | 
| 66 | * @see #clearProperties | 
| 67 | */ | 
| 68 | void addProperty(GenericData* genData); | 
| 69 |  | 
| 70 | /** | 
| 71 | * Removes property from PropertyMap by name | 
| 72 | * | 
| 73 | * @param propName the name of property to be removed | 
| 74 | * | 
| 75 | * @see #addProperty | 
| 76 | * @see #clearProperties | 
| 77 | */ | 
| 78 | void removeProperty(std::string& propName); | 
| 79 |  | 
| 80 | /** | 
| 81 | * clear all of the properties | 
| 82 | * | 
| 83 | * @see #addProperty | 
| 84 | * @see #removeProperty | 
| 85 | */ | 
| 86 | void clearProperties(); | 
| 87 |  | 
| 88 | /** | 
| 89 | * Returns all names of properties | 
| 90 | * | 
| 91 | * @return all names of properties | 
| 92 | */ | 
| 93 | std::vector<std::string> getPropertyNames(); | 
| 94 |  | 
| 95 | /** | 
| 96 | * Returns all of the properties in PropertyMap | 
| 97 | * | 
| 98 | * @return all of the properties in PropertyMap | 
| 99 | * | 
| 100 | * @see #getPropertyByName | 
| 101 | */ | 
| 102 | std::vector<GenericData*> getProperties(); | 
| 103 |  | 
| 104 | /** | 
| 105 | * Returns property | 
| 106 | * | 
| 107 | * @param propName name of property | 
| 108 | * | 
| 109 | * @return a pointer point to property with propName. If no property named propName | 
| 110 | * exists, return NULL | 
| 111 | * | 
| 112 | * @see #getProperties | 
| 113 | */ | 
| 114 | GenericData* getPropertyByName(std:string& propName); | 
| 115 | template<typename T = GenericData*> T getPropertyByName(std:string& propName); | 
| 116 |  | 
| 117 | protected: | 
| 118 | std::map<std::string, GenericData*> propMap_; | 
| 119 |  | 
| 120 | private: | 
| 121 |  | 
| 122 | /** prevent copy constructing */ | 
| 123 | PropertyMap(const PropertyMap&); | 
| 124 |  | 
| 125 | /** prevent copy assignment */ | 
| 126 | PropertyMap& operator=(const PropertyMap&); | 
| 127 | }; | 
| 128 |  | 
| 129 | }// namespace oopse | 
| 130 | #endif //UTIL_PROPERTYMAP_HPP |