Avogadro
1.1.0
|
00001 /********************************************************************** 00002 PrimitiveList - Organized List of Primitives. 00003 00004 Copyright (C) 2007 Donald Ephraim Curtis 00005 00006 This file is part of the Avogadro molecular editor project. 00007 For more information, see <http://avogadro.openmolecules.net/> 00008 00009 Avogadro is free software; you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation; either version 2 of the License, or 00012 (at your option) any later version. 00013 00014 Avogadro 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 00017 GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License 00020 along with this program; if not, write to the Free Software 00021 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00022 02110-1301, USA. 00023 **********************************************************************/ 00024 00025 #ifndef PRIMITIVELIST_H 00026 #define PRIMITIVELIST_H 00027 00028 #include <avogadro/global.h> 00029 #include <avogadro/primitive.h> 00030 00031 #include <QVector> 00032 #include <QList> 00033 00034 namespace Avogadro 00035 { 00036 00046 class PrimitiveListPrivate; 00047 class A_EXPORT PrimitiveList 00048 { 00049 public: 00053 PrimitiveList(); 00054 PrimitiveList( const PrimitiveList &other ); 00055 PrimitiveList( const QList<Primitive *> &other ); 00056 00057 PrimitiveList &operator=( const PrimitiveList &other ); 00058 PrimitiveList &operator=(const QList<Primitive *> &other); 00059 00063 ~PrimitiveList(); 00064 00071 QList<Primitive *> subList( Primitive::Type type ) const; 00072 00078 QList<Primitive *> list() const; 00079 00084 bool contains( const Primitive *p ) const; 00085 00091 void append( Primitive *p ); 00092 00099 void removeAll( Primitive *p ); 00100 00104 int size() const; 00105 00109 bool isEmpty() const; 00110 00115 int count( Primitive::Type type ) const; 00116 00121 int count() const; 00122 00126 void clear(); 00127 00128 private: 00129 PrimitiveListPrivate * const d; 00130 00131 public: 00132 00133 class const_iterator 00134 { 00135 public: 00136 QVector< QList<Primitive *> > *vl; 00137 QVector< QList<Primitive *> >::const_iterator vit; 00138 QList<Primitive *>::const_iterator lit; 00139 00140 inline const_iterator(QVector< QList<Primitive *> > *p) : vl(p) 00141 { 00142 vit = vl->constBegin(); 00143 lit = (*vit).constBegin(); 00144 while(lit == (*vit).constEnd()) 00145 { 00146 vit++; 00147 if(vit != vl->constEnd()) 00148 { 00149 lit = (*vit).constBegin(); 00150 } 00151 else 00152 { 00153 break; 00154 } 00155 } 00156 } 00157 00158 inline Primitive* operator*() const { return *lit; } 00159 inline const_iterator operator++(int) { 00160 const_iterator p = *this; 00161 ++(*this); 00162 return p; 00163 } 00164 00165 inline const_iterator &operator++() 00166 { 00167 if(vit != vl->constEnd()) 00168 { 00169 lit++; 00170 while(lit == (*vit).constEnd()) 00171 { 00172 vit++; 00173 00174 if(vit == vl->constEnd()) 00175 { 00176 break; 00177 } 00178 lit = (*vit).constBegin(); 00179 } 00180 } 00181 return *this; 00182 } 00183 00184 inline bool operator!=(const const_iterator &o) const 00185 { 00186 return !(vit == vl->constEnd() && o.vit == vl->constEnd()) && 00187 !(vit == o.vit && lit == o.lit); 00188 } 00189 00190 inline bool operator==(const const_iterator &o) const 00191 { // equal if both are at the end 00192 return (vit == vl->constEnd() && o.vit == vl->constEnd()) || 00193 (vit == o.vit && lit == o.lit); 00194 } 00195 }; 00196 00197 const_iterator begin() const; 00198 const_iterator end() const; 00199 00200 00201 }; 00202 00203 } // namespace Avogadro 00204 00205 #endif // __PRIMITIVELIST_H