Remove make_cast_it (#2594)
This commit is contained in:
parent
55ca6bddd5
commit
e347adcb20
7 changed files with 48 additions and 274 deletions
|
@ -5,7 +5,6 @@
|
|||
|
||||
// tcg includes
|
||||
#include "tcg/tcg_misc.h"
|
||||
#include "tcg/tcg_iterator_ops.h"
|
||||
|
||||
#define INCLUDE_HPP
|
||||
#include "tmeshimage.h"
|
||||
|
@ -24,10 +23,6 @@ typedef tcg::TriMesh<TTextureVertex, tcg::Edge, tcg::FaceN<3>> TriMesh_base;
|
|||
DEFINE_CLASS_CODE(TTextureMesh, 120)
|
||||
PERSIST_IDENTIFIER(TTextureMesh, "mesh")
|
||||
|
||||
static TTextureMeshP cloneMesh_(const TTextureMeshP &other) {
|
||||
return TTextureMeshP(new TTextureMesh(*other));
|
||||
}
|
||||
|
||||
static void static_check() {
|
||||
/* input iterator */
|
||||
static_assert(
|
||||
|
@ -56,35 +51,6 @@ static void static_check() {
|
|||
TTextureMeshP>::iterator>::reference>::value ==
|
||||
true,
|
||||
"akan");
|
||||
|
||||
/* converted iterator */
|
||||
std::vector<TTextureMeshP> vec;
|
||||
auto it = vec.end();
|
||||
auto c = tcg::make_cast_it(it, cloneMesh_);
|
||||
|
||||
static_assert(
|
||||
std::is_same<std::iterator_traits<decltype(c)>::iterator_category,
|
||||
std::random_access_iterator_tag>::value == true,
|
||||
"random");
|
||||
|
||||
static_assert(
|
||||
std::is_base_of<
|
||||
std::input_iterator_tag,
|
||||
std::iterator_traits<decltype(c)>::iterator_category>::value == true,
|
||||
"input");
|
||||
|
||||
static_assert(
|
||||
std::is_base_of<
|
||||
std::forward_iterator_tag,
|
||||
std::iterator_traits<decltype(c)>::iterator_category>::value == true,
|
||||
"forward");
|
||||
|
||||
// TTextureMeshP p(std::iterator_traits< decltype(c) >::reference);
|
||||
static_assert(
|
||||
std::is_constructible<
|
||||
TTextureMeshP, std::iterator_traits<decltype(c)>::reference>::value ==
|
||||
true,
|
||||
"akan");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -310,11 +276,11 @@ public:
|
|||
|
||||
Imp() : m_dpiX(), m_dpiY() {}
|
||||
|
||||
Imp(const Imp &other)
|
||||
: m_meshes(tcg::make_cast_it(other.m_meshes.begin(), cloneMesh),
|
||||
tcg::make_cast_it(other.m_meshes.end(), cloneMesh))
|
||||
, m_dpiX(other.m_dpiX)
|
||||
, m_dpiY(other.m_dpiY) {}
|
||||
Imp(const Imp &other) : m_dpiX(other.m_dpiX), m_dpiY(other.m_dpiY) {
|
||||
for (auto const &e : other.m_meshes) {
|
||||
m_meshes.push_back(cloneMesh(e));
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
static TTextureMeshP cloneMesh(const TTextureMeshP &other) {
|
||||
|
|
|
@ -26,159 +26,6 @@ struct iterator_traits<T *> : public std::iterator_traits<T *> {
|
|||
typedef ptr<T> inheritable_iterator_type;
|
||||
};
|
||||
|
||||
//****************************************************************************
|
||||
// Derived Iterator definition
|
||||
//****************************************************************************
|
||||
|
||||
template <typename It, typename Der,
|
||||
typename iterator_tag =
|
||||
typename std::iterator_traits<It>::iterator_category>
|
||||
struct derived_iterator
|
||||
: public tcg::iterator_traits<It>::inheritable_iterator_type {
|
||||
typedef typename tcg::iterator_traits<It>::inheritable_iterator_type
|
||||
base_iterator;
|
||||
|
||||
public:
|
||||
derived_iterator() : base_iterator() {}
|
||||
derived_iterator(const base_iterator &it) : base_iterator(it) {}
|
||||
|
||||
Der &operator++() {
|
||||
base_iterator::operator++();
|
||||
return static_cast<Der &>(*this);
|
||||
}
|
||||
Der operator++(int) {
|
||||
return Der(base_iterator::operator++(0), static_cast<Der &>(*this));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename It, typename Der>
|
||||
struct derived_iterator<It, Der, std::bidirectional_iterator_tag>
|
||||
: public derived_iterator<It, Der, std::forward_iterator_tag> {
|
||||
typedef typename tcg::iterator_traits<It>::inheritable_iterator_type
|
||||
base_iterator;
|
||||
|
||||
public:
|
||||
derived_iterator() : _iter() {}
|
||||
derived_iterator(const base_iterator &it) : _iter(it) {}
|
||||
|
||||
Der &operator--() {
|
||||
base_iterator::operator--();
|
||||
return static_cast<Der &>(*this);
|
||||
}
|
||||
Der operator--(int) {
|
||||
return Der(base_iterator::operator--(0), static_cast<Der &>(*this));
|
||||
}
|
||||
|
||||
private:
|
||||
typedef derived_iterator<It, Der, std::forward_iterator_tag> _iter;
|
||||
};
|
||||
|
||||
template <typename It, typename Der>
|
||||
struct derived_iterator<It, Der, std::random_access_iterator_tag>
|
||||
: public derived_iterator<It, Der, std::bidirectional_iterator_tag> {
|
||||
typedef typename tcg::iterator_traits<It>::inheritable_iterator_type
|
||||
base_iterator;
|
||||
typedef typename base_iterator::difference_type difference_type;
|
||||
|
||||
public:
|
||||
derived_iterator() : _iter() {}
|
||||
derived_iterator(const base_iterator &it) : _iter(it) {}
|
||||
|
||||
Der operator+(difference_type d) const {
|
||||
return Der(static_cast<const base_iterator &>(*this) + d,
|
||||
static_cast<const Der &>(*this));
|
||||
}
|
||||
Der &operator+=(difference_type d) {
|
||||
static_cast<base_iterator &>(*this) += d;
|
||||
return static_cast<Der &>(*this);
|
||||
}
|
||||
|
||||
Der operator-(difference_type d) const {
|
||||
return Der(static_cast<const base_iterator &>(*this) - d,
|
||||
static_cast<const Der &>(*this));
|
||||
}
|
||||
Der &operator-=(difference_type d) {
|
||||
static_cast<base_iterator &>(*this) -= d;
|
||||
return static_cast<Der &>(*this);
|
||||
}
|
||||
|
||||
difference_type operator-(const Der &other) const {
|
||||
return static_cast<const base_iterator &>(*this) -
|
||||
static_cast<const base_iterator &>(other);
|
||||
}
|
||||
|
||||
private:
|
||||
typedef derived_iterator<It, Der, std::bidirectional_iterator_tag> _iter;
|
||||
};
|
||||
|
||||
//****************************************************************************
|
||||
// Cast Iterator definition
|
||||
//****************************************************************************
|
||||
|
||||
/*!
|
||||
A cast iterator is a utility iterator wrapper that can be used to access
|
||||
an iterator's data through a supplied functor intermediary, proving to be
|
||||
especially useful when converting data from a container to another with
|
||||
minimal effort.
|
||||
*/
|
||||
|
||||
template <typename It, typename Func,
|
||||
typename Val = typename traits<
|
||||
typename function_traits<Func>::ret_type>::referenced_type,
|
||||
typename Ref = typename choose_if_match<
|
||||
typename function_traits<Func>::ret_type &,
|
||||
typename traits<Val>::reference_type>::type,
|
||||
typename Ptr = typename choose_if_match<
|
||||
Ref, void, typename traits<Val>::pointer_type>::type>
|
||||
class cast_iterator
|
||||
: public derived_iterator<It, cast_iterator<It, Func, Val, Ref, Ptr>> {
|
||||
typedef derived_iterator<It, cast_iterator> iterator;
|
||||
typedef typename iterator::base_iterator base_iterator;
|
||||
typedef Func function;
|
||||
typedef typename function_traits<Func>::ret_type ret_type;
|
||||
|
||||
public:
|
||||
typedef Ref reference;
|
||||
typedef Ptr pointer;
|
||||
typedef Val value_type;
|
||||
|
||||
public:
|
||||
cast_iterator() : iterator(), m_func() {}
|
||||
cast_iterator(const Func &func) : iterator(), m_func(func) {}
|
||||
|
||||
cast_iterator(const base_iterator &it) : iterator(it), m_func() {}
|
||||
cast_iterator(const base_iterator &it, const Func &func)
|
||||
: iterator(it), m_func(func) {}
|
||||
|
||||
cast_iterator(const base_iterator &it, const cast_iterator &other)
|
||||
: iterator(it), m_func(other.m_func) {}
|
||||
|
||||
ret_type operator*() { return m_func(iterator::operator*()); }
|
||||
pointer operator->() { return ptr(0); }
|
||||
|
||||
private:
|
||||
Func m_func;
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
pointer ptr(T,
|
||||
typename tcg::enable_if<tcg::type_mismatch<pointer, void>::value,
|
||||
T>::type = 0) const {
|
||||
return &operator*();
|
||||
}
|
||||
|
||||
void ptr(char) const {}
|
||||
};
|
||||
|
||||
//==========================================================================
|
||||
|
||||
// Utility maker function
|
||||
|
||||
template <typename It, typename Func>
|
||||
inline cast_iterator<It, Func> make_cast_it(const It &it, Func func) {
|
||||
return cast_iterator<It, Func>(it, func);
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
// Step Iterator class
|
||||
//***********************************************************************
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#include "tcg/tcg_misc.h"
|
||||
#include "tcg/tcg_pool.h"
|
||||
#include "tcg/tcg_function_types.h"
|
||||
#include "tcg/tcg_iterator_ops.h"
|
||||
|
||||
#include "ext/plasticskeleton.h"
|
||||
|
||||
|
@ -573,16 +572,9 @@ int PlasticSkeleton::closestEdge(const TPointD &pos, double *dist) const {
|
|||
//-------------------------------------------------------------------------------
|
||||
|
||||
std::vector<PlasticHandle> PlasticSkeleton::verticesToHandles() const {
|
||||
// Someway, PlasticHandle's EXPLICIT unary constructors are not enough
|
||||
// to disambiguate the direct construction of a vector of PlasticHandles
|
||||
// from m_vertices, at least with *gcc*. I guess it could be a compiler bug.
|
||||
|
||||
// So, we'll convert them using an explicit casting iterator...
|
||||
|
||||
typedef tcg::function < PlasticHandle (PlasticSkeletonVertex::*)() const,
|
||||
&PlasticSkeletonVertex::operator PlasticHandle> Func;
|
||||
|
||||
return std::vector<PlasticHandle>(
|
||||
tcg::make_cast_it(m_vertices.begin(), Func()),
|
||||
tcg::make_cast_it(m_vertices.end(), Func()));
|
||||
std::vector<PlasticHandle> v;
|
||||
for (auto const &e : m_vertices) {
|
||||
v.push_back(e);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
// tcg includes
|
||||
#include "tcg/tcg_point_ops.h"
|
||||
#include "tcg/tcg_function_types.h"
|
||||
#include "tcg/tcg_iterator_ops.h"
|
||||
|
||||
#include "plastictool.h"
|
||||
|
||||
|
@ -562,12 +561,6 @@ void PlasticTool::leftButtonDown_build(const TPointD &pos,
|
|||
|
||||
// Start move vertex operation
|
||||
if (!m_svSel.isEmpty()) {
|
||||
struct locals {
|
||||
static TPointD vertexPos(const PlasticSkeleton &skel, int v) {
|
||||
return skel.vertex(v).P();
|
||||
}
|
||||
};
|
||||
|
||||
const PlasticSkeletonP &skel = skeleton();
|
||||
assert(skel);
|
||||
|
||||
|
@ -575,11 +568,11 @@ void PlasticTool::leftButtonDown_build(const TPointD &pos,
|
|||
if (m_svSel.hasSingleObject()) m_pressedPos = skel->vertex(m_svSel).P();
|
||||
|
||||
// Store original vertex positions
|
||||
m_pressedVxsPos = std::vector<TPointD>(
|
||||
tcg::make_cast_it(m_svSel.objects().begin(),
|
||||
tcg::bind1st(&locals::vertexPos, *skel)),
|
||||
tcg::make_cast_it(m_svSel.objects().end(),
|
||||
tcg::bind1st(&locals::vertexPos, *skel)));
|
||||
std::vector<TPointD> v;
|
||||
for (auto const &e : m_svSel.objects()) {
|
||||
v.push_back(skel->vertex(e).P());
|
||||
}
|
||||
m_pressedVxsPos = std::move(v);
|
||||
}
|
||||
|
||||
invalidate();
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
// tcg includes
|
||||
#include "tcg/tcg_macros.h"
|
||||
#include "tcg/tcg_point_ops.h"
|
||||
#include "tcg/tcg_iterator_ops.h"
|
||||
#include "tcg/tcg_function_types.h"
|
||||
|
||||
// boost includes
|
||||
|
@ -1052,11 +1051,6 @@ void PlasticTool::leftButtonDown_mesh(const TPointD &pos,
|
|||
} else
|
||||
m_this->setMeshSelection(sel, MeshSelection());
|
||||
}
|
||||
|
||||
static TPointD vertexPos(const TMeshImage &mi, const MeshIndex &meshIdx) {
|
||||
return mi.meshes()[meshIdx.m_meshIdx]->vertex(meshIdx.m_idx).P();
|
||||
}
|
||||
|
||||
} locals = {this};
|
||||
|
||||
// Track mouse position
|
||||
|
@ -1068,11 +1062,11 @@ void PlasticTool::leftButtonDown_mesh(const TPointD &pos,
|
|||
|
||||
// Store original vertex positions
|
||||
if (!m_mvSel.isEmpty()) {
|
||||
m_pressedVxsPos = std::vector<TPointD>(
|
||||
tcg::make_cast_it(m_mvSel.objects().begin(),
|
||||
tcg::bind1st(&Locals::vertexPos, *m_mi)),
|
||||
tcg::make_cast_it(m_mvSel.objects().end(),
|
||||
tcg::bind1st(&Locals::vertexPos, *m_mi)));
|
||||
std::vector<TPointD> v;
|
||||
for (auto const &e : m_mvSel.objects()) {
|
||||
v.push_back(m_mi->meshes()[e.m_meshIdx]->vertex(e.m_idx).P());
|
||||
}
|
||||
m_pressedVxsPos = std::move(v);
|
||||
}
|
||||
|
||||
// Redraw selections
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
// tcg includes
|
||||
#include "tcg/tcg_numeric_ops.h"
|
||||
#include "tcg/tcg_function_types.h"
|
||||
#include "tcg/tcg_iterator_ops.h"
|
||||
|
||||
// boost includes
|
||||
#include <boost/iterator/counting_iterator.hpp>
|
||||
|
@ -298,10 +297,6 @@ AdjustThicknessPopup::SelectionData::SelectionData(const TSelection *sel)
|
|||
struct Locals {
|
||||
SelectionData *m_this;
|
||||
|
||||
typedef tcg::function<int (TXshSimpleLevel::*)(const TFrameId &) const,
|
||||
&TXshSimpleLevel::fid2index>
|
||||
Fid2Index;
|
||||
|
||||
void resetIfInvalid() // Resets to empty if thickness adjustment is
|
||||
{ // not applicable:
|
||||
if (!m_this->m_sl) // 1. The level is not a VECTOR level
|
||||
|
@ -349,11 +344,11 @@ AdjustThicknessPopup::SelectionData::SelectionData(const TSelection *sel)
|
|||
|
||||
const std::set<TFrameId> &fids = selection.getSelectedFids();
|
||||
|
||||
m_this->m_frameIdxs = std::set<int>(
|
||||
tcg::make_cast_it(fids.begin(),
|
||||
tcg::bind1st(Fid2Index(), *m_this->m_sl)),
|
||||
tcg::make_cast_it(fids.end(),
|
||||
tcg::bind1st(Fid2Index(), *m_this->m_sl)));
|
||||
std::set<int> s;
|
||||
for (auto const &e : fids) {
|
||||
s.insert(m_this->m_sl->fid2index(e));
|
||||
}
|
||||
m_this->m_frameIdxs = std::move(s);
|
||||
|
||||
resetIfInvalid();
|
||||
}
|
||||
|
@ -484,11 +479,11 @@ AdjustThicknessPopup::SelectionData::SelectionData(const TSelection *sel)
|
|||
|
||||
const std::set<TFrameId> &fids = TTool::getSelectedFrames();
|
||||
|
||||
m_this->m_frameIdxs = std::set<int>(
|
||||
tcg::make_cast_it(fids.begin(),
|
||||
tcg::bind1st(Fid2Index(), *m_this->m_sl)),
|
||||
tcg::make_cast_it(fids.end(),
|
||||
tcg::bind1st(Fid2Index(), *m_this->m_sl)));
|
||||
std::set<int> s;
|
||||
for (auto const &e : fids) {
|
||||
s.insert(m_this->m_sl->fid2index(e));
|
||||
}
|
||||
m_this->m_frameIdxs = std::move(s);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,6 @@
|
|||
#include "tcg/tcg_macros.h"
|
||||
#include "tcg/tcg_base.h"
|
||||
#include "tcg/tcg_function_types.h"
|
||||
#include "tcg/tcg_iterator_ops.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
@ -2366,12 +2365,10 @@ static void deleteColumns(const std::list<int> &columns,
|
|||
// columns directly, and then their (updated) column index.
|
||||
TXsheet *xsh = xshHandle->getXsheet();
|
||||
|
||||
typedef tcg::function<TXshColumn *(TXsheet::*)(int)const, &TXsheet::getColumn>
|
||||
getColumn_fun;
|
||||
tcg::binder1st<getColumn_fun> getCol(getColumn_fun(), *xsh);
|
||||
|
||||
std::vector<TXshColumn *> cols(tcg::make_cast_it(columns.begin(), getCol),
|
||||
tcg::make_cast_it(columns.end(), getCol));
|
||||
std::vector<TXshColumn *> cols;
|
||||
for (auto const &c : columns) {
|
||||
cols.push_back(xsh->getColumn(c));
|
||||
}
|
||||
|
||||
size_t c, cCount = cols.size();
|
||||
for (c = 0; c != cCount; ++c) {
|
||||
|
@ -3107,20 +3104,6 @@ private:
|
|||
//======================================================
|
||||
|
||||
void UndoDisconnectFxs::initialize() {
|
||||
struct locals {
|
||||
static QPair<TFxP, TPointD> originalPos(const QPair<TFxP, TPointD> &pair) {
|
||||
return QPair<TFxP, TPointD>(pair.first,
|
||||
pair.first->getAttributes()->getDagNodePos());
|
||||
}
|
||||
|
||||
static bool contains(const std::list<TFxP> &fxs, TFx *fx) {
|
||||
tcg::function<TFx *(TFxP::*)() const, &TFxP::getPointer> getPointer_fun;
|
||||
|
||||
return (std::count(tcg::make_cast_it(fxs.begin(), getPointer_fun),
|
||||
tcg::make_cast_it(fxs.end(), getPointer_fun), fx) > 0);
|
||||
}
|
||||
};
|
||||
|
||||
TXsheet *xsh = m_xshHandle->getXsheet();
|
||||
FxDag *fxDag = xsh->getFxDag();
|
||||
|
||||
|
@ -3132,13 +3115,15 @@ void UndoDisconnectFxs::initialize() {
|
|||
if (m_fxs.empty()) return;
|
||||
|
||||
// Build fxs data
|
||||
tcg::binder1st<bool (*)(const std::list<TFxP> &, TFx *)> contains_fun(
|
||||
&locals::contains, m_fxs);
|
||||
auto const contains = [this](TFx const *fx) -> bool {
|
||||
return std::count_if(this->m_fxs.begin(), this->m_fxs.end(),
|
||||
[fx](TFxP &f) { return f.getPointer() == fx; }) > 0;
|
||||
};
|
||||
|
||||
m_leftFx = FxCommandUndo::leftmostConnectedFx(m_fxs.front().getPointer(),
|
||||
contains_fun);
|
||||
m_rightFx = FxCommandUndo::rightmostConnectedFx(m_fxs.front().getPointer(),
|
||||
contains_fun);
|
||||
m_leftFx =
|
||||
FxCommandUndo::leftmostConnectedFx(m_fxs.front().getPointer(), contains);
|
||||
m_rightFx =
|
||||
FxCommandUndo::rightmostConnectedFx(m_fxs.front().getPointer(), contains);
|
||||
|
||||
// Store sensible original data for the undo
|
||||
m_undoLinksIn = FxCommandUndo::inputLinks(xsh, m_leftFx);
|
||||
|
@ -3150,10 +3135,12 @@ void UndoDisconnectFxs::initialize() {
|
|||
m_undoTerminalLinks.push_back(TFxCommand::Link(lt->m_inputFx.getPointer(),
|
||||
fxDag->getXsheetFx(), -1));
|
||||
|
||||
std::vector<QPair<TFxP, TPointD>>(
|
||||
tcg::make_cast_it(m_undoDagPos.begin(), &locals::originalPos),
|
||||
tcg::make_cast_it(m_undoDagPos.end(), &locals::originalPos))
|
||||
.swap(m_redoDagPos);
|
||||
std::vector<QPair<TFxP, TPointD>> v;
|
||||
for (auto const &e : m_undoDagPos) {
|
||||
v.emplace_back(e.first, e.first->getAttributes()->getDagNodePos());
|
||||
}
|
||||
m_redoDagPos = std::move(v);
|
||||
m_redoDagPos.shrink_to_fit();
|
||||
}
|
||||
|
||||
//------------------------------------------------------
|
||||
|
|
Loading…
Reference in a new issue