Stroika Library 3.0d18
 
Loading...
Searching...
No Matches
WebService/Sources/WSImpl.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Frameworks/StroikaPreComp.h"
5
7#include "Stroika/Foundation/Containers/Mapping.h"
9#include "Stroika/Foundation/IO/Network/HTTP/ClientErrorException.h"
10
11#include "WSImpl.h"
12
13// Comment this in to turn on aggressive noisy DbgTrace in this module
14// #define USE_NOISY_TRACE_IN_THIS_MODULE_ 1
15
16using namespace Stroika::Foundation;
19using namespace Stroika::Foundation::Execution;
20
21using IO ::Network::HTTP::ClientErrorException;
22
23using namespace StroikaSample::WebServices;
24
25namespace {
27}
28
29/*
30 ********************************************************************************
31 ************************************* WSImpl ***********************************
32 ********************************************************************************
33 */
34Collection<String> WSImpl::Variables_GET () const
35{
36 return sVariables_.cget ()->Keys ();
37}
38
39Number WSImpl::Variables_GET (const String& variable) const
40{
41 if (auto o = sVariables_.cget ()->Lookup (variable)) {
42 return *o;
43 }
44 Execution::Throw (ClientErrorException{"no such variable"sv});
45}
46
47void WSImpl::Variables_DELETE (const String& variable) const
48{
49 sVariables_.rwget ()->Remove (variable);
50}
51
52void WSImpl::Variables_SET (const String& variable, const Number& value)
53{
54 sVariables_.rwget ()->Add (variable, value);
55}
56
57Number WSImpl::plus (Number lhs, Number rhs) const
58{
59 return lhs + rhs;
60}
61
62Number WSImpl::minus (Number lhs, Number rhs) const
63{
64 return lhs - rhs;
65}
66
67Number WSImpl::times (Number lhs, Number rhs) const
68{
69 return lhs * rhs;
70}
71
72Number WSImpl::divide (Number lhs, Number rhs) const
73{
74 if (rhs == Number{0}) {
75 // Note - important to use ClientErrorException so web-server returns HTTP status 400, instead of 500
76 Execution::Throw (ClientErrorException{"divide by zero"sv});
77 }
78 return lhs / rhs;
79}
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
A Collection<T> is a container to manage an un-ordered collection of items, without equality defined ...
nonvirtual void Remove(ArgByValueType< value_type > item, EQUALS_COMPARER &&equalsComparer={})
Remove () the argument value (which must exist)
Wrap any object with Synchronized<> and it can be used similarly to the base type,...
void Throw(T &&e2Throw)
identical to builtin C++ 'throw' except that it does helpful, type dependent DbgTrace() messages firs...
Definition Throw.inl:43