PLCnext API Documentation  22.9.0.33
Formatter.hxx
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 #include "Arp/System/Commons/Exceptions/InvalidFormatException.hpp"
9 
10 namespace Arp { namespace System { namespace Commons { namespace Text
11 {
12 
13 class Formatter
14 {
15 private: // usings
17 
18 public: // 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 
31 private: // methods
32  static void OnInvalidFormatOperationOccurs(const char* formatString, const char* errorMessage);
33 };
34 
36 // inline methods of class Formatter
38 template<typename... Args>
39 inline String Formatter::FormatCommon(const String& format, const Args& ... args)
40 {
41  return FormatCommon(format.CStr(), args...);
42 }
43 
45 template<typename... Args>
46 inline String Formatter::FormatCommon(const char* format, const Args& ... args)
47 {
48  return BasicFormatterType::FormatCommon(&OnInvalidFormatOperationOccurs, format, args...);
49 }
50 
52 template<typename... Args>
53 inline String Formatter::FormatPrintf(const String& format, const Args& ... args)
54 {
55  return FormatPrintf(format.CStr(), args...);
56 }
57 
59 template<typename... Args>
60 inline String Formatter::FormatPrintf(const char* format, const Args& ... args)
61 {
62  return BasicFormatterType::FormatPrintf(&OnInvalidFormatOperationOccurs, format, args...);
63 }
64 
65 inline 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:27
static StringType FormatPrintf(ExceptionHandler exceptionHandler, const StringType &format, const Args &... args)
Uses Ansi-C printf syntax for the placeholders in the format string like 's'.
Definition: BasicFormatter.hxx:77
static StringType FormatCommon(ExceptionHandler exceptionHandler, const StringType &format, const Args &... args)
Uses common CLR syntax (.Net) for the placeholders in the format string like '{0}'.
Definition: BasicFormatter.hxx:55
static InvalidFormatException Create(const char *formatString)
Creates an InvalidFormatException instance using a default message text.
Definition: InvalidFormatException.hpp:77
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
const CharType * CStr() const
Gets the character data of this string.
Definition: BasicString.hxx:1508
@ System
System components used by the System, Device, Plc or Io domains.
Root namespace for the PLCnext API