OpenJPH
Open-source implementation of JPEG2000 Part-15
ojph_message.cpp
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.cpp
34 // Author: Aous Naman
35 // Date: 29 August 2019
36 //***************************************************************************/
37 
38 #include <cstdio>
39 #include <cstdarg>
40 #include <stdexcept>
41 
42 #include "ojph_message.h"
43 
44 namespace ojph {
45 
47  FILE* info_stream = stdout;
48 
52 
55  {
56  local_info = *info;
57  }
58 
61  {
62  return local_info;
63  }
64 
66  void set_info_stream(FILE* s)
67  {
68  info_stream = s;
69  }
70 
72  void message_info::operator()(int info_code, const char* file_name,
73  int line_num, const char* fmt, ...)
74  {
75  fprintf(info_stream, "ojph info 0x%08X at %s:%d: ",
76  info_code, file_name, line_num);
77  va_list args;
78  va_start(args, fmt);
79  vfprintf(info_stream, fmt, args);
80  fprintf(info_stream, "\n");
81  va_end(args);
82  }
83 
85  FILE *warning_stream = stdout;
86 
90 
93  {
94  local_warn = *warn;
95  }
96 
99  {
100  return local_warn;
101  }
102 
104  void set_warning_stream(FILE *s)
105  {
106  warning_stream = s;
107  }
108 
110  void message_warning::operator()(int warn_code, const char* file_name,
111  int line_num, const char *fmt, ...)
112  {
113  fprintf(warning_stream, "ojph warning 0x%08X at %s:%d: ",
114  warn_code, file_name, line_num);
115  va_list args;
116  va_start(args, fmt);
117  vfprintf(warning_stream, fmt, args);
118  fprintf(warning_stream, "\n");
119  va_end(args);
120  }
121 
123  FILE *error_stream = stderr;
124 
128 
131  {
132  local_error = *error;
133  }
134 
137  {
138  return local_error;
139  }
140 
142  void set_error_stream(FILE *s)
143  {
144  error_stream = s;
145  }
146 
148  void message_error::operator()(int error_code, const char* file_name,
149  int line_num, const char *fmt, ...)
150  {
151  fprintf(error_stream, "ojph error 0x%08X at %s:%d: ",
152  error_code, file_name, line_num);
153  va_list args;
154  va_start(args, fmt);
155  vfprintf(error_stream, fmt, args);
156  fprintf(error_stream, "\n");
157  va_end(args);
158 
159  throw std::runtime_error("ojph error");
160  }
161 
162 }
virtual OJPH_EXPORT void operator()(int warn_code, const char *file_name, int line_num, const char *fmt,...)
virtual OJPH_EXPORT void operator()(int info_code, const char *file_name, int line_num, const char *fmt,...)
virtual OJPH_EXPORT void operator()(int warn_code, const char *file_name, int line_num, const char *fmt,...)
message_warning warn
OJPH_EXPORT message_error & get_error()
message_warning & local_warn
OJPH_EXPORT void set_error_stream(FILE *s)
message_info info
OJPH_EXPORT void configure_error(message_error *error)
FILE * info_stream
OJPH_EXPORT message_warning & get_warning()
OJPH_EXPORT void set_warning_stream(FILE *s)
FILE * warning_stream
OJPH_EXPORT void set_info_stream(FILE *s)
message_error & local_error
OJPH_EXPORT void configure_warning(message_warning *warn)
OJPH_EXPORT message_info & get_info()
OJPH_EXPORT void configure_info(message_info *info)
message_error error
FILE * error_stream
message_info & local_info