All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
system_message.hpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2015
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
15 #ifndef PAAL_SYSTEM_MESSAGE_HPP
16 #define PAAL_SYSTEM_MESSAGE_HPP
17 
18 #include <string>
19 #include <cstdlib>
20 #include <iostream>
21 
22 namespace paal {
23 
24 namespace utils {
25 
27 inline auto print_message(std::ostream &output_stream) {
28  output_stream << std::endl;
29 }
30 
32 template <typename Arg, typename ...Args>
33 auto print_message(std::ostream &output_stream, Arg &&arg, Args... args) {
34  output_stream << arg;
35  print_message(output_stream, std::forward<Args>(args)...);
36 }
37 
39 template <typename Arg, typename ...Args>
40 auto info(Arg &&arg, Args... args) {
41  print_message(std::cout, std::forward<Arg>(arg), std::forward<Args>(args)...);
42 }
43 
45 template <typename Arg, typename ...Args>
46 auto warning(Arg &&arg, Args... args) {
47  static const std::string message_prefix = "Warning: ";
48  print_message(std::cerr, message_prefix, std::forward<Arg>(arg), std::forward<Args>(args)...);
49 }
50 
52 template <typename Arg, typename ...Args>
53 auto failure(Arg &&arg, Args... args) {
54  static const std::string message_prefix = "Failure: ";
55  print_message(std::cerr, message_prefix, std::forward<Arg>(arg), std::forward<Args>(args)...);
56  std::exit(EXIT_FAILURE);
57 }
58 
62  template <typename Arg, typename ...Args>
63  void operator()(Arg &&arg, Args... args) {
64  failure(std::forward<Arg>(arg), std::forward<Args>(args)...);
65  }
66 };
67 
68 } // utils
69 
70 } // paal
71 
72 #endif // PAAL_SYSTEM_MESSAGE_HPP
73 
auto info(Arg &&arg, Args...args)
prints info message
void operator()(Arg &&arg, Args...args)
operator()
auto warning(Arg &&arg, Args...args)
prints warning message
Functor prints failure message.
auto failure(Arg &&arg, Args...args)
prints failure message
auto print_message(std::ostream &output_stream)
prints message (specialization for empty message)