00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef TEUCHOS_MAP_H
00030 #define TEUCHOS_MAP_H
00031
00036 #include "Teuchos_ConfigDefs.hpp"
00037
00049 namespace Teuchos {
00050
00051 #ifdef TFLOP
00052
00053 template<class Key, class T>
00054 class map {
00055 public:
00056 typedef Key key_type;
00057 typedef T mapped_type;
00058 typedef std::pair<Key,T> value_type;
00059 typedef std::list<value_type> list_t;
00060 typedef typename list_t::iterator iterator;
00061 typedef typename list_t::const_iterator const_iterator;
00062
00064
00066 map() {}
00067
00069 map( const map<Key,T>& map_in ) : list_( map_in.list_ ) {}
00070
00072 virtual ~map() {}
00074
00076
00078 iterator begin() { return list_.begin(); }
00079
00081 const_iterator begin() const { return list_.begin(); }
00082
00084 iterator end() { return list_.end(); }
00085
00087 const_iterator end() const { return list_.end(); }
00088
00090
00094 mapped_type& operator[]( const key_type& k )
00095 {
00096 iterator itr = find(k);
00097 if(itr != end()) return (*itr).second;
00098 list_.push_back( value_type( k, T() ) );
00099 return list_.back().second;
00100 }
00102
00104
00106
00110 iterator find(const key_type& k)
00111 {
00112 for( iterator itr = begin(); itr != end(); ++itr ) {
00113 if( (*itr).first == k ) {
00114 return itr;
00115 }
00116 }
00117 return end();
00118 }
00119
00121
00125 const_iterator find(const key_type& k) const
00126 {
00127 for( const_iterator itr = begin(); itr != end(); ++itr ) {
00128 if( (*itr).first == k ) {
00129 return itr;
00130 }
00131 }
00132 return end();
00133 }
00134
00135 bool empty() const { return list_.empty(); }
00136
00138 private:
00139 list_t list_;
00140 };
00141
00142 #else
00143
00144 using std::map;
00145
00146 #endif
00147
00148 }
00149
00150 #endif // TEUCHOS_MAP_H