| 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 |
#include "PropertyMap.hpp" |
| 27 |
#include <cassert> |
| 28 |
|
| 29 |
PropertyMap::~PropertyMap(){ |
| 30 |
clearProperties(); |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
PropertyMap::addProperty(GenericData* genData){ |
| 35 |
std::map<std::string, GenericData*>::iterator iter; |
| 36 |
|
| 37 |
assert( genData != NULL); |
| 38 |
|
| 39 |
iter = propMap_.find(genData->getID()); |
| 40 |
|
| 41 |
if (iter == propMap_.end()){ |
| 42 |
propMap_.insert(make_pair(genData->getID(), genData)); |
| 43 |
} |
| 44 |
else |
| 45 |
logger.warn(""); |
| 46 |
|
| 47 |
} |
| 48 |
|
| 49 |
void PropertyMap::removeProperty(std::string& propName){ |
| 50 |
std::map<std::string, GenericData*>::iterator iter; |
| 51 |
|
| 52 |
iter = propMap_.find(propName); |
| 53 |
|
| 54 |
if (iter != propMap.end()){ |
| 55 |
delete iter->second; |
| 56 |
propMap_.erase(iter); |
| 57 |
} |
| 58 |
else |
| 59 |
logger.warn("Can not find property with name: " + propName); |
| 60 |
} |
| 61 |
|
| 62 |
void PropertyMap::clearProperties(){ |
| 63 |
std::map<std::string, GenericData*>::iterator iter; |
| 64 |
|
| 65 |
for (iter = propMap_.begin(); iter != propMap_.end(); ++iter) |
| 66 |
delete iter->second; |
| 67 |
|
| 68 |
propMap_.clear(); |
| 69 |
} |
| 70 |
|
| 71 |
std::vector<std::string> PropertyMap::getPropertyNames(){ |
| 72 |
vector<string> propNames; |
| 73 |
std::map<std::string, GenericData*>::iterator iter; |
| 74 |
|
| 75 |
for (iter = propMap_.begin(); iter != propMap_.end(); ++iter) |
| 76 |
propNames.push_back(iter->first); |
| 77 |
|
| 78 |
return propNames; |
| 79 |
} |
| 80 |
|
| 81 |
std::vector<GenericData*> PropertyMap::getProperties(){ |
| 82 |
vector<GenericData*> properties; |
| 83 |
std::map<std::string, GenericData*>::iterator iter; |
| 84 |
|
| 85 |
for (iter = propMap_.begin(); iter != propMap_.end(); ++iter) |
| 86 |
properties.push_back(iter->second); |
| 87 |
|
| 88 |
return properties; |
| 89 |
} |
| 90 |
|
| 91 |
GenericData* PropertyMap::getPropertyByName(std:string& propName){ |
| 92 |
std::map<std::string, GenericData*>::iterator iter; |
| 93 |
|
| 94 |
iter = propMap_.find(propName); |
| 95 |
|
| 96 |
if (iter != propMap_.end()) |
| 97 |
return iter->second; |
| 98 |
else |
| 99 |
return NULL; |
| 100 |
} |