Teuchos_map.hpp
Go to the documentation of this file.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 std::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
00065
00067 std::map() {}
00068
00070 std::map( const std::map<Key,T>& map_in ) : list_( map_in.list_ ) {}
00071
00073 virtual ~std::map() {}
00075
00077
00078
00080 iterator begin() { return list_.begin(); }
00081
00083 const_iterator begin() const { return list_.begin(); }
00084
00086 iterator end() { return list_.end(); }
00087
00089 const_iterator end() const { return list_.end(); }
00090
00092
00096 mapped_type& operator[]( const key_type& k )
00097 {
00098 iterator itr = find(k);
00099 if(itr != end()) return (*itr).second;
00100 list_.push_back( value_type( k, T() ) );
00101 return list_.back().second;
00102 }
00104
00106
00107
00109
00113 iterator find(const key_type& k)
00114 {
00115 for( iterator itr = begin(); itr != end(); ++itr ) {
00116 if( (*itr).first == k ) {
00117 return itr;
00118 }
00119 }
00120 return end();
00121 }
00122
00124
00128 const_iterator find(const key_type& k) const
00129 {
00130 for( const_iterator itr = begin(); itr != end(); ++itr ) {
00131 if( (*itr).first == k ) {
00132 return itr;
00133 }
00134 }
00135 return end();
00136 }
00137
00138 bool empty() const { return list_.empty(); }
00139
00141 private:
00142 list_t list_;
00143 };
00144
00145 #else
00146
00147 using std::map;
00148
00149 #endif
00150
00151 }
00152
00153 #endif // TEUCHOS_MAP_H