PLCnext API Documentation  22.9.0.33
Console.hpp
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 #include "Arp/System/Commons/Text/Formatter.hxx"
9 #include <iostream>
10 #include <mutex>
11 
12 namespace Arp { namespace System { namespace Commons
13 {
14 
15 class Console
16 {
17 public:
18  template<typename... Args> static void Write(const char* pFormat, const Args& ... args);
19  template<typename... Args> static void WriteLine(const char* pFormat, const Args& ... args);
20 
21 private:
22  static std::mutex consoleMutex;
23 };
24 
26 // inline methods of class Console
27 template<typename... Args>
28 inline void Console::WriteLine(const char* pFormat, const Args& ... args)
29 {
30  std::lock_guard<std::mutex> lock(consoleMutex);
31  {
32  std::cout << Text::Formatter::FormatCommon(pFormat, args...) << std::endl;
33  }
34 }
35 
36 template<typename... Args>
37 inline void Console::Write(const char* pFormat, const Args& ... args)
38 {
39  std::lock_guard<std::mutex> lock(consoleMutex);
40  {
41  std::cout << Text::Formatter::FormatCommon(pFormat, args...);
42  }
43 }
44 
45 }}} // end of namespace Arp::System::Commons
Definition: Console.hpp:16
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
@ System
System components used by the System, Device, Plc or Io domains.
Root namespace for the PLCnext API