GridFire 0.0.1a General Purpose Nuclear Network

Loading...
Searching...
No Matches
expected_engine.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <iostream>
5
6 namespace gridfire::expectations {
7 enum class EngineErrorTypes {
8 FAILURE,
9 INDEX,
10 STALE
11 };
12
13 enum class StaleEngineErrorTypes {
14 SYSTEM_RESIZED
15 };
16
17 // TODO: rename this to EngineExpectation or something similar
18 struct EngineError {
19 std::string m_message;
20 const EngineErrorTypes type = EngineErrorTypes::FAILURE;
21
22 explicit EngineError(const std::string &message, const EngineErrorTypes type)
23 : m_message(message), type(type) {}
24
25 virtual ~EngineError() = default;
26
27 friend std::ostream& operator<<(std::ostream& os, const EngineError& e) {
28 os << "EngineError: " << e.m_message;
29 return os;
30 }
31 };
32
33 struct EngineIndexError : EngineError {
34 int m_index;
35
36 explicit EngineIndexError(const int index)
37 : EngineError("Index error occurred", EngineErrorTypes::INDEX), m_index(index) {}
38 friend std::ostream& operator<<(std::ostream& os, const EngineIndexError& e) {
39 os << "EngineIndexError: " << e.m_message << " at index " << e.m_index;
40 return os;
41 }
42 };
43
44 struct StaleEngineError : EngineError {
45 StaleEngineErrorTypes staleType;
46
47 explicit StaleEngineError(const StaleEngineErrorTypes sType)
48 : EngineError("Stale engine error occurred", EngineErrorTypes::STALE), staleType(sType) {}
49
50 explicit operator std::string() const {
51 switch (staleType) {
52 case (StaleEngineErrorTypes::SYSTEM_RESIZED):
53 return "StaleEngineError: System resized, please update the engine.";
54 default:
55 return "StaleEngineError: Unknown stale error type.";
56 }
57 }
58 };
59}
gridfire::expectations
Definition expected_engine.h:6
gridfire::expectations::EngineErrorTypes
EngineErrorTypes
Definition expected_engine.h:7
gridfire::expectations::EngineErrorTypes::FAILURE
@ FAILURE
Definition expected_engine.h:8
gridfire::expectations::EngineErrorTypes::STALE
@ STALE
Definition expected_engine.h:10
gridfire::expectations::EngineErrorTypes::INDEX
@ INDEX
Definition expected_engine.h:9
gridfire::expectations::StaleEngineErrorTypes
StaleEngineErrorTypes
Definition expected_engine.h:13
gridfire::expectations::StaleEngineErrorTypes::SYSTEM_RESIZED
@ SYSTEM_RESIZED
Definition expected_engine.h:14
gridfire::expectations::EngineError::~EngineError
virtual ~EngineError()=default
gridfire::expectations::EngineError::operator<<
friend std::ostream & operator<<(std::ostream &os, const EngineError &e)
Definition expected_engine.h:27
gridfire::expectations::EngineError::type
const EngineErrorTypes type
Definition expected_engine.h:20
gridfire::expectations::EngineError::m_message
std::string m_message
Definition expected_engine.h:19
gridfire::expectations::EngineError::EngineError
EngineError(const std::string &message, const EngineErrorTypes type)
Definition expected_engine.h:22
gridfire::expectations::EngineIndexError::m_index
int m_index
Definition expected_engine.h:34
gridfire::expectations::EngineIndexError::EngineIndexError
EngineIndexError(const int index)
Definition expected_engine.h:36
gridfire::expectations::EngineIndexError::operator<<
friend std::ostream & operator<<(std::ostream &os, const EngineIndexError &e)
Definition expected_engine.h:38
gridfire::expectations::StaleEngineError::staleType
StaleEngineErrorTypes staleType
Definition expected_engine.h:45
gridfire::expectations::StaleEngineError::StaleEngineError
StaleEngineError(const StaleEngineErrorTypes sType)
Definition expected_engine.h:47