LCOV - code coverage report
Current view: top level - ugbase/common/util - archivar.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 16 0
Test Date: 2025-09-21 23:31:46 Functions: 0.0 % 40 0

            Line data    Source code
       1              : /*
       2              :  * Copyright (c) 2016:  G-CSC, Goethe University Frankfurt
       3              :  * Author: Sebastian Reiter
       4              :  * 
       5              :  * This file is part of UG4.
       6              :  * 
       7              :  * UG4 is free software: you can redistribute it and/or modify it under the
       8              :  * terms of the GNU Lesser General Public License version 3 (as published by the
       9              :  * Free Software Foundation) with the following additional attribution
      10              :  * requirements (according to LGPL/GPL v3 §7):
      11              :  * 
      12              :  * (1) The following notice must be displayed in the Appropriate Legal Notices
      13              :  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
      14              :  * 
      15              :  * (2) The following notice must be displayed at a prominent place in the
      16              :  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
      17              :  * 
      18              :  * (3) The following bibliography is recommended for citation and must be
      19              :  * preserved in all covered files:
      20              :  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
      21              :  *   parallel geometric multigrid solver on hierarchically distributed grids.
      22              :  *   Computing and visualization in science 16, 4 (2013), 151-164"
      23              :  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
      24              :  *   flexible software system for simulating pde based models on high performance
      25              :  *   computers. Computing and visualization in science 16, 4 (2013), 165-179"
      26              :  * 
      27              :  * This program is distributed in the hope that it will be useful,
      28              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      29              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      30              :  * GNU Lesser General Public License for more details.
      31              :  */
      32              : 
      33              : #ifndef __H__UG_archivar
      34              : #define __H__UG_archivar
      35              : 
      36              : #include <boost/static_assert.hpp>
      37              : #include <boost/mpl/for_each.hpp>
      38              : #include <boost/type_traits/is_base_of.hpp>
      39              : #include "../boost_serialization.h"
      40              : #include "detail/register_type_pair_functor.h"
      41              : 
      42              : namespace ug{
      43              : 
      44              : 
      45              : namespace detail{
      46              : namespace archivar{
      47              :         template <typename TArchive, typename TBase, typename TDerived>
      48            0 :         void CallArchiveOnDerivedClass (TArchive& ar, TBase& base, const char* name)
      49              :         {
      50              :                 BOOST_STATIC_ASSERT((boost::is_base_of<TBase, TDerived>::value));
      51            0 :                 TDerived& derived = dynamic_cast<TDerived&>(base);
      52              :                 ar & make_nvp(name, derived);
      53            0 :         }
      54              : }
      55              : }
      56              : 
      57              : template <class TArchive, class TBase, class TPairSeq>
      58              : class Archivar
      59              : {
      60              : public:
      61            0 :         Archivar()
      62              :         {
      63              :                 detail::RegisterTypePairFunctor<Archivar> func(this);
      64              :                 boost::mpl::for_each<TPairSeq>(func);
      65            0 :         }
      66              : 
      67              :         template <class T>
      68              :         void archive(TArchive& ar, T& t)
      69              :         {
      70            0 :                 archive(ar, t, "");
      71            0 :         }
      72              : 
      73              :         template <class T>
      74            0 :         void archive(TArchive& ar, T& t, const char* name)
      75              :         {
      76            0 :                 std::string typeName(typeid(t).name());
      77              : 
      78              :                 typename callback_map_t::iterator icallback = m_callbackMap.find(typeName);
      79            0 :                 UG_COND_THROW(icallback == m_callbackMap.end(),
      80              :                                           "Unregistered class used in 'Archivar::archive': " << typeName);
      81              : 
      82            0 :                 icallback->second(ar, t, name);
      83            0 :         }
      84              : 
      85              :         template <class TDerived>
      86            0 :         void register_class(const char* name)
      87              :         {
      88              :                 BOOST_STATIC_ASSERT((boost::is_base_of<TBase, TDerived>::value));
      89            0 :                 std::string typeName(typeid(TDerived).name());
      90            0 :                 m_callbackMap[typeName] =
      91              :                                 &detail::archivar::CallArchiveOnDerivedClass<TArchive, TBase, TDerived>;
      92            0 :         }
      93              : 
      94              : private:
      95              :         typedef void (*archive_sig)(TArchive&, TBase&, const char* name);
      96              : 
      97              :         typedef std::map<std::string, archive_sig>        callback_map_t;
      98              :         callback_map_t  m_callbackMap;
      99              : };
     100              : 
     101              : }//     end of namespace
     102              : 
     103              : #endif  //__H__UG_archivar
        

Generated by: LCOV version 2.0-1