source: trunk/libdjvu/DjVuGlobal.h @ 76

Last change on this file since 76 was 17, checked in by Eugene Romanenko, 16 years ago

update makefiles, remove absolute paths, update djvulibre to version 3.5.17

File size: 14.3 KB
Line 
1//C-  -*- C++ -*-
2//C- -------------------------------------------------------------------
3//C- DjVuLibre-3.5
4//C- Copyright (c) 2002  Leon Bottou and Yann Le Cun.
5//C- Copyright (c) 2001  AT&T
6//C-
7//C- This software is subject to, and may be distributed under, the
8//C- GNU General Public License, Version 2. The license should have
9//C- accompanied the software or you may obtain a copy of the license
10//C- from the Free Software Foundation at http://www.fsf.org .
11//C-
12//C- This program is distributed in the hope that it will be useful,
13//C- but WITHOUT ANY WARRANTY; without even the implied warranty of
14//C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15//C- GNU General Public License for more details.
16//C-
17//C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library
18//C- distributed by Lizardtech Software.  On July 19th 2002, Lizardtech
19//C- Software authorized us to replace the original DjVu(r) Reference
20//C- Library notice by the following text (see doc/lizard2002.djvu):
21//C-
22//C-  ------------------------------------------------------------------
23//C- | DjVu (r) Reference Library (v. 3.5)
24//C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved.
25//C- | The DjVu Reference Library is protected by U.S. Pat. No.
26//C- | 6,058,214 and patents pending.
27//C- |
28//C- | This software is subject to, and may be distributed under, the
29//C- | GNU General Public License, Version 2. The license should have
30//C- | accompanied the software or you may obtain a copy of the license
31//C- | from the Free Software Foundation at http://www.fsf.org .
32//C- |
33//C- | The computer code originally released by LizardTech under this
34//C- | license and unmodified by other parties is deemed "the LIZARDTECH
35//C- | ORIGINAL CODE."  Subject to any third party intellectual property
36//C- | claims, LizardTech grants recipient a worldwide, royalty-free,
37//C- | non-exclusive license to make, use, sell, or otherwise dispose of
38//C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the
39//C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU
40//C- | General Public License.   This grant only confers the right to
41//C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to
42//C- | the extent such infringement is reasonably necessary to enable
43//C- | recipient to make, have made, practice, sell, or otherwise dispose
44//C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to
45//C- | any greater extent that may be necessary to utilize further
46//C- | modifications or combinations.
47//C- |
48//C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY
49//C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
50//C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF
51//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
52//C- +------------------------------------------------------------------
53//
54// $Id: DjVuGlobal.h,v 1.10 2004/08/04 02:36:59 leonb Exp $
55// $Name:  $
56
57#ifndef _DJVUGLOBAL_H
58#define _DJVUGLOBAL_H
59#ifdef HAVE_CONFIG_H
60# include "config.h"
61#endif
62#if NEED_GNUG_PRAGMAS
63# pragma interface
64#endif
65
66#if defined(UNDER_CE)
67# ifndef __WCEALT_H__
68inline void * operator new(size_t, void * ptr) { return ptr; }
69# endif
70#elif defined(AUTOCONF) && defined(HAVE_STDINCLUDES)
71# include <new>
72#else
73# include <new.h>
74#endif
75
76#ifdef WIN32
77# ifdef DLL_EXPORT
78#  define DJVUAPI __declspec(dllexport)
79# else
80#  ifdef LIBDJVU_DLL_IMPORT
81#   define DJVUAPI __declspec(dllimport)
82#  endif
83# endif
84#endif
85#ifndef DJVUAPI
86# define DJVUAPI
87#endif
88
89
90/** @name DjVuGlobal.h
91
92    This file is included by all include files in the DjVu reference library.
93   
94        If compilation symbols #NEED_DJVU_MEMORY#, #NEED_DJVU_PROGRESS#
95        or #NEED_DJVU_NAMES# are defined, this file enables
96        features which are useful for certain applications of the
97    DjVu Reference Library.  These features are still experimental and
98    therefore poorly documented.
99   
100    @memo
101    Global definitions.
102    @version
103    #$Id: DjVuGlobal.h,v 1.10 2004/08/04 02:36:59 leonb Exp $#
104    @author
105    L\'eon Bottou <leonb@research.att.com> -- empty file.\\
106    Bill Riemers <docbill@sourceforge.net> -- real work.  */
107//@{
108
109
110/** @name DjVu Memory
111
112    This section is enabled when compilation symbol #NEED_DJVU_MEMORY# is
113    defined.  Function #_djvu_memory_callback# can be used to redefine the C++
114    memory allocation operators.  Some operating systems (e.g. Macintoshes)
115    require very peculiar memory allocation in shared objects.  We redefine
116    the operators #new# and #delete# as #STATIC_INLINE# because we do not
117    want to export these redefined versions to other libraries.  */
118//@{
119//@}
120
121#ifdef NEED_DJVU_MEMORY
122
123# include "DjVu.h"
124
125// These define the two callbacks needed for C++
126typedef void djvu_delete_callback(void *);
127typedef void *djvu_new_callback(size_t);
128
129// These functions allow users to set the callbacks.
130int djvu_memoryObject_callback ( djvu_delete_callback*, djvu_new_callback*);
131int djvu_memoryArray_callback ( djvu_delete_callback*, djvu_new_callback*);
132
133// We need to use this inline function in all modules, but we never want it to
134// appear in the symbol table.  It seems different compilers need different
135// directives to do this...
136# ifndef STATIC_INLINE
137#  ifdef __GNUC__
138#   define STATIC_INLINE extern inline
139#  else /* !__GNUC__ */
140#   define STATIC_INLINE static inline
141#  endif /* __GNUC__ */
142# endif /* STATIC_INLINE */
143
144// This clause is used when overriding operator new
145// because the standard has slightly changed.
146# if defined( __GNUC__ ) && ( __GNUC__*1000 + __GNUC_MINOR__ >= 2091 )
147#  ifndef new_throw_spec
148#   define new_throw_spec throw(std::bad_alloc)
149#  endif /* new_throw_spec */
150#  ifndef delete_throw_spec
151#   define delete_throw_spec throw()
152#  endif /* delete_throw_spec */
153# endif /* __GNUC__ ... */
154// Old style
155# ifndef new_throw_spec
156#  define new_throw_spec
157# endif /* new_throw_spec */
158# ifndef delete_throw_spec
159#  define delete_throw_spec
160# endif  /* delete_throw_spec */
161
162# ifdef UNIX
163extern djvu_new_callback *_djvu_new_ptr;
164extern djvu_new_callback *_djvu_newArray_ptr;
165extern djvu_delete_callback *_djvu_delete_ptr;
166extern djvu_delete_callback *_djvu_deleteArray_ptr;
167
168#  ifndef NEED_DJVU_MEMORY_IMPLEMENTATION
169void *operator new (size_t) new_throw_spec;
170void *operator new[] (size_t) new_throw_spec;
171void operator delete (void *) delete_throw_spec;
172void operator delete[] (void *) delete_throw_spec;
173
174STATIC_INLINE void *
175operator new(size_t sz) new_throw_spec
176{ return (*_djvu_new_ptr)(sz); }
177STATIC_INLINE void
178operator delete(void *addr) delete_throw_spec
179{ return (*_djvu_delete_ptr)(addr); }
180STATIC_INLINE void *
181operator new [] (size_t sz) new_throw_spec
182{ return (*_djvu_newArray_ptr)(sz); }
183STATIC_INLINE void
184operator delete [] (void *addr) delete_throw_spec
185{ return (*_djvu_deleteArray_ptr)(addr); }
186#  endif /* NEED_DJVU_MEMORY_IMPLEMENTATION */
187
188# else /* UNIX */
189
190#  ifndef NEED_DJVU_MEMORY_IMPLEMENTATION
191STATIC_INLINE void *
192operator new(size_t sz) new_throw_spec
193{ return _djvu_new(sz); }
194inline_as_macro void
195operator delete(void *addr) delete_throw_spec
196{ return _djvu_delete(addr); }
197inline_as_macro void *
198operator new [] (size_t sz) new_throw_spec
199{ return _djvu_new(sz); }
200inline_as_macro void
201operator delete [] (void *addr) delete_throw_spec
202{ _djvu_deleteArray(addr); }
203#  endif /* !NEED_DJVU_MEMORY_IMPLEMENTATION */
204
205# endif /* UNIX */
206
207#else
208
209# define _djvu_free(ptr) free((ptr))
210# define _djvu_malloc(siz) malloc((siz))
211# define _djvu_realloc(ptr,siz) realloc((ptr),(siz))
212# define _djvu_calloc(siz,items) calloc((siz),(items))
213
214#endif /* NEED_DJVU_MEMORY */
215
216/** @name DjVu Progress 
217
218    This section is enabled when compilation symbol #NEED_DJVU_PROGRESS# is
219    defined.  This macro setups callback function that may be used to
220    implement a progress indicator for the encoding routines.  The decoding
221    routines do not need such a facility because it is sufficient to monitor
222    the calls to function \Ref{ByteStream::read} in class \Ref{ByteStream}.
223   
224    {\bf Code tracing macros} ---
225    Monitoring the progress of such complex algorithms requires significant
226    code support.  This is achieved by inserting {\em code tracing macros}
227    in strategic regions of the code. 
228    \begin{description}
229    \item[DJVU_PROGRESS_TASK(name,task,nsteps)]  indicates that the current
230         scope performs a task roughly divided in #nsteps# equal steps, with
231               the specified #task# string used in the callback.
232    \item[DJVU_PROGRESS_RUN(name,tostep)] indicates that we are starting
233         an operation which will take us to step #tostep#.  The operation
234         will be considered finished when #DJVU_PROGRESS_RUN# will be called
235         again with an argument greater than #tostep#.  The execution of
236         this operation of course can be described by one subtask and so on.
237    \end{description}
238 
239    {\bf Progress callback} --- Before defining the outermost task, you can
240    store a callback function pointer into the static member variable
241    #DjVuProgressTask::callback#.  This callback function is called
242    periodically with two unsigned long arguments.  The first argument is the
243    elapsed time. The second argument is the estimated total execution time.
244    Both times are given in milliseconds.
245
246    {\bf Important Note} --- This monitoring mechanism should not be used by
247    multithreaded programs.  */
248//@{
249
250#ifndef HAS_DJVU_PROGRESS_CALLBACKS
251# define HAS_DJVU_PROGRESS_CALLBACKS
252
253# ifdef NEED_DJVU_PROGRESS
254#  include "DjVu.h"
255
256extern djvu_progress_callback *_djvu_progress_ptr;
257
258#  define DJVU_PROGRESS_TASK(name,task,nsteps)  DjVuProgressTask task_##name(task,nsteps)
259#  define DJVU_PROGRESS_RUN(name,tostep)   { task_##name.run(tostep); }
260
261class DjVuProgressTask
262{
263public:
264  class Data;
265  ~DjVuProgressTask();
266  DjVuProgressTask(const char *task,int nsteps);
267  void run(int tostep);
268  const char *task;
269  static djvu_progress_callback *set_callback(djvu_progress_callback *ptr=0);
270private:
271  DjVuProgressTask *parent;
272  int nsteps;
273  int runtostep;
274  unsigned long startdate;
275  // Statics
276  void *gdata;
277  Data *data;
278  // Helpers
279  void signal(unsigned long curdate, unsigned long estdate);
280};
281
282# else  // ! NEED_DJVU_PROGRESS
283
284#  define DJVU_PROGRESS_TASK(name,task,nsteps)
285#  define DJVU_PROGRESS_RUN(name,step)
286
287# endif // ! NEED_DJVU_PROGRESS
288#endif // HAS_DJVU_PROGRESS_CALLBACKS
289//@}
290
291
292/** @name General functions.
293
294    This section contains functions that replace some of the standard
295    system calls without any other header file dependancies.
296 */
297
298#ifdef __cplusplus
299# define DJVUEXTERNCAPI(x) extern "C" DJVUAPI x;
300#else
301# define DJVUEXTERNCAPI(x) extern DJVUAPI x
302#endif
303
304/** This replaces fprintf(stderr,...), but with UTF8 encoded strings. */
305DJVUEXTERNCAPI(void DjVuPrintErrorUTF8(const char *fmt, ...));
306
307/** This replaces fprintf(stderr,...), but with UTF8 encoded strings. */
308DJVUEXTERNCAPI(void DjVuPrintErrorNative(const char *fmt, ...));
309
310/** This replaces printf(...), but requires UTF8 encoded strings. */
311DJVUEXTERNCAPI(void DjVuPrintMessageUTF8(const char *fmt, ...));
312
313/** This replaces printf(...), but requires UTF8 encoded strings. */
314DJVUEXTERNCAPI(void DjVuPrintMessageNative(const char *fmt, ...));
315
316/** The format (fmt) and arguments define a MessageList to be looked
317    up in the external messages and printed to stderr. */
318DJVUEXTERNCAPI(void DjVuFormatErrorUTF8(const char *fmt, ...));
319
320/** The format (fmt) and arguments define a MessageList to be looked
321    up in the external messages and printed to stderr. */
322DJVUEXTERNCAPI(void DjVuFormatErrorNative(const char *fmt, ...));
323
324/** Prints the translation of message to stderr. */
325DJVUEXTERNCAPI(void DjVuWriteError( const char *message ));
326
327/** Prints the translation of message to stdout. */
328DJVUEXTERNCAPI(void DjVuWriteMessage( const char *message ));
329
330/** A C function to perform a message lookup. Arguments are a buffer to
331  received the translated message, a buffer size (bytes), and a
332  message_list. The translated result is returned in msg_buffer encoded
333  in UTF-8. In case of error, msg_buffer is empty
334  (i.e., msg_buffer[0] == '\0').
335*/
336DJVUEXTERNCAPI(void DjVuMessageLookUpUTF8(
337  char *msg_buffer, const unsigned int buffer_size, 
338  const char *message ));
339DJVUEXTERNCAPI(void DjVuMessageLookUpNative(
340  char *msg_buffer, const unsigned int buffer_size, 
341  const char *message ));
342
343/** This function sets the program name used when
344    searching for language files.
345*/
346DJVUEXTERNCAPI(const char *djvu_programname(const char *programname));
347
348
349/** @name DjVu Names 
350
351    This section is enabled when compilation symbol #NEED_DJVU_NAMES# is
352    defined.  This section redefines class names in order to unclutter the
353    name space of shared objects.  This is useful on systems which
354    automatically export all global symbols when building a shared object.
355    @args */
356//@{
357//@}
358
359#ifdef NEED_DJVU_NAMES
360/* The contents of this section may be generated by this shell command :
361 * % egrep -h '^(class|struct) +[A-Z_][A-Za-z0-9_]*' *.h *.cpp |\
362 *   sed -e 's:[a-z]*  *\([A-Za-z_][A-Za-z0-9_]*\).*:#define \1 DJVU_\1:g' |\
363 *   sort
364 */
365#endif // NEED_DJVU_NAMES
366
367//@}
368
369#if defined(macintosh)
370# define EMPTY_LOOP continue
371#else
372# define EMPTY_LOOP /* nop */
373#endif
374
375//  The ERR_MSG(x) macro is intended to permit automated checking of the
376//  externalized error message names against the source code. It has no
377//  effect on the executed program. It should be used to surround each
378//  message name that will need to be looked up in the external message
379//  files. In particular, it should use on all strings passed to G_THROW.
380#ifndef HAS_CTRL_C_IN_ERR_MSG
381# define HAS_CTRL_C_IN_ERR_MSG 1
382#endif
383#ifndef ERR_MSG
384# if HAS_CTRL_C_IN_ERR_MSG
385// This hack allows for the coexistence of internationalized
386// and non-internationalized code.  All internationalized error
387// message names are prefixed with a ctrl-c.  Only these will
388// be looked for in the message files.  Messages that do no
389// start with a ctrl-c will remain untranslated.
390#  define ERR_MSG(x) "\003" x
391# else
392#  define ERR_MSG(x) x
393# endif
394#endif
395
396#endif /* _DJVUGLOBAL_H_ */
397
398
Note: See TracBrowser for help on using the repository browser.