00001
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{
00016 template <class charT,class traitsT>
00017 class AttrMap {
00018 public:
00019 MiX_Template_Typedef(charT,traitsT);
00020 typedef std::pair<string_type,string_type> val_type;
00021 typedef std::vector<val_type> container_type;
00022 typedef typename container_type::iterator iterator;
00023 typedef typename container_type::const_iterator const_iterator;
00024 private:
00025 container_type impl_;
00026 struct search_by_key{
00027 string_type key_;
00028 search_by_key(const string_type& key) : key_(key) { };
00029 bool operator()(const val_type& v){ return v.first==key_; }
00030 };
00031
00032 public:
00034 AttrMap(){ impl_.clear(); }
00036 iterator begin() { return impl_.begin(); }
00038 iterator end() { return impl_.end(); }
00040 const_iterator begin()const{ return impl_.begin(); }
00042 const_iterator end()const{ return impl_.end(); }
00044 size_t size()const{ return impl_.size(); }
00046 bool empty()const{ return impl_.empty(); }
00048 void insert(const val_type& data){ impl_.push_back(data); }
00050 void clear(){ impl_.clear(); }
00052 iterator find(const string_type& key){
00053 return find_if(begin(),end(),search_by_key(key));
00054 }
00056 const_iterator find(const string_type key)const{
00057 return find_if(begin(),end(),search_by_key(key));
00058 }
00060 void erase(const string_type key){
00061 iterator it = find(key);
00062 if(it!=end()) impl_.erase(it);
00063 }
00065 string_type operator[](const string_type& key) const;
00066 };
00067 }
00068
00069 #ifndef MIX_ATTRMAP_CPP_
00070 #include "AttrMap.cpp"
00071 #endif//MIX_ATTRMAP_CPP_
00072
00073 #endif