libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRNConsoleMessenger.cpp
Go to the documentation of this file.
1 /* Copyright 2009-2016 INSA Lyon, ENS-Lyon
2  *
3  * This file is part of libcrn.
4  *
5  * libcrn is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * libcrn is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with libcrn. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * file: CRNConsoleMessenger.cpp
19  * \author Yann LEYDIER
20  */
21 
23 #ifdef CRN_C_CONSOLE_MESSENGER
24 # include <stdio.h>
25 #else
26 # include <iostream>
27 #endif
28 #include <CRNi18n.h>
29 
30 using namespace crn;
31 
34 {
35  DebugPrefix = String(U"[") + _("DEBUG") + String(U"] ");
36  VerbosePrefix = U"[libcrn] ";
37  WarningPrefix = String(U"[") + _("WARNING") + String(U"] ");
38  ErrorPrefix = String(U"[") + _("ERROR") + String(U"] ");
39 }
40 
42 
45 {
46 #ifdef CRN_C_CONSOLE_MESSENGER
47  printf("%s%s\n", DebugPrefix.CStr(), msg.CStr());
48 #else
49  std::cout << DebugPrefix.CStr() << msg.CStr() << std::endl;
50 #endif
51 }
52 
55 {
56 #ifdef CRN_C_CONSOLE_MESSENGER
57  printf("%s%s\n", VerbosePrefix.CStr(), msg.CStr());
58 #else
59  std::cout << VerbosePrefix.CStr() << msg.CStr() << std::endl;
60 #endif
61 }
62 
65 {
66 #ifdef CRN_C_CONSOLE_MESSENGER
67  printf("%s%s\n", WarningPrefix.CStr(), msg.CStr());
68 #else
69  std::cout << WarningPrefix.CStr() << msg.CStr() << std::endl;
70 #endif
71 }
72 
75 {
76 #ifdef CRN_C_CONSOLE_MESSENGER
77  printf("%s%s\n", ErrorPrefix.CStr(), msg.CStr());
78 #else
79  std::cerr << ErrorPrefix.CStr() << msg.CStr() << std::endl;
80 #endif
81 }
82 
83 
String WarningPrefix
Definition: CRNMessenger.h:53
#define _(String)
Definition: CRNi18n.h:51
const char * CStr() const
Conversion to UTF8 cstring.
Definition: CRNString.cpp:167
virtual void PrintVerbose(const String &msg) override
Prints a message.
ConsoleMessenger()
Default constructor.
A UTF32 character string class.
Definition: CRNString.h:61
virtual void PrintWarning(const String &msg) override
Prints a warning message.
String DebugPrefix
Definition: CRNMessenger.h:53
String ErrorPrefix
Definition: CRNMessenger.h:53
String VerbosePrefix
Definition: CRNMessenger.h:53
virtual ~ConsoleMessenger() override
virtual void PrintDebug(const String &msg) override
Prints a debug message.
virtual void PrintError(const String &msg) override
Prints an error message.