// SpaFEDTe, a Template based C++ library for creating 
// Discontinuous Finite Element Spaces,
// Copyright (C) 2012 Lorenzo Alessio Botti

/* 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 3.0 of the License, or (at your option) any later version. */

/* This software 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 software; if not, a copy of the full */
/* GNU Lesser General Public License can be found at */
/* http://www.gnu.org/licenses/. */

// This implementation is mostly borrowed from the MOAB VtkUtil class 

#ifndef __vtu_mesh_util_hpp__
#define __vtu_mesh_util_hpp__

#include <string>
#include "Mesh.hpp"

using namespace SpaMesh;
using namespace Connectivity;

//! Structure defining relation between MOAB and VTK element
//! types.  VTK had different types for quadratic than linear
//! elements, so a tuple of the MOAB type and number of
//! elements maps to a VTK type.
struct MeshVtuElemType
{
  const char* name;            //!< String name for use in error messages
  unsigned vtu_type;           //!< VTK integer type
  ElemTypesMesh spa_type;        //!< MOAB type
  unsigned num_nodes;          //!< Number of nodes (0 for polygon)
  const unsigned* node_order;  //!< VTK element node ordering, indexed by
                               //!< the VTK node position and containing
                               //!< the corresponding SpaFEDTeMesh node position.
                               //!< NOTE: This field is NULL if SpaFEDTe and VTK 
                               //!< ordering is the same!
};

//! General data about VTK files for use by read and write code.
//! \author Jason Kraftcheck
class VtuMeshUtil 
{

public:
    //! Vtu types, indexed by VTK type number.
    //! For unused VTK type numbers, mb_type will be MBMAXTYPE.
  static const MeshVtuElemType vtuElemTypes[];
  
    //! Lenght of \ref vtuElemTypes
  static const unsigned numVtuElemType;
  
    //! Get the VTK type corresponding to a tuple of the MOAB type and number of nodes.
    //! num_nodes is ignored for MBPOLYGON type.
  static const MeshVtuElemType* get_vtu_type( ElemTypesMesh type, unsigned num_nodes );

  static bool check_vtu_data_type (const char* vtuType, const char* expected_type);
  
  //static DataType vtu2spa_data_type (const char* vtuType, size_t& size);
  
  static bool checkStringValuesSize(const char *& string, long nValues);
  
  static bool checkConnectivityStringSize(const char *& connectivity, const char*& connOffset);

  static void setmem( void* mem, const void* value, unsigned value_size, size_t num_elem );
};

#endif
