Commit 5c0e1f36 authored by Sylvain Thery's avatar Sylvain Thery

add C++11 for syntax traversal with attributes

parent 996669d5
......@@ -63,7 +63,16 @@ int main()
{
std::cout << id << " : " << position[id]<< " / ";
}
std::cout << std::endl;
std::cout << std::endl << "--------------------------------" << std::endl;
//using (C++11 for syntax)
// warning: if you want ot modify the attributes do not forget the &
for (auto& p: position.iterable())
{
p *= 2.0;
}
//using foreach function (C++11 lambda expression)
foreach_attribute(position, [&] (unsigned int id) // for each element of position
......@@ -71,6 +80,8 @@ int main()
std::cout << id << " : " << position[id]<< " / ";
});
std::cout << std::endl << "--------------------------------" << std::endl;
// using parallel foreach
// parameter position must be captured explicitly even if it used as first parameter of foreach !
Parallel::foreach_attribute(position, [&position] (unsigned int id, unsigned int /*thread*/) // for each elt of the position attribute
......
......@@ -392,9 +392,9 @@ bool exportOFF(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3,
out.close() ;
return true ;
}
/*
template <typename PFP>
bool exportOBJ(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const char* filename)
bool exportOBJ(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& position, const char* filename)
{
typedef typename PFP::MAP MAP;
typedef typename PFP::VEC3 VEC3;
......@@ -416,7 +416,7 @@ bool exportOBJ(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>
std::vector<unsigned int> vertices ;
vertices.reserve(nbDarts/6) ;
CellMarker<VERTEX> markV(map) ;
CellMarker<typename PFP::MAP,VERTEX> markV(map) ;
TraversorF<MAP> t(map) ;
for(Dart d = t.begin(); d != t.end(); d = t.next())
{
......@@ -425,7 +425,9 @@ bool exportOBJ(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>
Traversor2FV<typename PFP::MAP> tfv(map, d) ;
for(Dart it = tfv.begin(); it != tfv.end(); it = tfv.next())
{
unsigned int vNum = map.getEmbedding(VERTEX, it) ;
// unsigned int vNum = map.getEmbedding(VERTEX, it) ;
unsigned int vNum = map. template getEmbedding<VERTEX>(it) ;
if(!markV.isMarked(it))
{
markV.mark(it) ;
......@@ -458,7 +460,7 @@ bool exportOBJ(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>
out.close() ;
return true ;
}
/*
template <typename PFP>
bool exportPlyPTMgeneric(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const char* filename)
{
......
......@@ -86,6 +86,13 @@ public:
static const unsigned int ORBIT = ORB;
};
// forward declaration
template <typename T, unsigned int ORB, typename MAP>
class AttributeHandlerIter;
/**
* Class that create an access-table to an existing attribute
* Main available operations are:
......@@ -107,7 +114,6 @@ protected:
public:
typedef T DATA_TYPE ;
// static const unsigned int ORBIT = ORB;
/**
* Default constructor
......@@ -255,6 +261,8 @@ public:
* @param iter iterator to
*/
void next(unsigned int& iter) const;
AttributeHandlerIter<T,ORB,MAP> iterable() const;
} ;
......@@ -303,6 +311,64 @@ typedef AttributeHandlerOrbit<VOLUME> VolumeAttributeGen;
template <typename T, unsigned int ORB, typename MAP>
class AttributeHandlerIter : public AttributeHandler<T,ORB,MAP>
{
public:
AttributeHandlerIter(const AttributeHandler<T, ORB, MAP>& ta):
AttributeHandler<T,ORB,MAP>(ta)
{
}
class iterator
{
AttributeHandlerIter<T,ORB,MAP>* m_ptr;
unsigned int m_index;
public:
inline iterator(AttributeHandlerIter<T, ORB, MAP>* p, unsigned int i): m_ptr(p),m_index(i){}
inline iterator& operator++()
{
m_ptr->next(m_index);
return *this;
}
inline T& operator*()
{
T& v = m_ptr->operator[](m_index);
return v;
}
inline bool operator!=(iterator it)
{
return m_index != it.m_index;
}
};
inline iterator begin()
{
return iterator(this,AttributeHandler<T,ORB,MAP>::begin());
}
inline iterator end()
{
return iterator(this,AttributeHandler<T,ORB,MAP>::end());
}
};
// turn_to<b>(A*</b> obj) changes class of the object
// that means it just replaces VTBL of the object by VTBL of another class.
// NOTE: these two classes has to be ABI compatible!
......
......@@ -268,6 +268,13 @@ inline void AttributeHandler<T, ORB, MAP>::next(unsigned int& iter) const
}
template <typename T, unsigned int ORB, typename MAP>
inline AttributeHandlerIter<T,ORB,MAP> AttributeHandler<T, ORB, MAP>::iterable() const
{
return AttributeHandlerIter<T,ORB,MAP>(*this);
}
namespace Parallel
{
......
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