MFEM  v4.1.0
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
binaryio.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2020, Lawrence Livermore National Security, LLC. Produced
2 // at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3 // LICENSE and NOTICE for details. LLNL-CODE-806117.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability visit https://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the BSD-3 license. We welcome feedback and contributions, see file
10 // CONTRIBUTING.md for details.
11 
12 #ifndef MFEM_BINARYIO
13 #define MFEM_BINARYIO
14 
15 #include "../config/config.hpp"
16 
17 #include <iostream>
18 #include <vector>
19 
20 namespace mfem
21 {
22 
23 // binary I/O helpers
24 
25 namespace bin_io
26 {
27 
28 template<typename T>
29 inline void write(std::ostream& os, T value)
30 {
31  os.write((char*) &value, sizeof(T));
32 }
33 
34 template<typename T>
35 inline T read(std::istream& is)
36 {
37  T value;
38  is.read((char*) &value, sizeof(T));
39  return value;
40 }
41 
42 template <typename T>
43 void AppendBytes(std::vector<char> &vec, const T &val)
44 {
45  const char *ptr = reinterpret_cast<const char*>(&val);
46  vec.insert(vec.end(), ptr, ptr + sizeof(T));
47 }
48 
49 void WriteBase64(std::ostream &out, const void *bytes, size_t length);
50 
51 } // namespace mfem::bin_io
52 
53 } // namespace mfem
54 
55 #endif
void write(std::ostream &os, T value)
Definition: binaryio.hpp:29
void WriteBase64(std::ostream &out, const void *bytes, size_t nbytes)
Definition: binaryio.cpp:25
T read(std::istream &is)
Definition: binaryio.hpp:35
void AppendBytes(std::vector< char > &vec, const T &val)
Definition: binaryio.hpp:43
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
Definition: globals.hpp:66