/// This file is part of the X3DToolKit library
/// Copyright (C) 2002-2004  Yannick Le Goc (legoc@imag.fr)

/// http://artis.imag.fr/Members/Yannick.Legoc/X3D/

/// This library is free software; you can redistribute it and/or
/// modify it under the terms of the GNU Lesser General Public
/// License as published by the Free Software Foundation; either
/// version 2.1 of the License, or (at your option) any later version.

/// This library 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
/// Lesser General Public License for more details.

/// You should have received a copy of the GNU Lesser General Public
/// License along with this library; if not, write to the Free Software
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#ifndef X3DTK_MESH_SFVERTEX_H
#define X3DTK_MESH_SFVERTEX_H

#include "MESH_BaseSFVertex.h"
#include "TypeList.h"

#include <vector>

namespace X3DTK {
namespace MESH {

template<class MData, class VData, class EData, class FData, bool RW> class TemplateMesh;
template<class MData, class VData, class EData, class FData, bool RW> class TemplateVertex;
template<class MData, class VData, class EData, class FData, bool RW> class SFTemplateEdge;
template<class MData, class VData, class EData, class FData, bool RW> class SFTemplateFace;
template<class MData, class VData, class EData, class FData, bool RW> class EntityMFTemplateEdge;
template<class MData, class VData, class EData, class FData, bool RW> class EntityMFTemplateFace;

/*! \brief Template class declared in <b><X3DTK/MESH/scenegraph.h></b> 
 *  providing a vertex structure for the Mesh class.
 *
 * \ingroup MeshSceneGraph
 */

template<class MData, class VData, class EData, class FData, bool RW>
class SFTemplateVertex : public BaseSFVertex
{
  friend class TemplateVertex<MData, VData, EData, FData, RW>;
  friend class TemplateMesh<MData, VData, EData, FData, RW>;
public:
  typedef EntityMFTemplateFace<MData, VData, EData, FData, RW> MFFace;
  typedef EntityMFTemplateEdge<MData, VData, EData, FData, RW> MFEdge;
  
  /// Gets the rounding edges.
  inline const MFEdge &getEdges() const;
  /// Gets the rounding faces.
  inline const MFFace &getFaces() const;
  /// Gets the data.
  inline VData &data();
  /// Gets the data.
  inline const VData &data() const;
  /// Returns true if is an isolated vertex.
  inline bool isIsolated() const;

#ifdef TEMPLATE_SPECIALIZATION_SUPPORTED
  /// Gets the data F from VData which must be of type clist<tlist<T...> >.
  template<class F>  
  F &getData();
  /// Gets optionally the data F from VData which must be of type clist<tlist<T...> >.
  template<class F>  
  F &ogetData();
#endif
  
private:
  MFEdge _edges;
  MFFace _faces;
  VData _data;

  /// Constructor.
  SFTemplateVertex(unsigned int i);
  /// Destructor.
  ~SFTemplateVertex();
  
  /// Adds an edge.
  void addEdge(SFTemplateEdge<MData, VData, EData, FData, RW> *edge);
  /// Adds a face.
  void addFace(SFTemplateFace<MData, VData, EData, FData, RW> *face);
  
  /// Removes an edge.
  void removeEdge(SFTemplateEdge<MData, VData, EData, FData, RW> *edge);
  /// Adds a face.
  void removeFace(SFTemplateFace<MData, VData, EData, FData, RW> *face);
};

/// operator<< overloaded for SFEdge class.
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);

}
}

#include "MESH_SFVertex.inl"

#endif
