"Fossies" - the Fresh Open Source Software Archive

Member "qdiff-0.9.1/tmap.h" (21 Oct 2008, 2142 Bytes) of package /linux/privat/old/qdiff-0.9.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "tmap.h" see the Fossies "Dox" file reference documentation.

    1 /*GPL*START*
    2  * 
    3  * tmap<> class template -- improved stl map<>
    4  * 
    5  * Copyright (C) 2000-2001 by Johannes Overmann <Johannes.Overmann@gmx.de>
    6  * 
    7  * This program is free software; you can redistribute it and/or modify
    8  * it under the terms of the GNU General Public License as published by
    9  * the Free Software Foundation; either version 2 of the License, or
   10  * (at your option) any later version.
   11  * 
   12  * This program is distributed in the hope that it will be useful,
   13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15  * GNU General Public License for more details.
   16  * 
   17  * You should have received a copy of the GNU General Public License
   18  * along with this program; if not, write to the Free Software
   19  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   20  * *GPL*END*/  
   21 
   22 #ifndef _ngw_tmap_h_
   23 #define _ngw_tmap_h_
   24 
   25 
   26 #ifdef DONT_USE_STL
   27 # include "ttmap.h"
   28 # define tmap_base ttmap
   29 #else
   30 # include <map>
   31 # define tmap_base map
   32 using namespace std;
   33 #endif
   34 
   35 
   36 #include "texception.h"
   37 
   38 // history: start 08 Jul 2000
   39 // 2000:
   40 // 08 Jul: removing tarray and tassocarray, this should provide tmap and tvector
   41 // 2001:
   42 // 15 Sep: DONT_USE_STL feature added
   43 // 16 Sep: splittet tstl.h into tvector.h and tmap.h
   44 
   45 
   46 template<class K, class T>
   47 class tmap: public tmap_base<K,T> {
   48  public:
   49    // 1:1 wrapper
   50 
   51    /// access element (read/write) (this is needed for some strange reason)
   52    T& operator[](const K& key) { return tmap_base<K,T>::operator[](key); };
   53 
   54    // new functionality
   55 
   56    /// return whether an element with key is contained or not
   57     bool contains(const K& key) const { return find(key) != tmap_base<K,T>::end(); }
   58    /// access element read only (const)
   59 // g++ 2.95.2 does not allow this:
   60 // const T& operator[](const K& key) const { const_iterator i = find(key); if(i != end()) return i->second; else throw TNotFoundException(); } // throw(TNotFoundException)
   61    const T& operator[](const K& key) const { if(contains(key)) return find(key)->second; else throw TNotFoundException(); } // throw(TNotFoundException)
   62 };
   63 
   64 
   65 #endif /* _ngw_tmap_h_ */
   66