OnixS C++ ICE Binary Order Entry Handler 1.2.3
API Documentation
Loading...
Searching...
No Matches
Formatting.h
Go to the documentation of this file.
1/*
2 * Copyright Onix Solutions Limited [OnixS]. All rights reserved.
3 *
4 * This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
5 * and international copyright treaties.
6 *
7 * Access to and use of the software is governed by the terms of the applicable OnixS Software
8 * Services Agreement (the Agreement) and Customer end user license agreements granting
9 * a non-assignable, non-transferable and non-exclusive license to use the software
10 * for it's own data processing purposes under the terms defined in the Agreement.
11 *
12 * Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
13 * of this source code or associated reference material to any other location for further reproduction
14 * or redistribution, and any amendments to this copyright notice, are expressly prohibited.
15 *
16 * Any reproduction or redistribution for sale or hiring of the Software not in accordance with
17 * the terms of the Agreement is a violation of copyright law.
18 */
19#pragma once
20
21#include <OnixS/ICE/BOE/ABI.h>
25
26#include <exception>
27#include <string>
28
30
33std::string format(Int32 index, StrRef input);
34
36{
37 return value ? *value : StrRef{};
38}
39
40inline StrRef unwrap(StrRef value)
41{
42 return value;
43}
44
55template <typename Message>
57std::string format(const Message message)
58{
59 const auto code = message.exchangeCode();
60
61 if(!code)
62 return {};
63
64 try
65 {
66 return format(*code, unwrap(message.text()));
67 }
68 catch(const std::exception& e)
69 {
70 return std::string("Exception while description formatting: ") + e.what();
71 }
72}
73
74namespace details {
79 template<typename T>
80 struct hasText
81 {
82 template<typename U> static auto test(int) -> typename std::enable_if<noexcept(std::declval<const U&>().text()), char>::type;
83 template<typename U> static int test(...);
84 static constexpr bool value = sizeof(test<T>(0)) == sizeof(char);
85 };
86
87 template<typename T>
89 {
90 template<typename U> static auto test(int) -> typename std::enable_if<noexcept(std::declval<const U&>().exchangeCode()), char>::type;
91 template<typename U> static int test(...);
92 static constexpr bool value = sizeof(test<T>(0)) == sizeof(char);
93 };
94
95 template <typename T>
97 : std::integral_constant<bool, std::is_base_of<BinaryBlockBase, T>::value && hasText<T>::value && hasExchangeCode<T>::value> {};
98}
99
100template <typename T> struct isFormattableMsg : public details::isFormattableMsgImpl<cleanType<T>> {};
101
102template <typename Message>
104std::string formatMsg(const Message message, typename std::enable_if<isFormattableMsg<Message>::value, void*>::type = nullptr)
105{
106 return format(message);
107}
108
109template <typename Message>
111std::string formatMsg(const Message, typename std::enable_if<!isFormattableMsg<Message>::value, void*>::type = nullptr)
112{
113 return "";
114}
115
#define ONIXS_ICEBOE_MESSAGING_NAMESPACE_BEGIN
Definition ABI.h:102
#define ONIXS_ICEBOE_MESSAGING_NAMESPACE_END
Definition ABI.h:106
#define ONIXS_ICEBOE_EXPORTED
Definition Compiler.h:154
#define ONIXS_ICEBOE_NODISCARD
Definition Compiler.h:155
std::string formatMsg(const Message message, typename std::enable_if< isFormattableMsg< Message >::value, void * >::type=nullptr)
Definition Formatting.h:104
StrRef unwrap(SbeOptionalStr value)
Definition Formatting.h:35
std::string format(Int32 index, StrRef input)
std::basic_string_view< Char > StrRef
Definition StrRef.h:46
static auto test(int) -> typename std::enable_if< noexcept(std::declval< const U & >().exchangeCode()), char >::type
Both getters can be inherited rather than declared by T itself - MessageHolder hands out a HeldAdapte...
Definition Formatting.h:81
static auto test(int) -> typename std::enable_if< noexcept(std::declval< const U & >().text()), char >::type