// 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/. */

#ifndef __finite_element_mapping_basis_h__
#define __finite_element_mapping_basis_h__

#include "BasisFunction.hpp"
#include "MappingBasisFunction.hpp"
#include "LagrangeNodalMappingFunction.hpp"
#include "Quadrature.hpp"
#include "EnumElemType.hpp"
#include "Tuple.hpp"

template<class FiniteElementMappingFunctionT>
class FiniteElementMappingBasis
{
public:
  typedef FiniteElementMappingFunctionT FiniteElementMappingFunctionType;
  typedef Quadrature::PointVector PointVector;
  
  FiniteElementMappingBasis() 
    {
      ;
    }
  
  ~FiniteElementMappingBasis() { }
  
public:
  template<unsigned int Dim, unsigned int DIm,
           template <unsigned int, unsigned int> class MappingFunctionType>
    static void init(MappingFunctionType<Dim,DIm>& basisFunction, const Quadrature& quadrature, const ElemType itemType, const unsigned int order)
  {
    assert(itemType == quadrature.getItemType());
    ElemType& b_itemType = basisFunction.getItemType();
    unsigned int& b_Order = basisFunction.getOrder();
    unsigned int& q_Order = basisFunction.getQorder();
    if (itemType == b_itemType && order == b_Order && quadrature.getOrder() == q_Order)
    {
      return;
    }
    else 
    {
      b_itemType = itemType;
      b_Order = order;
      q_Order = quadrature.getOrder();
    }
    FiniteElementMappingFunctionType::initBasisFunction(basisFunction, quadrature.getQpoint());
  }
  
  template<unsigned int Dim, unsigned int DIm,
           template <unsigned int, unsigned int> class MappingFunctionType>
    static void reInit(MappingFunctionType<Dim,DIm>& basisFunction, const typename Quadrature::PointVector& quadratureVec, const ElemType itemType, const unsigned int order)
  {
    basisFunction.getItemType() = itemType;
    basisFunction.getOrder() = order;
    basisFunction.getQorder() = 0;
    FiniteElementMappingFunctionType::initBasisFunction(basisFunction, quadratureVec);
  }
    
  static unsigned int dofsNumber (const unsigned int Dim, const unsigned int order, const ElemType itemType = INVALID_ELEM)
  {
    return FiniteElementMappingFunctionType::dofsNumber(Dim, order, itemType);
  }

  static bool is_hierarchical() 
  {
    return FiniteElementMappingFunctionType::is_hierarchical();
  }
};

#endif
