| 1 |
//***************************************************************************/ |
| 2 |
// This software is released under the 2-Clause BSD license, included |
| 3 |
// below. |
| 4 |
// |
| 5 |
// Copyright (c) 2019, Aous Naman |
| 6 |
// Copyright (c) 2019, Kakadu Software Pty Ltd, Australia |
| 7 |
// Copyright (c) 2019, The University of New South Wales, Australia |
| 8 |
// |
| 9 |
// Redistribution and use in source and binary forms, with or without |
| 10 |
// modification, are permitted provided that the following conditions are |
| 11 |
// met: |
| 12 |
// |
| 13 |
// 1. Redistributions of source code must retain the above copyright |
| 14 |
// notice, this list of conditions and the following disclaimer. |
| 15 |
// |
| 16 |
// 2. Redistributions in binary form must reproduce the above copyright |
| 17 |
// notice, this list of conditions and the following disclaimer in the |
| 18 |
// documentation and/or other materials provided with the distribution. |
| 19 |
// |
| 20 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 21 |
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 22 |
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
| 23 |
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 |
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 |
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED |
| 26 |
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 27 |
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 28 |
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 29 |
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 30 |
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 |
//***************************************************************************/ |
| 32 |
// This file is part of the OpenJPH software implementation. |
| 33 |
// File: ojph_message.h |
| 34 |
// Author: Aous Naman |
| 35 |
// Date: 29 August 2019 |
| 36 |
//***************************************************************************/ |
| 37 |
|
| 38 |
#ifndef OJPH_MESSAGE_H |
| 39 |
#define OJPH_MESSAGE_H |
| 40 |
|
| 41 |
#include <cstring> |
| 42 |
#include "ojph_arch.h" |
| 43 |
|
| 44 |
namespace ojph { |
| 45 |
|
| 46 |
//////////////////////////////////////////////////////////////////////////// |
| 47 |
enum OJPH_MSG_LEVEL : int |
| 48 |
{ |
| 49 |
NO_MSG = 0, |
| 50 |
INFO = 1, |
| 51 |
WARN = 2, |
| 52 |
ERROR = 3 |
| 53 |
}; |
| 54 |
|
| 55 |
//////////////////////////////////////////////////////////////////////////// |
| 56 |
class message_base { |
| 57 |
public: |
| 58 |
OJPH_EXPORT |
| 59 |
virtual void operator() (int warn_code, const char* file_name, |
| 60 |
int line_num, const char *fmt, ...) = 0; |
| 61 |
}; |
| 62 |
|
| 63 |
//////////////////////////////////////////////////////////////////////////// |
| 64 |
class message_info : public message_base |
| 65 |
{ |
| 66 |
public: |
| 67 |
OJPH_EXPORT |
| 68 |
virtual void operator() (int info_code, const char* file_name, |
| 69 |
int line_num, const char* fmt, ...); |
| 70 |
}; |
| 71 |
|
| 72 |
//////////////////////////////////////////////////////////////////////////// |
| 73 |
OJPH_EXPORT |
| 74 |
void set_info_stream(FILE* s); |
| 75 |
OJPH_EXPORT |
| 76 |
void configure_info(message_info* info); |
| 77 |
OJPH_EXPORT |
| 78 |
message_info& get_info(); |
| 79 |
|
| 80 |
//////////////////////////////////////////////////////////////////////////// |
| 81 |
class message_warning : public message_base |
| 82 |
{ |
| 83 |
public: |
| 84 |
OJPH_EXPORT |
| 85 |
virtual void operator() (int warn_code, const char* file_name, |
| 86 |
int line_num, const char* fmt, ...); |
| 87 |
}; |
| 88 |
|
| 89 |
//////////////////////////////////////////////////////////////////////////// |
| 90 |
OJPH_EXPORT |
| 91 |
void set_warning_stream(FILE* s); |
| 92 |
OJPH_EXPORT |
| 93 |
void configure_warning(message_warning* warn); |
| 94 |
OJPH_EXPORT |
| 95 |
message_warning& get_warning(); |
| 96 |
|
| 97 |
//////////////////////////////////////////////////////////////////////////// |
| 98 |
class message_error : public message_base |
| 99 |
{ |
| 100 |
public: |
| 101 |
OJPH_EXPORT |
| 102 |
virtual void operator() (int warn_code, const char* file_name, |
| 103 |
int line_num, const char *fmt, ...); |
| 104 |
}; |
| 105 |
|
| 106 |
//////////////////////////////////////////////////////////////////////////// |
| 107 |
OJPH_EXPORT |
| 108 |
void set_error_stream(FILE *s); |
| 109 |
OJPH_EXPORT |
| 110 |
void configure_error(message_error* error); |
| 111 |
OJPH_EXPORT |
| 112 |
message_error& get_error(); |
| 113 |
} |
| 114 |
|
| 115 |
////////////////////////////////////////////////////////////////////////////// |
| 116 |
#if (defined OJPH_OS_WINDOWS) |
| 117 |
#define __OJPHFILE__ \ |
| 118 |
(strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) |
| 119 |
#else |
| 120 |
#define __OJPHFILE__ \ |
| 121 |
(strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) |
| 122 |
#endif |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
#endif // !OJPH_MESSAGE_H |