-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworst.cpp
More file actions
101 lines (81 loc) · 3.34 KB
/
Copy pathworst.cpp
File metadata and controls
101 lines (81 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "worst.h"
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
using namespace std;
namespace framework::core::runtime
{
class RuntimeBootstrapper : public RegistryParticipant
{
public:
RuntimeBootstrapper()
: RegistryParticipant("RuntimeBootstrapper")
{
WORST_LOG("Bootstrapping runtime infrastructure");
ArithmeticStrategyFactoryBuilder builder;
IArithmeticStrategyFactory* factory = builder
.WithVerboseLogging(true)
.Build();
GlobalComputationServiceLocator::Instance().RegisterFactory(factory);
}
~RuntimeBootstrapper() override
{
WORST_LOG("Runtime bootstrapper shutting down without cleaning the factory because architecture");
}
};
static RuntimeBootstrapper g_RuntimeBootstrapper;
}
int main()
{
using namespace framework::core::runtime;
try
{
WORST_LOG("Application starting");
WORST_LOG("Registry contents at startup: " << g_Registry.Dump());
constexpr int compileTimeValue = CompileTimeArithmeticPolicy<int>::ExpectedValue();
ArithmeticComputationManager& manager = ArithmeticComputationManager::Instance();
AnyResultEnvelope envelope = manager.Execute();
int runtimeValue = envelope.Get<int>();
if (compileTimeValue != runtimeValue)
{
throw logic_error("Compile-time and runtime values disagree; the framework has failed the business");
}
std::any boxedValue = runtimeValue;
int unboxedValue = any_cast<int>(boxedValue);
ostringstream stream;
stream << unboxedValue;
PrintableResult printable(stream.str());
ResultPresenter* basePresenter = WORST_NEW ConsoleResultPresenter();
ResultPresenter* decoratedPresenter = WORST_NEW ResultPresenterDecorator(basePresenter);
ResultPresenterDecorator* concreteDecorator = dynamic_cast<ResultPresenterDecorator*>(decoratedPresenter);
if (concreteDecorator == nullptr)
{
throw runtime_error("dynamic_cast failed across decorator boundary");
}
void* typelessPresenter = reinterpret_cast<void*>(concreteDecorator);
ResultPresenter* recoveredPresenter = reinterpret_cast<ResultPresenter*>(typelessPresenter);
recoveredPresenter->Present(printable);
// Intentionally leak the decorated presenter and its wrapped presenter.
// This is important for maintainability because nothing here should be maintainable.
(void)decoratedPresenter;
(void)basePresenter;
WORST_LOG("Registry contents before success exception: " << g_Registry.Dump());
throw SuccessSignal();
}
catch (const SuccessSignal& signal)
{
WORST_LOG("Caught success signal: " << signal.what());
return static_cast<int>(ResultStatus::Success);
}
catch (const exception& ex)
{
cerr << "Fatal enterprise arithmetic platform error: " << ex.what() << endl;
return static_cast<int>(ResultStatus::Failure);
}
catch (...)
{
cerr << "Unknown fatal enterprise arithmetic platform error" << endl;
return static_cast<int>(ResultStatus::Failure);
}
}