Commit 6684837b authored by Jan Möbius's avatar Jan Möbius
Browse files

Introduced animation iterator

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@13092 383ad7c9-94d9-4d36-a494-682f7c89f535
parent b41c76b4
......@@ -274,6 +274,90 @@ typename SkeletonT<PointT>::Joint *SkeletonT<PointT>::Iterator::nextSibling(Join
return 0;
}
//-----------------------------------------------------------------------------
// AnimationIterator - IMPLEMENTATION
//-----------------------------------------------------------------------------
/**
* @brief Default constructor
*
* Creates an iterator pointing to the beginning of the vector of animations
*/
template<typename PointT>
SkeletonT<PointT>::AnimationIterator::AnimationIterator(std::vector<Animation*>& _animations ) :
animations_(_animations)
{
currentIndex_ = 0;
// Increment, until we are at the end or we found a valid animation which is not deleted ( == 0 )
while ( currentIndex_ < animations_.size() && animations_[currentIndex_] == 0) {
currentIndex_++;
}
}
/**
* @brief Constructor - Creates an iterator for the given animation set starting at a specific position
*
*/
template<typename PointT>
SkeletonT<PointT>::AnimationIterator::AnimationIterator(std::vector<Animation*>& _animations, unsigned int _animationIndex ) :
animations_(_animations)
{
currentIndex_ = _animationIndex;
// Increment, until we are at the end or we found a valid animation which is not deleted ( == 0 )
while ( currentIndex_ < animations_.size() && animations_[currentIndex_] == 0) {
currentIndex_++;
}
}
/**
* @brief Increase the iterator
*
* The iterator will be changed to the next animation in the list
*/
template<typename PointT>
typename SkeletonT<PointT>::AnimationIterator& SkeletonT<PointT>::AnimationIterator::operator++() {
currentIndex_++;
// Increment, until we are at the end or we found a valid animation which is not deleted ( == 0 )
while ( currentIndex_ < animations_.size() && animations_[currentIndex_] == 0) {
currentIndex_++;
}
return *this;
}
/**
* @brief Operator =
*
*/
template<typename PointT>
typename SkeletonT<PointT>::AnimationIterator& SkeletonT<PointT>::AnimationIterator::operator=(const AnimationIterator &other) {
currentIndex_ = other.currentIndex_;
animations_ = other.animations_;
return *this;
}
/**
* @brief boolean operator
*
* Returns true if the iterator is pointing to a valid handle
*/
template<typename PointT>
SkeletonT<PointT>::AnimationIterator::operator bool() const {
return ( currentIndex_ < animations_.size() );
}
/**
* @brief Get an animation handle for the current animation
*
*/
template<typename PointT>
AnimationHandle SkeletonT<PointT>::AnimationIterator::operator*() const {
return AnimationHandle(currentIndex_);
}
//-----------------------------------------------------------------------------
// SKELETONT - IMPLEMENTATION
......@@ -638,6 +722,7 @@ typename SkeletonT<PointT>::Iterator SkeletonT<PointT>::end()
return Iterator(0);
}
//-----------------------------------------------------------------------------
/**
......@@ -843,6 +928,31 @@ void SkeletonT<PointT>::clearAnimations()
animations_.clear();
}
//-----------------------------------------------------------------------------
/**
* @brief Returns an iterator pointing to the first animation
*
*/
template<typename PointT>
typename SkeletonT<PointT>::AnimationIterator SkeletonT<PointT>::animationsBegin()
{
return AnimationIterator(animations_);
}
//-----------------------------------------------------------------------------
/**
* @brief Returns an iterator pointing behind the last animation
*/
template<typename PointT>
typename SkeletonT<PointT>::AnimationIterator SkeletonT<PointT>::animationsEnd()
{
return AnimationIterator(animations_.size());
}
//-----------------------------------------------------------------------------
/**
......
......@@ -105,6 +105,27 @@ public:
stack<Joint*> stJoints_;
};
/**
* @brief Iterator class for the animations attached to a skeleton
*
* This iterator can be used to iterate over all animations that are attached to the skeleton
*/
class AnimationIterator {
public:
AnimationIterator(std::vector<Animation*>& _animations );
AnimationIterator(std::vector<Animation*>& _animations, unsigned int _animationIndex );
public:
AnimationIterator &operator++();
AnimationHandle operator*() const;
AnimationIterator &operator=(const AnimationIterator &other);
operator bool() const;
private:
unsigned int currentIndex_;
std::vector<Animation*>& animations_;
};
public:
/// Default constructor
......@@ -165,6 +186,10 @@ public:
void removeAnimation(const AnimationHandle &_hAni);
void clearAnimations();
/// Iterator over the animations
AnimationIterator animationsBegin();
AnimationIterator animationsEnd();
unsigned int animationCount();
const std::string &animationName(unsigned int _index);
///@}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment