Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Specification.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Frameworks/StroikaPreComp.h"
5
9#include "Stroika/Foundation/Containers/Mapping.h"
13
14#include "Specification.h"
15
16using std::byte;
17
18using namespace Stroika::Foundation;
22
23using namespace Stroika::Frameworks;
24using namespace Stroika::Frameworks::WebService::OpenAPI;
25
26namespace {
27 const String kServersElt_ = "servers"sv;
28 const String kURLElt_ = "url"sv;
29}
30
31namespace {
32 VariantValue rd_ (const Streams::InputStream::Ptr<byte>& b, const optional<DataExchange::InternetMediaType>& mediaType)
33 {
34 if (mediaType) { // only check if specifed, else assume its right
35 InternetMediaTypeRegistry::sThe->CheckIsA (kMediaType, *mediaType);
36 }
38 }
39}
40
41/*
42 ********************************************************************************
43 *********************************** Specification ******************************
44 ********************************************************************************
45 */
46Specification::Specification (const Streams::InputStream::Ptr<byte>& b, const optional<DataExchange::InternetMediaType>& mediaType)
47 : Specification{rd_ (b, mediaType)}
48{
49}
50
51Memory::BLOB Specification::As (const DataExchange::InternetMediaType& mediaType)
52{
53 if (mediaType == kMediaType) {
55 }
56 else {
57 Execution::Throw (Execution::RuntimeErrorException{"Type not supported"sv});
58 }
59}
60
61Sequence<URI> Specification::GetServers () const
62{
63 // @todo store in better internal rep assuring structure already has all these fields... - so the below cannot fail (as is it can)
64 return fValue_.As<Mapping<String, VariantValue>> ().LookupValue (kServersElt_, {}).As<Sequence<VariantValue>> ().Map<Sequence<URI>> ([] (auto vv) {
65 return URI{vv.template As<Mapping<String, VariantValue>> ().LookupValue (kURLElt_).template As<String> ()};
66 });
67}
68
69void Specification::SetServers (const Sequence<URI>& s)
70{
72 vv.Add (kServersElt_, VariantValue{s.Map<Sequence<VariantValue>> (
73 [] (URI u) { return VariantValue{Mapping<String, VariantValue>{{kURLElt_, u.As<String> ()}}}; })});
74 fValue_ = VariantValue{vv};
75}
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
nonvirtual CONTAINER_OF_Key_T As() const
nonvirtual bool Add(ArgByValueType< key_type > key, ArgByValueType< mapped_type > newElt, AddReplaceMode addReplaceMode=AddReplaceMode::eAddReplaces)
Definition Mapping.inl:190
A generalization of a vector: a container whose elements are keyed by the natural numbers.
Definition Sequence.h:187
nonvirtual RESULT_CONTAINER Map(ELEMENT_MAPPER &&elementMapper) const
'override' Iterable<>::Map () function so RESULT_CONTAINER defaults to Sequence, and improve that cas...
Definition Sequence.inl:174
static Execution::Synchronized< InternetMediaTypeRegistry > sThe
nonvirtual Memory::BLOB WriteAsBLOB(const VariantValue &v) const
Definition Writer.cpp:48
Simple variant-value (case variant union) object, with (variant) basic types analogous to a value in ...
InputStream<>::Ptr is Smart pointer (with abstract Rep) class defining the interface to reading from ...
void Throw(T &&e2Throw)
identical to builtin C++ 'throw' except that it does helpful, type dependent DbgTrace() messages firs...
Definition Throw.inl:43