PLCnext API Documentation 25.0.2.69
Formatter.hxx
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
4//
6#pragma once
8#include "Arp/System/Commons/Exceptions/InvalidFormatException.hpp"
9
10namespace Arp { namespace System { namespace Commons { namespace Text
11{
12
14{
15private: // usings
17
18public: // operations
19 template<typename... Args>
20 static String FormatCommon(const String& format, const Args& ... args);
21
22 template<typename... Args>
23 static String FormatCommon(const char* format, const Args& ... args);
24
25 template<typename... Args>
26 static String FormatPrintf(const String& format, const Args& ... args);
27
28 template<typename... Args>
29 static String FormatPrintf(const char* format, const Args& ... args);
30
31private: // methods
32 static void OnInvalidFormatOperationOccurs(const char* formatString, const char* errorMessage);
33};
34
36// inline methods of class Formatter
38template<typename... Args>
39inline String Formatter::FormatCommon(const String& format, const Args& ... args)
40{
41 return FormatCommon(format.CStr(), args...);
42}
43
45template<typename... Args>
46inline String Formatter::FormatCommon(const char* format, const Args& ... args)
47{
48 return BasicFormatterType::FormatCommon(&OnInvalidFormatOperationOccurs, format, args...);
49}
50
52template<typename... Args>
53inline String Formatter::FormatPrintf(const String& format, const Args& ... args)
54{
55 return FormatPrintf(format.CStr(), args...);
56}
57
59template<typename... Args>
60inline String Formatter::FormatPrintf(const char* format, const Args& ... args)
61{
62 return BasicFormatterType::FormatPrintf(&OnInvalidFormatOperationOccurs, format, args...);
63}
64
65inline void Formatter::OnInvalidFormatOperationOccurs(const char* formatString, const char* errorMessage)
66{
67 throw InvalidFormatException::Create(formatString, errorMessage);
68}
69
70}}}} // end of namespace Arp::System::Commons::Text
This class encapsulates formatting operations which are based on the open source library libfmt forme...
Definition: BasicFormatter.hxx:32
static StringType FormatPrintf(ExceptionHandler exceptionHandler, const StringType &format, Args &&... args)
Uses Ansi-C printf syntax for the placeholders in the format string like 's'.
Definition: BasicFormatter.hxx:82
static StringType FormatCommon(ExceptionHandler exceptionHandler, const StringType &format, Args &&... args)
Uses common CLR syntax (.Net) for the placeholders in the format string like '{0}'.
Definition: BasicFormatter.hxx:60
This class represents the Arp String. The implementation is based on std::string.
Definition: String.hpp:39
const CharType * CStr(void) const
Gets the character data of this string.
Definition: String.ipp:1395
static InvalidFormatException Create(const char *formatString)
Creates an InvalidFormatException instance using a default message text.
Definition: InvalidFormatException.cpp:46
Definition: Formatter.hxx:14
static String FormatPrintf(const String &format, const Args &... args)
Uses Ansi-C printf syntax for the placeholders in the format string like 's'.
Definition: Formatter.hxx:53
static String FormatCommon(const String &format, const Args &... args)
Uses common CLR syntax (.Net) for the placeholders in the format string like '{0}'.
Definition: Formatter.hxx:39
Root namespace for the PLCnext API