00001 // -*- mode: C++ -*- 00002 #ifndef MiX_ATTRMAP_H_ 00003 #define MiX_ATTRMAP_H_ 00004 00005 #include <vector> 00006 #include "XMLString.h" 00007 #include "misc.h" 00008 00009 namespace MiX{ 00010 template <class charT,class char_traits,class xml_traits> 00011 class AttrMap { 00012 public: 00013 MiX_Template_Typedef(charT,char_traits,xml_traits); 00014 typedef std::pair<string_type,string_type> val_type; 00015 typedef std::vector<val_type> container_type; 00016 typedef typename container_type::iterator iterator; 00017 typedef typename container_type::const_iterator const_iterator; 00018 private: 00019 container_type impl_; 00020 struct search_by_key{ 00021 string_type key_; 00022 search_by_key(const string_type& key) : key_(key) { }; 00023 bool operator()(const val_type& v){ return v.first==key_; } 00024 }; 00025 00026 public: 00028 AttrMap(){ impl_.clear(); } 00030 iterator begin() { return impl_.begin(); } 00032 iterator end() { return impl_.end(); } 00034 const_iterator begin()const{ return impl_.begin(); } 00036 const_iterator end()const{ return impl_.end(); } 00038 size_t size()const{ return impl_.size(); } 00040 bool empty()const{ return impl_.empty(); } 00042 void insert(const val_type& data){ impl_.push_back(data); } 00044 void clear(){ impl_.clear(); } 00046 iterator find(const string_type& key){ 00047 return find_if(begin(),end(),search_by_key(key)); 00048 } 00050 const_iterator find(const string_type key)const{ 00051 return find_if(begin(),end(),search_by_key(key)); 00052 } 00054 void erase(const string_type key){ 00055 iterator it = find(key); 00056 if(it!=end()) impl_.erase(it); 00057 } 00059 string_type operator[](const string_type& key) const; 00060 }; 00061 } 00062 00063 #ifndef MiX_ATTRMAP_CPP_ 00064 #include "AttrMap.cpp" 00065 #endif 00066 00067 #endif