Mantid
Loading...
Searching...
No Matches
OptionalBool.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8
9#include <json/value.h>
10
11#include <ostream>
12#include <utility>
13
14namespace Mantid::Kernel {
15
16const std::string OptionalBool::StrUnset = "Unset";
17const std::string OptionalBool::StrFalse = "False";
18const std::string OptionalBool::StrTrue = "True";
19
20OptionalBool::OptionalBool() : m_arg(Unset) {}
21
23
25
26bool OptionalBool::operator==(const OptionalBool &other) const { return m_arg == other.getValue(); }
27
28bool OptionalBool::operator!=(const OptionalBool &other) const { return m_arg != other.getValue(); }
29
31
32std::ostream &operator<<(std::ostream &os, OptionalBool const &object) {
33 os << OptionalBool::enumToStrMap()[object.getValue()];
34 return os;
35}
36
37std::istream &operator>>(std::istream &istream, OptionalBool &object) {
38 std::string result;
39 istream >> result;
40 object.m_arg = OptionalBool::strToEmumMap()[result];
41 return istream;
42}
43
44std::map<std::string, OptionalBool::Value> OptionalBool::strToEmumMap() {
46}
47
48std::map<OptionalBool::Value, std::string> OptionalBool::enumToStrMap() {
49 std::map<Value, std::string> map;
50 auto opposite = strToEmumMap();
51 for (auto &oppositePair : opposite) {
52 map.emplace(oppositePair.second, oppositePair.first);
53 }
54 return map;
55}
56
62Json::Value encodeAsJson(const OptionalBool &value) {
63 const auto enumValue = value.getValue();
64 if (enumValue == OptionalBool::True)
65 return Json::Value(true);
66 else if (enumValue == OptionalBool::False)
67 return Json::Value(false);
68 else
69 return Json::Value();
70}
71
72// Specialization of ToCpp for OptionalBool
73namespace pwvjdetail {
74
75bool ToCpp<OptionalBool>::operator()(const Json::Value &value) { return value.asBool(); }
76
77} // namespace pwvjdetail
78
79} // namespace Mantid::Kernel
double value
The value of the point.
Definition: FitMW.cpp:51
OptionalBool : Tri-state bool.
Definition: OptionalBool.h:25
static std::map< Value, std::string > enumToStrMap()
static std::map< std::string, Value > strToEmumMap()
bool operator==(const OptionalBool &other) const
bool operator!=(const OptionalBool &other) const
static const std::string StrUnset
Definition: OptionalBool.h:30
static const std::string StrFalse
Definition: OptionalBool.h:31
static const std::string StrTrue
Definition: OptionalBool.h:32
MANTID_KERNEL_DLL std::ostream & operator<<(std::ostream &, CPUTimer &)
Convenience function to provide for easier debug printing.
Definition: CPUTimer.cpp:86
MANTID_KERNEL_DLL std::istream & operator>>(std::istream &, Interpolation &)
Reads in parameter value.
MANTID_KERNEL_DLL::Json::Value encodeAsJson(const OptionalBool &)
Encode an OptionalBool as a Json::Value.