1 /** \file
2  * \brief Processing Counter
3  *
4  * See Copyright Notice in im_lib.h
5  */
6 module im.im_counter;
7 
8 version(IM) :
9 
10 version(DigitalMars) version(Windows) { pragma(lib, "im.lib"); } // required anyway
11 
12 extern(C) :
13 
14 
15 /** \defgroup counter Counter 
16  * \par
17  * Used to notify the application that a step in the loading, saving or processing operation has been performed.
18  * \par
19  * See \ref im_counter.h
20  * \ingroup util */
21 
22 /** Counter callback, informs the progress of the operation to the client. \n
23  * Text contains a constant string that is NULL during normal counting, a title in the begining of a sequence 
24  * and a message in the begining of a count.
25  * Counter id identifies diferrent counters. \n
26  * Progress in a count reports a value from 0 to 1000. 
27  * If -1 indicates the start of a sequence of operations, 1001 ends the sequence. \n
28  * If returns 0 the client should abort the operation. \n
29  * If the counter is aborted, the callback will be called one last time at 1001.
30  * \ingroup counter */
31 alias imCounterCallback = int function(int counter, void* user_data, const(char)* text, int progress) nothrow;
32 
33 @nogc nothrow :
34 
35 /** Changes the counter callback. Returns old callback. \n
36  * User data is changed only if not NULL.
37  * \ingroup counter */
38 imCounterCallback imCounterSetCallback(void* user_data, imCounterCallback counter_func);
39 
40 /** Returns true if the counter callback is set.
41  * When the callback is NULL the counter is inactive and all functions do nothing.
42  * \ingroup counter */
43 int imCounterHasCallback();
44 
45 /** Begins a new count, or a partial-count in a sequence. \n
46  * Calls the callback with "-1" and text=title, if it is at the top level. \n     
47  * This is to be used by the operations. Returns a counter Id.
48  * \ingroup counter */
49 int imCounterBegin(const(char)* title);
50 
51 /** Ends a count, or a partial-count in a sequence. \n
52  * Calls the callback with "1001", text=null, and releases the counter if it is at top level count. \n
53  * \ingroup counter */
54 void imCounterEnd(int counter);
55 
56 /** Increments a count. Must set the total first. \n
57  * Calls the callback, text=message if it is the first increment for the count. \n
58  * Returns 0 if the callback aborted, 1 if returns normally.
59  * \ingroup counter */
60 int imCounterInc(int counter);
61 
62 /** Set a specific count. Must set the total first. \n
63  * Calls the callback, text=message if it is the first increment for the count. \n
64  * Returns 0 if the callback aborted, 1 if returns normally.
65  * \ingroup counter */
66 int imCounterIncTo(int counter, int count);
67 
68 /** Sets the total increments of a count.
69  * \ingroup counter */
70 void imCounterTotal(int counter, int total, const(char)* message);
71 
72 /** Sets an additional user data in the counter.
73  * Used to save the lock in multi-threaded configurations.
74  * \ingroup counter */
75 void* imCounterGetUserData(int counter);
76 
77 /** Returns the additional user data in the counter.
78  * \ingroup counter */
79 void imCounterSetUserData(int counter, void* userdata);