/usr/include/BALL/KERNEL/iterator.h is in libball1.4-dev 1.4.3~beta1-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | // -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#ifndef BALL_KERNEL_ITERATOR_H
#define BALL_KERNEL_ITERATOR_H
#ifndef BALL_CONCEPT_BIDIRECTIONALITERATOR_H
# include <BALL/CONCEPT/bidirectionalIterator.h>
#endif
#ifndef BALL_CONCEPT_COMPOSITE_H
# include <BALL/CONCEPT/composite.h>
#endif
/** A macro defining kernel iterators.
This macro allows th definition of arbitrary bidirectional
iterators for kernel container classes.
Multiple iterator definition macros can be included at the same
time, thus enabling the iteration over different types of
kernel objects. Each macro defines beginX()/endX() (const and mutable)
and rendX()/rbeginX() where X is the type of item to iterate over.
*/
#define BALL_KERNEL_DEFINE_ITERATOR_CREATORS(Type) \
Type##Iterator \
begin##Type () \
{ \
return Type##Iterator::begin(*this); \
} \
\
Type##Iterator \
end##Type () \
{ \
return Type##Iterator::end(*this); \
} \
\
Type##ReverseIterator \
rbegin##Type () \
{ \
return Type##ReverseIterator(end##Type ()); \
} \
\
Type##ReverseIterator \
rend##Type () \
{ \
return Type##ReverseIterator(begin##Type ()); \
} \
\
Type##ConstIterator \
begin##Type () const \
{ \
return Type##ConstIterator::begin(*this); \
} \
\
Type##ConstIterator \
end##Type () const \
{ \
return Type##ConstIterator::end(*this); \
} \
\
Type##ConstReverseIterator \
rbegin##Type () const \
{ \
return Type##ConstReverseIterator(end##Type ()); \
} \
\
Type##ConstReverseIterator \
rend##Type () const \
{ \
return Type##ConstReverseIterator(begin##Type ()); \
}
namespace BALL
{
/** Composite Iterator Traits
This class is used in the implementation of the kernel iterators.
It is intended for internal use only.
\par
\ingroup KernelIterators
*/
class BALL_EXPORT CompositeIteratorTraits
{
public:
/** @name Constructors and Destructor
*/
//@{
/// Default constructor
inline CompositeIteratorTraits();
/// Copy constructor
inline CompositeIteratorTraits(const Composite& composite);
/// Detailed constructor
inline CompositeIteratorTraits(const CompositeIteratorTraits& traits);
/// Destructor
inline ~CompositeIteratorTraits() {}
//@}
/** @name Assignment
*/
//@{
/// Assignment operator
inline CompositeIteratorTraits& operator = (const CompositeIteratorTraits& traits);
//@}
/** @name Accessors
*/
//@{
/// Return a pointer to the container the iterator is bound to
Composite* getContainer() { return bound_; }
/// Return a const pointer to the container the iterator is bound to
inline const Composite* getContainer() const { return bound_; }
//@}
/** @name Predicates
*/
//@{
/// Equality operator.
inline bool operator == (const CompositeIteratorTraits& traits) const;
/// Inequality operator.
inline bool operator != (const CompositeIteratorTraits& traits) const;
//@}
/** @name Predicates
*/
//@{
/** Return the current status of the iterator.
If the iterator is bound and its subcomposite iterator is valid,
this predicate returns <tt>true</tt>.
*/
inline bool isValid() const { return ((bound_ != 0) && composite_iterator_.isValid()); }
/// Check whether the iterator is bound to a container.
inline bool isSingular() const { return (bound_ == 0); }
/** Return true if the iterator is at the first element of the container.
@see isSingular
*/
inline bool isBegin() const;
/** Return true if the iterator is beyond the last element of the container.
@exception InvalidIterator if the iterator is <b> singular </b>
@see isSingular
*/
inline bool isEnd() const
{
return composite_iterator_.isEnd();
}
/** Return true if the iterator is at the last element of the container.
@exception InvalidIterator if the iterator is <b> singular </b>
@see isSingular
*/
inline bool isRBegin() const;
/** Return true if the iterator is beyond the first element of the container.
@exception InvalidIterator if the iterator is <b> singular </b>
@see isSingular
*/
inline bool isREnd() const;
//@}
/// Return the current iterator position
inline Composite::CompositeIterator& getPosition() { return composite_iterator_; }
/// Return the current iterator posittion (const method)
inline const Composite::CompositeIterator& getPosition() const { return composite_iterator_; }
/** Invalidate the iterator.
The iterator is separated from its container ( \link isSingular isSingular \endlink is <b>true</b> afterwards)
and its \link SubCompositeIterator SubCompositeIterator \endlink is invalidated as well.
*/
inline void invalidate();
/** Reposition the iterator to the first element of the container.
* @throw Exception::Precondition if the iterator is unbound
* @see isSingular
*/
inline void toBegin();
/** Reposition the iterator after the last element of the container.
* @throw Exception::Precondition if the iterator is unbound
* @see isSingular
*/
inline void toEnd();
/// Return a reference to the current element
inline Composite& getData();
/// Return a const reference to the current element
inline const Composite& getData() const;
/// Increment the iterator by one element.
inline void forward();
/// Decrement the iterator one element
inline void backward();
/** Reposition the (backward) iterator to the last element of the container
* @throw Exception::Precondition if the iterator is unbound
*/
inline void toRBegin();
/** Reposition the (backward) iterator beyond the first element of the container
* @throw Exception::Precondition if the iterator is unbound
*/
inline void toREnd();
/// Assign the current predicate associated with the iterator
inline void setPredicate(const UnaryPredicate<Composite>& predicate) { predicate_ = &predicate; }
/// Return the current predicate associated with the iterator
inline const UnaryPredicate<Composite>* getPredicate() const { return predicate_; }
protected:
/// The pointer to the container
Composite* bound_;
/// The internal iterator to iterate over the current node's children
Composite::CompositeIterator composite_iterator_;
/// The predicate
const UnaryPredicate<Composite>* predicate_;
};
inline CompositeIteratorTraits::CompositeIteratorTraits()
: bound_(0),
composite_iterator_(),
predicate_(0)
{
}
inline CompositeIteratorTraits::CompositeIteratorTraits(const Composite& composite)
: bound_(const_cast<Composite*>(&composite)),
composite_iterator_(const_cast<Composite&>(composite).beginComposite()),
predicate_(0)
{
}
inline CompositeIteratorTraits::CompositeIteratorTraits(const CompositeIteratorTraits& traits)
: bound_(traits.bound_),
composite_iterator_(traits.composite_iterator_),
predicate_(traits.predicate_)
{
}
inline CompositeIteratorTraits& CompositeIteratorTraits::operator = (const CompositeIteratorTraits& traits)
{
bound_ = traits.bound_;
composite_iterator_ = traits.composite_iterator_;
predicate_ = traits.predicate_;
return *this;
}
inline bool CompositeIteratorTraits::operator == (const CompositeIteratorTraits& traits) const
{
return ((composite_iterator_ == traits.composite_iterator_) && (bound_ == traits.bound_));
}
inline bool CompositeIteratorTraits::operator != (const CompositeIteratorTraits& traits) const
{
return !this->operator == (traits);
}
inline void CompositeIteratorTraits::invalidate()
{
bound_ = 0;
composite_iterator_.invalidate();
}
inline void CompositeIteratorTraits::toBegin()
{
BALL_PRECONDITION_EXCEPTION((bound_ != 0), "cannot move unbound iterator to begin")
composite_iterator_ = bound_->beginComposite();
while (+composite_iterator_ && (predicate_->operator () (*composite_iterator_) == false))
{
++composite_iterator_;
}
}
inline bool CompositeIteratorTraits::isBegin() const
{
if (isSingular())
{
return false;
}
try
{
Composite::CompositeIterator sub_iterator(bound_->beginComposite());
while (+sub_iterator && (predicate_->operator () (*sub_iterator) == false))
{
++sub_iterator;
}
return (composite_iterator_ == sub_iterator);
}
catch (Exception::Precondition&)
{
}
return false;
}
inline void CompositeIteratorTraits::toEnd()
{
composite_iterator_.toEnd();
}
inline Composite& CompositeIteratorTraits::getData()
{
return const_cast<Composite&>(*composite_iterator_);
}
inline const Composite& CompositeIteratorTraits::getData() const
{
return *composite_iterator_;
}
inline void CompositeIteratorTraits::forward()
{
++composite_iterator_;
while (+composite_iterator_ && (predicate_->operator () (*composite_iterator_) == false))
{
++composite_iterator_;
}
}
inline void CompositeIteratorTraits::toRBegin()
{
BALL_PRECONDITION_EXCEPTION(!isSingular(), "cannot move singular iterator to reverse begin")
composite_iterator_ = --bound_->endComposite();
while (+composite_iterator_ && (predicate_->operator () (*composite_iterator_) == false))
{
--composite_iterator_;
}
}
inline bool CompositeIteratorTraits::isRBegin() const
{
if (isSingular())
{
return false;
}
Composite::CompositeIterator sub_iterator = --bound_->endComposite();
while (+sub_iterator && (predicate_->operator () (*sub_iterator) == false))
{
--sub_iterator;
}
return (composite_iterator_ == sub_iterator);
}
inline void CompositeIteratorTraits::toREnd()
{
composite_iterator_.toREnd();
}
inline bool CompositeIteratorTraits::isREnd() const
{
if (isSingular())
{
return false;
}
return composite_iterator_.isREnd();
}
inline void CompositeIteratorTraits::backward()
{
--composite_iterator_;
while (+composite_iterator_ && (predicate_->operator () (*composite_iterator_) == false))
{
--composite_iterator_;
}
}
} // namespace BALL
#endif // BALL_KERNEL_ITERATOR_H
|