Teuchos - Trilinos Tools Package Version of the Day
Teuchos_map.hpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 //
00004 //                    Teuchos: Common Tools Package
00005 //                 Copyright (2004) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00025 //
00026 // ***********************************************************************
00027 // @HEADER
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 } // namespace Teuchos
00152 
00153 #endif // TEUCHOS_MAP_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines