|
From: Christian P. <cp...@us...> - 2005-01-14 14:53:10
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20723/include/pclasses Added Files: PropertyMap.h Log Message: Added simple PropertyMap. --- NEW FILE: PropertyMap.h --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_PropertyMap_h #define P_PropertyMap_h #include <map> #include <string> namespace P { template <typename KeyType, typename ValueType> class PropertyMap { public: typedef std::map<KeyType, ValueType> FieldMap; typedef typename FieldMap::iterator iterator; typedef typename FieldMap::const_iterator const_iterator; PropertyMap() {} ~PropertyMap() {} void set(const KeyType& key, const ValueType& val) { _fields[key] = val; } const ValueType& get(const KeyType& key) const { static KeyType empty = KeyType(); const_iterator i = _fields.find(key); if(i != _fields.end()) return i->second; return empty; } bool remove(const KeyType& key) { _fields.erase(key); } bool isset(const KeyType& key) const { return _fields.find(key) != _fields.end(); } iterator find(const KeyType& key) { return _fields.find(key); } const_iterator find(const KeyType& key) const { return _fields.find(key); } inline const_iterator begin() const { return _fields.begin(); } inline const_iterator end() const { return _fields.end(); } inline iterator begin() { return _fields.begin(); } inline iterator end() { return _fields.end(); } std::string& operator[](const KeyType& key) { return _fields[key]; } const std::string& operator[](const KeyType& key) const { return _fields[key]; } private: FieldMap _fields; }; } #endif |