DryChem 1.0.0
A generic, compile-time C++ toolbox with no dependencies for the modern computational chemistry project.
Loading...
Searching...
No Matches
stringDetails.hpp
Go to the documentation of this file.
1// Copyright (c) 2020-2025 Cody R. Drisko. All rights reserved.
2// Licensed under the MIT License. See the LICENSE file in the project root for more information.
3//
4// Name: stringDetails.hpp
5// Author: crdrisko
6// Date: 11/15/2020-07:26:05
7// Description: Details to be used with the testing of the strings library
8
9#ifndef DRYCHEM_COMMON_UTILITIES_LIBS_STRINGS_TESTS_DETAILS_STRINGDETAILS_HPP
10#define DRYCHEM_COMMON_UTILITIES_LIBS_STRINGS_TESTS_DETAILS_STRINGDETAILS_HPP
11
12#include <iostream>
13#include <string>
14
16{
18 {
19 private:
20 int val {};
21
22 public:
23 GoodValue() = default;
24 explicit GoodValue(int Val) : val {Val} {}
25
26 int getValue() const { return val; }
27
28 friend std::istream& operator>>(std::istream& stream, GoodValue& rhs)
29 {
30 std::string str {};
31 stream >> str;
32
33 rhs.val = std::stoi(str);
34
35 return stream;
36 }
37 };
38
39 class BadValue : public GoodValue
40 {
41 public:
42 BadValue() = default;
43 explicit BadValue(int Val) : GoodValue {Val} {}
44
45 friend std::istream& operator>>(std::istream& stream, BadValue&)
46 {
47 stream.setstate(std::ios::badbit);
48
49 return stream;
50 }
51 };
52
53 class FailValue : public GoodValue
54 {
55 public:
56 FailValue() = default;
57 explicit FailValue(int Val) : GoodValue {Val} {}
58
59 friend std::istream& operator>>(std::istream& stream, FailValue&)
60 {
61 stream.setstate(std::ios::failbit);
62
63 return stream;
64 }
65 };
66} // namespace CppUtils::Strings::details::testing
67
68#endif
friend std::istream & operator>>(std::istream &stream, BadValue &)
Definition stringDetails.hpp:45
BadValue(int Val)
Definition stringDetails.hpp:43
FailValue(int Val)
Definition stringDetails.hpp:57
friend std::istream & operator>>(std::istream &stream, FailValue &)
Definition stringDetails.hpp:59
int getValue() const
Definition stringDetails.hpp:26
friend std::istream & operator>>(std::istream &stream, GoodValue &rhs)
Definition stringDetails.hpp:28
GoodValue(int Val)
Definition stringDetails.hpp:24
int val
Definition stringDetails.hpp:20
Definition stringDetails.hpp:16