Antares Xpansion
Investment simulations for Antares studies
Loading...
Searching...
No Matches
ProblemFormatStream.h
1#pragma once
2
3#include <fmt/format.h>
4#include <istream>
5#include <ostream>
6#include <string>
7
8#include "antares-xpansion/core/ProblemFormat.h"
9
10inline std::ostream& operator<<(std::ostream& stream, const ProblemsFormat& rhs)
11{
12 switch (rhs)
13 {
14 case ProblemsFormat::MPS_FILE:
15 stream << "MPS";
16 break;
17 case ProblemsFormat::OPTIMIZED:
18 stream << "OPTIMIZED";
19 break;
20 default:
21 stream << "Unknown";
22 }
23 return stream;
24}
25
26inline std::istream& operator>>(std::istream& stream, ProblemsFormat& rhs)
27{
28 std::string str;
29 stream >> str;
30 if (stream)
31 {
32 try
33 {
34 rhs = problemsFormatFromString(str);
35 }
36 catch (const std::runtime_error&)
37 {
38 stream.setstate(std::ios::failbit);
39 throw;
40 }
41 }
42 return stream;
43}
44
45template<>
46struct fmt::formatter<ProblemsFormat>: formatter<string_view>
47{
48 // parse is inherited from formatter<string_view>.
49
50 auto format(ProblemsFormat problems_format,
51 format_context& ctx) const -> format_context::iterator;
52};