S.F.Tracker(288)

公開:2007-10-29 08:14
更新:2020-02-15 04:36
カテゴリ:sftracker,c++,windows,audio,tracker

ようやくcomponent_iteratorがビルドできるようなった。
前方向のシーケンスはテスト完了。
今後はランダムアクセス・イテレータの基準を満たしているかのテストをしながら、コードを修正していく。

#pragma once
/*
==============================================================================
This file is part of the S.F.Tracker
Copyright 2005-7 by Satoshi Fujiwara.
S.F.Tracker can be redistributed and/or modified under the terms of the
GNU General Public License, as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.
S.F.Tracker is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with S.F.Tracker; if not, visit www.gnu.org/licenses or write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
==============================================================================
*/
/** @file
*  @author S.F. (Satoshi Fujiwara)
*  @brief Component を iterateしたり、rangeしたりするhelper class library.
*/
#include <boost/iterator_adaptors.hpp>
#include <boost/type_traits/is_convertible.hpp>
#include <boost/utility/enable_if.hpp>
#include "src\juce_WithoutMacros.h"
namespace sf {
template <typename ComponentType>
struct component_iterator_base :
public boost::iterator_facade<component_iterator_base<ComponentType>,ComponentType*,boost::random_access_traversal_tag>
{
private:
struct enabler {};
public:
template <class OtherValue>
component_iterator_base(
component_iterator_base<OtherValue> const& other
, typename boost::enable_if<
boost::is_convertible<OtherValue*,ComponentType*>
, enabler
>::type = enabler()
) : comp_(other.comp_),index_(other.index_),valid_(other.valid_) {}
component_iterator_base<ComponentType>() :comp_(0),index_(0),valid_(false) {};
explicit component_iterator_base<ComponentType>(ComponentType& comp,int index = 0) :
comp_(&comp),index_(index),valid_(true)
{
};
private:
friend struct component_iterator_base;
friend class boost::iterator_core_access;
void increment()
{
valid_ = index_  < (comp_->getNumChildComponents() - 1);
if(valid_)
{
++index_;
}
};
void decrement()
{
valid_ = index_ > 1;
if(valid_)
{
--index_;
}
}
template <typename OtherType>
bool equal( component_iterator_base<OtherType> const & other) const
{
if(valid_ && other.valid_){
return comp_->getChildComponent(index_) == other.comp_->getChildComponent(other.index_);
} else {
//                return true;
return !valid_ && !other.valid_;
}
}
reference dereference() const
{    Component* t = comp_->getChildComponent(index_);
return t;
};
void advance(difference_type n)
{
index_ += n;
valid_ = (index_ < comp_->getNumChildComponents() - 1) && (index_ > 0);
};
difference_type distance_to (component_iterator_base const& other) const
{
return other.index_ - index_;
}
mutable int index_;
bool valid_;
mutable ComponentType* comp_;
};
typedef component_iterator_base<Component> component_iterator;
typedef component_iterator_base<Component const> const_component_iterator;
template <typename ComponentType> inline component_iterator_base<ComponentType> begin(ComponentType& parent_comp) { return component_iterator_base<ComponentType>(parent_comp);};
template <typename ComponentType> inline component_iterator_base<ComponentType> end(ComponentType&) { return component_iterator_base<ComponentType>();};
}