Grok  7.6.3
ojph_message.h
Go to the documentation of this file.
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 
47  enum OJPH_MSG_LEVEL : int
48  {
49  NO_MSG = 0,
50  INFO = 1,
51  WARN = 2,
52  ERROR = 3
53  };
54 
56  class message_base {
57  public:
59  virtual void operator() (int warn_code, const char* file_name,
60  int line_num, const char *fmt, ...) = 0;
61  };
62 
64  class message_info : public message_base
65  {
66  public:
68  virtual void operator() (int info_code, const char* file_name,
69  int line_num, const char* fmt, ...);
70  };
71 
74  void set_info_stream(FILE* s);
79 
82  {
83  public:
85  virtual void operator() (int warn_code, const char* file_name,
86  int line_num, const char* fmt, ...);
87  };
88 
91  void set_warning_stream(FILE* s);
96 
98  class message_error : public message_base
99  {
100  public:
102  virtual void operator() (int warn_code, const char* file_name,
103  int line_num, const char *fmt, ...);
104  };
105 
108  void set_error_stream(FILE *s);
113 }
114 
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 
125 #define OJPH_INFO(t, ...) \
126  { ojph::get_info()(t, __OJPHFILE__, __LINE__, __VA_ARGS__); }
127 #define OJPH_WARN(t, ...) \
129  { ojph::get_warning()(t, __OJPHFILE__, __LINE__, __VA_ARGS__); }
130 #define OJPH_ERROR(t, ...) \
132  { ojph::get_error()(t, __OJPHFILE__, __LINE__,__VA_ARGS__); }
133 
134 
135 #endif // !OJPH_MESSAGE_H
ojph::message_error::operator()
virtual OJPH_EXPORT void operator()(int warn_code, const char *file_name, int line_num, const char *fmt,...)
Definition: ojph_message.cpp:148
ojph::error_stream
FILE * error_stream
Definition: ojph_message.cpp:123
ojph_message.h
ojph::warn
message_warning warn
Definition: ojph_message.cpp:88
ojph::warning_stream
FILE * warning_stream
Definition: ojph_message.cpp:85
ojph::local_error
message_error & local_error
Definition: ojph_message.cpp:127
ojph::message_info
Definition: ojph_message.h:65
ojph::set_error_stream
OJPH_EXPORT void set_error_stream(FILE *s)
Definition: ojph_message.cpp:142
ojph::OJPH_MSG_LEVEL
OJPH_MSG_LEVEL
Definition: ojph_message.h:48
ojph::set_info_stream
OJPH_EXPORT void set_info_stream(FILE *s)
Definition: ojph_message.cpp:66
ojph::set_warning_stream
OJPH_EXPORT void set_warning_stream(FILE *s)
Definition: ojph_message.cpp:104
ojph::configure_warning
OJPH_EXPORT void configure_warning(message_warning *warn)
Definition: ojph_message.cpp:92
ojph::configure_error
OJPH_EXPORT void configure_error(message_error *error)
Definition: ojph_message.cpp:130
ojph::message_base::operator()
virtual OJPH_EXPORT void operator()(int warn_code, const char *file_name, int line_num, const char *fmt,...)=0
ojph::message_base
Definition: ojph_message.h:56
ojph::get_error
OJPH_EXPORT message_error & get_error()
Definition: ojph_message.cpp:136
ojph::NO_MSG
@ NO_MSG
Definition: ojph_message.h:49
ojph::local_info
message_info & local_info
Definition: ojph_message.cpp:51
ojph::message_warning::operator()
virtual OJPH_EXPORT void operator()(int warn_code, const char *file_name, int line_num, const char *fmt,...)
Definition: ojph_message.cpp:110
ojph::message_error
Definition: ojph_message.h:99
ojph::error
message_error error
Definition: ojph_message.cpp:126
ojph::get_info
OJPH_EXPORT message_info & get_info()
Definition: ojph_message.cpp:60
ojph::message_warning
Definition: ojph_message.h:82
ojph::get_warning
OJPH_EXPORT message_warning & get_warning()
Definition: ojph_message.cpp:98
ojph::info_stream
FILE * info_stream
Definition: ojph_message.cpp:47
ojph::message_info::operator()
virtual OJPH_EXPORT void operator()(int info_code, const char *file_name, int line_num, const char *fmt,...)
Definition: ojph_message.cpp:72
ojph_arch.h
ojph::local_warn
message_warning & local_warn
Definition: ojph_message.cpp:89
ojph::INFO
@ INFO
Definition: ojph_message.h:50
ojph::ERROR
@ ERROR
Definition: ojph_message.h:52
ojph
Definition: ojph_block_decoder.cpp:49
ojph::configure_info
OJPH_EXPORT void configure_info(message_info *info)
Definition: ojph_message.cpp:54
ojph::WARN
@ WARN
Definition: ojph_message.h:51
OJPH_EXPORT
#define OJPH_EXPORT
Definition: ojph_arch.h:205
ojph::info
message_info info
Definition: ojph_message.cpp:50