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 <output.hpp>
26#include <platform.hpp>
27#include <string>
28#include <util.hpp>
29#include <utility>
30#include <vector>
31
32using namespace std::literals;
33using namespace steppable::__internals::utils;
34
39namespace steppable::types
40{
50
62
69 template<typename StatusType, typename ResultT, StringLiteral ResultTName>
71 {
73 StatusType done;
74
76 std::vector<std::string> inputs;
77
79 std::vector<std::string> outputs;
80
83 ResultT result;
84
85 public:
86 ResultBase() = delete;
87
96 ResultBase(const std::vector<std::string>& _inputs,
97 std::vector<std::string> _out,
98 ResultT result,
99 StatusType _done) :
100 done(_done), inputs(_inputs), outputs(std::move(_out)), result(result)
101 {
102 }
103
105 StatusType getStatus() const { return done; }
106
107 [[nodiscard("Result should be used")]] ResultT getResult() const { return result; }
108
110 [[nodiscard("Output should be used")]] std::string getOutput(size_t idx = 0) const
111 {
112 if (idx >= outputs.size())
113 {
114 output::error("getOutput"s, "Output index out of range"s);
116 }
117 return outputs[idx];
118 }
119
121 [[nodiscard("Inputs should be used")]] std::vector<std::string> getInputs() const { return inputs; }
122 };
123
125 template<typename ResultT>
126 using Result = ResultBase<Status, ResultT, StringLiteral{ "str" }>;
127
129 template<typename ResultT>
130 using ResultBool = ResultBase<StatusBool, ResultT, StringLiteral{ "bool" }>;
131} // namespace steppable::types
A base class for a result of a calculation. You should use the Result and ResultBool aliases instead ...
Definition result.hpp:71
ResultT getResult() const
Definition result.hpp:107
std::vector< std::string > inputs
Definition result.hpp:76
StatusType getStatus() const
Gets how the calculation is done.
Definition result.hpp:105
std::vector< std::string > getInputs() const
Gets the inputs to the calculation.
Definition result.hpp:121
ResultBase(const std::vector< std::string > &_inputs, std::vector< std::string > _out, ResultT result, StatusType _done)
Constructs a new result object.
Definition result.hpp:96
std::string getOutput(size_t idx=0) const
Gets the output of the calculation.
Definition result.hpp:110
std::vector< std::string > outputs
Definition result.hpp:79
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:59
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:130
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:126
Status
The status of the calculation.
Definition result.hpp:45
@ MATH_ERROR
Definition result.hpp:48
@ CALCULATED_UNSIMPLIFIED
Definition result.hpp:47
@ CALCULATED_SIMPLIFIED
Definition result.hpp:46
StatusBool
The status of a boolean calculation.
Definition result.hpp:55
@ CALCULATED_UNSIMPLIFIED_YES
Definition result.hpp:58
@ CALCULATED_SIMPLIFIED_NO
Definition result.hpp:57
@ CALCULATED_UNSIMPLIFIED_NO
Definition result.hpp:59
@ CALCULATED_SIMPLIFIED_YES
Definition result.hpp:56
String literal workaround for templates.
Definition util.hpp:223
Untitled