////////////////////////////////////////////////////////////////////////////////
//                            MESH_SFVertex.inl                               //
////////////////////////////////////////////////////////////////////////////////

namespace X3DTK {
namespace MESH {

template<class MData, class VData, class EData, class FData, bool RW>
const typename SFTemplateVertex<MData, VData, EData, FData, RW>::MFEdge &SFTemplateVertex<MData, VData, EData, FData, RW>::getEdges() const 
{
  return _edges;
}

template<class MData, class VData, class EData, class FData, bool RW>
const typename SFTemplateVertex<MData, VData, EData, FData, RW>::MFFace &SFTemplateVertex<MData, VData, EData, FData, RW>::getFaces() const 
{
  return _faces;
}

template<class MData, class VData, class EData, class FData, bool RW>
VData &SFTemplateVertex<MData, VData, EData, FData, RW>::data() 
{
  return _data;
}

template<class MData, class VData, class EData, class FData, bool RW>
const VData &SFTemplateVertex<MData, VData, EData, FData, RW>::data() const 
{
  return _data;
}

#ifdef TEMPLATE_SPECIALIZATION_SUPPORTED
template<class MData, class VData, class EData, class FData, bool RW>
template<class F>  
F &SFTemplateVertex<MData, VData, EData, FData, RW>::getData()
{
  return _data.template get<F, false>();
}

template<class MData, class VData, class EData, class FData, bool RW>
template<class F>  
F &SFTemplateVertex<MData, VData, EData, FData, RW>::ogetData()
{
  return _data.template get<F, true>();
}
#endif

template<class MData, class VData, class EData, class FData, bool RW>
SFTemplateVertex<MData, VData, EData, FData, RW>::SFTemplateVertex(unsigned int i)
: BaseSFVertex(i)
{
}

template<class MData, class VData, class EData, class FData, bool RW>
SFTemplateVertex<MData, VData, EData, FData, RW>::~SFTemplateVertex()
{
}

template<class MData, class VData, class EData, class FData, bool RW>
bool SFTemplateVertex<MData, VData, EData, FData, RW>::isIsolated() const
{
  return (_edges.size() == 0);
}

template<class MData, class VData, class EData, class FData, bool RW>
void SFTemplateVertex<MData, VData, EData, FData, RW>::addEdge(SFTemplateEdge<MData, VData, EData, FData, RW> *edge) 
{
  _edges.push_back(edge);
}

template<class MData, class VData, class EData, class FData, bool RW>
void SFTemplateVertex<MData, VData, EData, FData, RW>::addFace(SFTemplateFace<MData, VData, EData, FData, RW> *face) 
{
  _faces.push_back(face);
}

template<class MData, class VData, class EData, class FData, bool RW>
void SFTemplateVertex<MData, VData, EData, FData, RW>::removeEdge(SFTemplateEdge<MData, VData, EData, FData, RW> *edge)
{
  typename MFEdge::iterator it = std::find(_edges.begin(), _edges.end(), edge);
  if (it != _edges.end())
    _edges.erase(it);
}

template<class MData, class VData, class EData, class FData, bool RW>
void SFTemplateVertex<MData, VData, EData, FData, RW>::removeFace(SFTemplateFace<MData, VData, EData, FData, RW> *face)
{
  typename MFFace::iterator it = std::find(_faces.begin(), _faces.end(), face);
  if (it != _faces.end())
    _faces.erase(it);
}

template<class MData, class VData, class EData, class FData, bool RW>
std::ostream& operator<<(std::ostream& o, const SFTemplateVertex<MData, VData, EData, FData, RW> &v)
{
  o << "[ " << v.getIndex() << " ]";
  return o;
}
  
}
}  
