2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2012-12-28 20:21:05 +00:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup freestyle
|
|
|
|
|
* \brief Iterators used to iterate over the elements of the Stroke. Can't be used in python
|
2012-12-28 20:21:05 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "Stroke.h"
|
2020-04-21 14:28:26 +02:00
|
|
|
#include "StrokeIterators.h"
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2013-04-09 00:46:49 +00:00
|
|
|
namespace Freestyle {
|
|
|
|
|
|
2008-04-30 15:41:54 +00:00
|
|
|
namespace StrokeInternal {
|
|
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
class vertex_const_traits : public Const_traits<StrokeVertex *> {
|
|
|
|
|
public:
|
|
|
|
|
typedef std::deque<StrokeVertex *> vertex_container;
|
|
|
|
|
typedef vertex_container::const_iterator vertex_container_iterator;
|
|
|
|
|
};
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
class vertex_nonconst_traits : public Nonconst_traits<StrokeVertex *> {
|
|
|
|
|
public:
|
|
|
|
|
typedef std::deque<StrokeVertex *> vertex_container; //! the vertices container
|
|
|
|
|
typedef vertex_container::iterator vertex_container_iterator;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<class Traits>
|
2013-03-11 06:56:51 +00:00
|
|
|
class vertex_iterator_base : public IteratorBase<Traits, BidirectionalIteratorTag_Traits> {
|
2012-12-28 20:21:05 +00:00
|
|
|
public:
|
|
|
|
|
typedef vertex_iterator_base<Traits> Self;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
protected:
|
2013-03-11 06:56:51 +00:00
|
|
|
typedef IteratorBase<Traits, BidirectionalIteratorTag_Traits> parent_class;
|
2012-12-28 20:21:05 +00:00
|
|
|
typedef typename Traits::vertex_container_iterator vertex_container_iterator;
|
|
|
|
|
typedef vertex_iterator_base<vertex_nonconst_traits> iterator;
|
|
|
|
|
typedef vertex_iterator_base<vertex_const_traits> const_iterator;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-30 17:50:57 +10:00
|
|
|
// protected:
|
2012-12-28 20:21:05 +00:00
|
|
|
public:
|
|
|
|
|
vertex_container_iterator _it;
|
|
|
|
|
vertex_container_iterator _begin;
|
|
|
|
|
vertex_container_iterator _end;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
public:
|
|
|
|
|
friend class Stroke;
|
2019-04-30 17:50:57 +10:00
|
|
|
// friend class vertex_iterator;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-03-29 16:50:54 +02:00
|
|
|
inline vertex_iterator_base() : parent_class() {}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
inline vertex_iterator_base(const iterator &iBrother) : parent_class()
|
|
|
|
|
{
|
|
|
|
|
_it = iBrother._it;
|
|
|
|
|
_begin = iBrother._begin;
|
|
|
|
|
_end = iBrother._end;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
inline vertex_iterator_base(const const_iterator &iBrother) : parent_class()
|
|
|
|
|
{
|
|
|
|
|
_it = iBrother._it;
|
|
|
|
|
_begin = iBrother._begin;
|
|
|
|
|
_end = iBrother._end;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-30 17:50:57 +10:00
|
|
|
// protected: //FIXME
|
2012-12-28 20:21:05 +00:00
|
|
|
public:
|
|
|
|
|
inline vertex_iterator_base(vertex_container_iterator it,
|
|
|
|
|
vertex_container_iterator begin,
|
|
|
|
|
vertex_container_iterator end)
|
|
|
|
|
: parent_class()
|
|
|
|
|
{
|
|
|
|
|
_it = it;
|
|
|
|
|
_begin = begin;
|
|
|
|
|
_end = end;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
public:
|
2023-03-29 16:50:54 +02:00
|
|
|
virtual ~vertex_iterator_base() {}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
virtual bool begin() const
|
|
|
|
|
{
|
|
|
|
|
return (_it == _begin) ? true : false;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
virtual bool end() const
|
|
|
|
|
{
|
|
|
|
|
return (_it == _end) ? true : false;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
// operators
|
|
|
|
|
inline Self &operator++() // operator corresponding to ++i
|
|
|
|
|
{
|
|
|
|
|
++_it;
|
|
|
|
|
return *(this);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
/* Operator corresponding to i++, i.e. which returns the value *and then* increments.
|
|
|
|
|
* That's why we store the value in a temp.
|
|
|
|
|
*/
|
|
|
|
|
inline Self operator++(int)
|
|
|
|
|
{
|
|
|
|
|
Self tmp = *this;
|
|
|
|
|
++_it;
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
inline Self &operator--() // operator corresponding to --i
|
|
|
|
|
{
|
|
|
|
|
--_it;
|
|
|
|
|
return *(this);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
inline Self operator--(int)
|
|
|
|
|
{
|
|
|
|
|
Self tmp = *this;
|
|
|
|
|
--_it;
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
// comparibility
|
|
|
|
|
virtual bool operator!=(const Self &b) const
|
|
|
|
|
{
|
|
|
|
|
return (_it != b._it);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
virtual bool operator==(const Self &b) const
|
|
|
|
|
{
|
|
|
|
|
return !(*this != b);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
// dereferencing
|
|
|
|
|
virtual typename Traits::reference operator*() const
|
|
|
|
|
{
|
|
|
|
|
return *(_it);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
virtual typename Traits::pointer operator->() const
|
|
|
|
|
{
|
|
|
|
|
return &(operator*());
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-24 15:57:33 +10:00
|
|
|
/** accessors */
|
2012-12-28 20:21:05 +00:00
|
|
|
inline vertex_container_iterator it() const
|
|
|
|
|
{
|
|
|
|
|
return _it;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
inline vertex_container_iterator getBegin() const
|
|
|
|
|
{
|
|
|
|
|
return _begin;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
inline vertex_container_iterator getEnd() const
|
|
|
|
|
{
|
|
|
|
|
return _end;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // end of namespace StrokeInternal
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2013-04-09 00:46:49 +00:00
|
|
|
} /* namespace Freestyle */
|