OnixS C++ ICE Binary Order Entry Handler 1.0.0
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 <string>
27
29
32std::string format(Int32 index, StrRef input);
33
35{
36 return value ? *value : StrRef{};
37}
38
39inline StrRef unwrap(StrRef value)
40{
41 return value;
42}
43
44template <typename Message>
46std::string format(const Message message)
47{
48 const auto code = message.exchangeCode();
49 const auto text = message.text();
50
51 if(code)
52 return format(*code, unwrap(text));
53
54 return "";
55}
56
57namespace details {
58 template<typename T>
59 struct hasText
60 {
61 template<typename U, typename V, V (U::*)() const noexcept> struct SFINAE {};
62 template<typename U> static char test(SFINAE<U, decltype(std::declval<const U&>().text()), &U::text>*);
63 template<typename U> static int test(...);
64 static constexpr bool value = sizeof(test<T>(nullptr)) == sizeof(char);
65 };
66
67 template<typename T>
69 {
70 template<typename U, typename V, V (U::*)() const noexcept> struct SFINAE {};
71 template<typename U> static char test(SFINAE<U, decltype(std::declval<const U&>().exchangeCode()), &U::exchangeCode>*);
72 template<typename U> static int test(...);
73 static constexpr bool value = sizeof(test<T>(nullptr)) == sizeof(char);
74 };
75
76 template <typename T>
78 : std::integral_constant<bool, std::is_base_of<BinaryBlockBase, T>::value && hasText<T>::value && hasExchangeCode<T>::value> {};
79}
80
81template <typename T> struct isFormattableMsg : public details::isFormattableMsgImpl<cleanType<T>> {};
82
83template <typename Message>
85std::string formatMsg(const Message message, typename std::enable_if<isFormattableMsg<Message>::value, void*>::type = nullptr)
86{
87 return format(message);
88}
89
90template <typename Message>
92std::string formatMsg(const Message, typename std::enable_if<!isFormattableMsg<Message>::value, void*>::type = nullptr)
93{
94 return "";
95}
96
#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:153
#define ONIXS_ICEBOE_NODISCARD
Definition Compiler.h:154
std::string formatMsg(const Message message, typename std::enable_if< isFormattableMsg< Message >::value, void * >::type=nullptr)
Definition Formatting.h:85
StrRef unwrap(SbeOptionalStr value)
Definition Formatting.h:34
std::string format(Int32 index, StrRef input)
std::basic_string_view< Char > StrRef
Definition StrRef.h:46
static char test(SFINAE< U, decltype(std::declval< const U & >().exchangeCode()), &U::exchangeCode > *)
static char test(SFINAE< U, decltype(std::declval< const U & >().text()), &U::text > *)