LCOV - code coverage report
Current view: top level - ugbase/lib_grid/attachments - attachment_io_traits.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 17 0
Test Date: 2025-09-21 23:31:46 Functions: 0.0 % 6 0

            Line data    Source code
       1              : /*
       2              :  * Copyright (c) 2015:  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_attachment_io_traits
      34              : #define __H__UG_attachment_io_traits
      35              : 
      36              : namespace ug{
      37              : 
      38              : 
      39              : template <class TAttachment>
      40              : struct attachment_io_traits{
      41              :         typedef typename TAttachment::ValueType                                                                 value_type;
      42              :         typedef typename attachment_value_traits<value_type>::reference                   reference_type;
      43              :         typedef typename attachment_value_traits<value_type>::const_reference     const_reference_type;
      44              : 
      45            0 :         static void write_value (std::ostream& out, const_reference_type v) {out << v;}
      46            0 :         static void read_value(std::istream& in, reference_type v)                  {in >> v;}
      47              : };
      48              : 
      49              : template <>
      50              : struct attachment_io_traits<Attachment<bool> > {
      51              :         typedef bool                                                                                                    value_type;
      52              :         typedef attachment_value_traits<value_type>::reference                    reference_type;
      53              :         typedef attachment_value_traits<value_type>::const_reference      const_reference_type;
      54              : 
      55              :         static void write_value (std::ostream& out, const_reference_type v) {out << v;}
      56            0 :         static void read_value(std::istream& in, reference_type v)                  {value_type tmp; in >> tmp; v = tmp;}
      57              : };
      58              : 
      59              : template <>
      60              : struct attachment_io_traits<Attachment<vector1> > {
      61              :         typedef vector1                                                                                                 value_type;
      62              :         typedef attachment_value_traits<value_type>::reference                    reference_type;
      63              :         typedef attachment_value_traits<value_type>::const_reference      const_reference_type;
      64              : 
      65              :         static void write_value (std::ostream& out, const_reference_type v)
      66              :         {
      67            0 :                 out << v[0];
      68              :         }
      69              :         static void read_value(std::istream& in, reference_type v)  
      70              :         {
      71              :                 in >> v[0];
      72              :         }
      73              : };
      74              : 
      75              : 
      76              : template <>
      77              : struct attachment_io_traits<Attachment<vector2> > {
      78              :         typedef vector2                                                                                                 value_type;
      79              :         typedef attachment_value_traits<value_type>::reference                    reference_type;
      80              :         typedef attachment_value_traits<value_type>::const_reference      const_reference_type;
      81              : 
      82            0 :         static void write_value (std::ostream& out, const_reference_type v)
      83              :         {
      84            0 :                 out << v[0] << " " << v[1];
      85            0 :         }
      86              :         static void read_value(std::istream& in, reference_type v)  
      87              :         {
      88              :                 in >> v[0] >> v[1];
      89              :         }
      90              : };
      91              : 
      92              : 
      93              : template <>
      94              : struct attachment_io_traits<Attachment<vector3> > {
      95              :         typedef vector3                                                                                                 value_type;
      96              :         typedef attachment_value_traits<value_type>::reference                    reference_type;
      97              :         typedef attachment_value_traits<value_type>::const_reference      const_reference_type;
      98              : 
      99            0 :         static void write_value (std::ostream& out, const_reference_type v)
     100              :         {
     101            0 :                 out << v[0] << " " << v[1] << " " << v[2];
     102            0 :         }
     103            0 :         static void read_value(std::istream& in, reference_type v)  
     104              :         {
     105              :                 in >> v[0] >> v[1] >> v[2];
     106            0 :         }
     107              : };
     108              : 
     109              : 
     110              : template <>
     111              : struct attachment_io_traits<Attachment<vector4> > {
     112              :         typedef vector4                                                                                                 value_type;
     113              :         typedef attachment_value_traits<value_type>::reference                    reference_type;
     114              :         typedef attachment_value_traits<value_type>::const_reference      const_reference_type;
     115              : 
     116            0 :         static void write_value (std::ostream& out, const_reference_type v)
     117              :         {
     118            0 :                 out << v[0] << " " << v[1] << " " << v[2] << " " << v[3];
     119            0 :         }
     120            0 :         static void read_value(std::istream& in, reference_type v)  
     121              :         {
     122              :                 in >> v[0] >> v[1] >> v[2] >> v[3];
     123            0 :         }
     124              : };
     125              : 
     126              : 
     127              : ////////////////////////////////////////////////////////////////////////////////
     128              : /// serialization for std::vector<T> with type T - e. g. std::vector<bool>
     129              : ////////////////////////////////////////////////////////////////////////////////
     130              : template <typename T>
     131              : struct attachment_io_traits<Attachment<std::vector<T> > >
     132              : /*!
     133              :  * \brief serializes/deserializes an Attachment of std::vector<T>
     134              :  * \note  this is possible whenever the corresponding Attachment<T>
     135              :  *        can be serialized/deserialized (cf. above)
     136              :  */
     137              : {
     138              :         typedef typename std::vector<T>                                                                                   value_type;
     139              :         typedef typename attachment_value_traits<value_type>::reference                   reference_type;
     140              :         typedef typename attachment_value_traits<value_type>::const_reference     const_reference_type;
     141              : 
     142              :         static void write_value (std::ostream& out, const_reference_type v)
     143              :         {
     144              :                 out << v.size() << " ";
     145              :                 for (size_t i = 0; i < v.size(); ++i)
     146              :                         attachment_io_traits<Attachment<T> >::write_value(out, v[i]);
     147              :         }
     148              :         static void read_value(std::istream& in, reference_type v)
     149              :         {
     150              :                 size_t sz;
     151              :                 in >> sz;
     152              :                 v.resize(sz);
     153              :                 for (size_t i = 0; i < sz; ++i)
     154              :                         attachment_io_traits<Attachment<T> >::read_value(in, v[i]);
     155              :         }
     156              : };
     157              : 
     158              : 
     159              : }//     end of namespace
     160              : 
     161              : #endif  //__H__UG_attachment_io_traits
        

Generated by: LCOV version 2.0-1