PSCF v1.4.0
Ensemble.cpp
1/*
2* PSCF - Polymer Self-Consistent Field
3*
4* Copyright 2015 - 2025, The Regents of the University of Minnesota
5* Distributed under the terms of the GNU General Public License.
6*/
7
8#include "Ensemble.h"
9
10namespace Pscf {
11
12 using namespace Util;
13
14 /*
15 * Extract a Ensemble from an istream as a string.
16 */
17 std::istream& operator >> (std::istream& in, Ensemble& policy)
18 {
19 std::string buffer;
20 in >> buffer;
21 if (buffer == "Closed" || buffer == "closed") {
22 policy = Ensemble::Closed;
23 } else
24 if (buffer == "Open" || buffer == "open") {
25 policy = Ensemble::Open;
26 } else {
27 UTIL_THROW("Invalid Ensemble enum string in operator >>");
28 }
29 return in;
30 }
31
32 /*
33 * Insert a Ensemble to an ostream as a string.
34 */
35 std::ostream& operator<<(std::ostream& out, Ensemble policy)
36 {
37 if (policy == Ensemble::Closed) {
38 out << "Closed";
39 } else
40 if (policy == Ensemble::Open) {
41 out << "Open";
42 } else
43 if (policy == Ensemble::Unknown) {
44 out << "Unknown";
45 } else {
46 std::cout << "Invalid Ensemble enum value on input"
47 << std::endl;
48 UTIL_THROW("Unrecognized value for Ensemble enum");
49 }
50 return out;
51 }
52
53} // namespace Pscf
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition global.h:49
Ensemble
Statistical ensemble type for the number of molecules of one species.
Definition Ensemble.h:23
PSCF package top-level namespace.
std::istream & operator>>(std::istream &in, Pair< Data > &pair)
Input a Pair from an istream.
Definition Pair.h:44
std::ostream & operator<<(std::ostream &out, const Pair< Data > &pair)
Output a Pair to an ostream, without line breaks.
Definition Pair.h:57