OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
SolutionStateIO.h
Go to the documentation of this file.
1//
2// Template SolutionState_t
3// Text (de)serialization helpers for SolutionState_t containers exchanged
4// between MasterNode instances. Replaces boost::archive; requires that the
5// container's value_type provides writeState(std::ostream&) const and
6// readState(std::istream&).
7//
8// Copyright (c) 2026, Paul Scherrer Institut, Villigen PSI, Switzerland
9// All rights reserved
10//
11// This file is part of OPAL.
12//
13// OPAL is free software: you can redistribute it and/or modify
14// it under the terms of the GNU General Public License as published by
15// the Free Software Foundation, either version 3 of the License, or
16// (at your option) any later version.
17//
18// You should have received a copy of the GNU General Public License
19// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
20//
21#ifndef __SOLUTION_STATE_IO__
22#define __SOLUTION_STATE_IO__
23
24#include <ostream>
25#include <istream>
26
27template <class SolutionState_t>
28void writeSolutionState(std::ostream& os, const SolutionState_t& state) {
29 os << state.size();
30 for (const auto& ind : state) {
31 os << ' ';
32 ind.writeState(os);
33 }
34}
35
36template <class SolutionState_t>
37void readSolutionState(std::istream& is, SolutionState_t& state) {
38 size_t n = 0;
39 is >> n;
40 state.resize(n);
41 for (auto& ind : state) {
42 ind.readState(is);
43 }
44}
45
46#endif
void writeSolutionState(std::ostream &os, const SolutionState_t &state)
void readSolutionState(std::istream &is, SolutionState_t &state)