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 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 } // namespace Teuchos
00149 
00150 #endif // TEUCHOS_MAP_H

Generated on Thu Sep 18 12:41:17 2008 for Teuchos - Trilinos Tools Package by doxygen 1.3.9.1