Steppable 0.0.1
A CAS project written from scratch in C++
Loading...
Searching...
No Matches
result.hpp
1/**************************************************************************************************
2 * Copyright (c) 2023-2025 NWSOFT *
3 * *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy *
5 * of this software and associated documentation files (the "Software"), to deal *
6 * in the Software without restriction, including without limitation the rights *
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
8 * copies of the Software, and to permit persons to whom the Software is *
9 * furnished to do so, subject to the following conditions: *
10 * *
11 * The above copyright notice and this permission notice shall be included in all *
12 * copies or substantial portions of the Software. *
13 * *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
20 * SOFTWARE. *
21 **************************************************************************************************/
22
23#pragma once
24
25#include <cstdint>
26#include <output.hpp>
27#include <platform.hpp>
28#include <string>
29#include <util.hpp>
30#include <utility>
31#include <vector>
32
33using namespace std::literals;
34using namespace steppable::__internals::utils;
35
40namespace steppable::types
41{
51
63
70 template<typename StatusType, typename ResultT, StringLiteral ResultTName>
72 {
74 StatusType done;
75
77 std::vector<std::string> inputs;
78
80 std::vector<std::string> outputs;
81
84 ResultT result;
85
86 public:
87 ResultBase() = delete;
88
97 ResultBase(const std::vector<std::string>& _inputs,
98 std::vector<std::string> _out,
99 ResultT result,
100 StatusType _done) :
101 done(_done), inputs(_inputs), outputs(std::move(_out)), result(result)
102 {
103 }
104
106 StatusType getStatus() const { return done; }
107
108 [[nodiscard("Result should be used")]] ResultT getResult() const { return result; }
109
111 [[nodiscard("Output should be used")]] std::string getOutput(size_t idx = 0) const
112 {
113 if (idx >= outputs.size())
114 {
115 output::error("getOutput"s, "Output index out of range"s);
117 }
118 return outputs[idx];
119 }
120
122 [[nodiscard("Inputs should be used")]] std::vector<std::string> getInputs() const { return inputs; }
123 };
124
126 template<typename ResultT>
127 using Result = ResultBase<Status, ResultT, StringLiteral{ "str" }>;
128
130 template<typename ResultT>
131 using ResultBool = ResultBase<StatusBool, ResultT, StringLiteral{ "bool" }>;
132} // namespace steppable::types
A base class for a result of a calculation. You should use the Result and ResultBool aliases instead ...
Definition result.hpp:72
ResultT getResult() const
Definition result.hpp:108
std::vector< std::string > inputs
Definition result.hpp:77
StatusType getStatus() const
Gets how the calculation is done.
Definition result.hpp:106
std::vector< std::string > getInputs() const
Gets the inputs to the calculation.
Definition result.hpp:122
ResultBase(const std::vector< std::string > &_inputs, std::vector< std::string > _out, ResultT result, StatusType _done)
Constructs a new result object.
Definition result.hpp:97
std::string getOutput(size_t idx=0) const
Gets the output of the calculation.
Definition result.hpp:111
std::vector< std::string > outputs
Definition result.hpp:80
The namespace containing utility functions for the Steppable library.
Definition argParse.cpp:40
void programSafeExit(const int status)
Exit the program safely.
Definition platform.hpp:61
void error(const std::string &name, const std::basic_string< T > &msg, const std::vector< std::string > &args={})
Prints an error message.
Definition output.hpp:80
The namespace containing types used in the steppable calculator.
ResultBase< StatusBool, ResultT, StringLiteral{ "bool" }> ResultBool
An alias for a result of a boolean calculation.
Definition result.hpp:131
ResultBase< Status, ResultT, StringLiteral{ "str" }> Result
An alias for a result of a calculation. This represents a calculation with a Status status.
Definition result.hpp:127
Status
The status of the calculation.
Definition result.hpp:46
@ MATH_ERROR
The calculation is not done because of an error.
Definition result.hpp:49
@ CALCULATED_UNSIMPLIFIED
The calculation is done.
Definition result.hpp:48
@ CALCULATED_SIMPLIFIED
The calculation is done by taking simplified steps.
Definition result.hpp:47
StatusBool
The status of a boolean calculation.
Definition result.hpp:56
@ CALCULATED_UNSIMPLIFIED_YES
The calculation is done, the result it True.
Definition result.hpp:59
@ CALCULATED_SIMPLIFIED_NO
The calculation is done by taking simplified steps, the result it False.
Definition result.hpp:58
@ CALCULATED_UNSIMPLIFIED_NO
The calculation is done, the result it False.
Definition result.hpp:60
@ CALCULATED_SIMPLIFIED_YES
The calculation is done by taking simplified steps, the result it True.
Definition result.hpp:57
String literal workaround for templates.
Definition util.hpp:228
Untitled