Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages

Group.h (Maintainer: Eva Lange)

Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 // --------------------------------------------------------------------------
00005 //                   OpenMS Mass Spectrometry Framework
00006 // --------------------------------------------------------------------------
00007 //  Copyright (C) 2003-2008 -- Oliver Kohlbacher, Knut Reinert
00008 //
00009 //  This library is free software; you can redistribute it and/or
00010 //  modify it under the terms of the GNU Lesser General Public
00011 //  License as published by the Free Software Foundation; either
00012 //  version 2.1 of the License, or (at your option) any later version.
00013 //
00014 //  This library is distributed in the hope that it will be useful,
00015 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 //  Lesser General Public License for more details.
00018 //
00019 //  You should have received a copy of the GNU Lesser General Public
00020 //  License along with this library; if not, write to the Free Software
00021 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 // --------------------------------------------------------------------------
00024 // $Maintainer: Eva Lange $
00025 // --------------------------------------------------------------------------
00026 
00027 #ifndef OPENMS_ANALYSIS_MAPMATCHING_GROUP_H
00028 #define OPENMS_ANALYSIS_MAPMATCHING_GROUP_H
00029 
00030 #include <OpenMS/ANALYSIS/MAPMATCHING/IndexTuple.h>
00031 #include <OpenMS/DATASTRUCTURES/String.h>
00032 
00033 #include <set>
00034 
00035 namespace OpenMS
00036 {
00042   template < typename ContainerType >
00043   class Group : public std::set
00044           < IndexTuple< ContainerType >, typename IndexTuple< ContainerType >::IndexLess >
00045     {
00046     public:
00047       typedef std::set
00048         < IndexTuple< ContainerType >, typename IndexTuple< ContainerType >::IndexLess > Base;
00049 
00052       typedef typename Base::iterator iterator;
00053       typedef typename Base::const_iterator const_iterator;
00054       typedef typename Base::reverse_iterator reverse_iterator;
00055       typedef typename Base::const_reverse_iterator const_reverse_iterator;
00056       typedef typename Base::value_type value_type;
00057       typedef typename Base::reference reference;
00058       typedef typename Base::const_reference const_reference;
00059       typedef typename Base::pointer pointer;
00060       typedef typename Base::difference_type difference_type;
00061       typedef typename Base::size_type size_type;
00063 
00064       typedef IndexTuple< ContainerType > Element;
00065 
00067       Group() : Base()
00068     {}
00069 
00071       inline Group(const Group& source)
00072           : Base(source)
00073       {}
00074 
00076       Group& operator= (const Group& source)
00077       {
00078         if (&source == this)
00079           return *this;
00080 
00081         Base::operator=(source);
00082         return *this;
00083       }
00084 
00086       virtual ~Group()
00087     {}
00088 
00090       inline unsigned int count() const
00091       {
00092         return this->size();
00093       }
00094 
00096       inline bool isEmpty()
00097       {
00098         return (this->size() == 0);
00099       }
00100 
00102       std::pair< typename Base::iterator, bool >
00103       insert(const Element& elem) throw (Exception::InvalidValue)
00104       {
00105         std::pair< typename Base::iterator, bool > pr;
00106         pr = Base::insert(elem);
00107 
00108         if (pr.second == false)
00109         {
00110           throw Exception::InvalidValue(__FILE__, __LINE__, __PRETTY_FUNCTION__,"The set already contained an element with this key.",(String)(elem.getMapIndex())) ;
00111         }
00112         else
00113         {
00114           return pr;
00115         }
00116       }
00117 
00119       virtual bool operator == (const Group& group) const
00120       {
00121         return std::operator==(group,*this);
00122       }
00123 
00125       virtual bool operator != (const Group& group) const
00126       {
00127         return !(std::operator==(group,*this));
00128       }
00129     };
00130 
00132   template < typename ContainerT >
00133   std::ostream& operator << (std::ostream& os, const Group<ContainerT>& cons)
00134   {
00135     os << "---------- GROUP BEGIN -----------------\n";
00136     unsigned int i=0;
00137     for (typename Group<ContainerT>::const_iterator it = cons.begin(); it != cons.end(); ++it,i)
00138     {
00139       os  << "Element: " << i << '\n'
00140       << it << std::endl;
00141     }
00142     return os;
00143   }
00144 } // namespace OpenMS
00145 
00146 #endif // OPENMS_ANALYSIS_MAPMATCHING_GROUP_H

Generated Tue Apr 1 15:36:34 2008 -- using doxygen 1.5.4 OpenMS / TOPP 1.1