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 #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 }
00145
00146 #endif // OPENMS_ANALYSIS_MAPMATCHING_GROUP_H