~siretart/gnucash/ubuntu-fullsource

« back to all changes in this revision

Viewing changes to lib/libqof/qof/qofquerycore.h

  • Committer: Reinhard Tartler
  • Date: 2008-08-03 07:25:46 UTC
  • Revision ID: siretart@tauware.de-20080803072546-y6p8xda8zpfi62ys
import gnucash_2.2.4.orig.tar.gz

The original tarball had the md5sum: 27e660297dc5b8ce574515779d05a5a5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/********************************************************************\
 
2
 * qofquerycore.h -- API for providing core Query data types        *
 
3
 * Copyright (C) 2002 Derek Atkins <warlord@MIT.EDU>                *
 
4
 *                                                                  *
 
5
 * This program is free software; you can redistribute it and/or    *
 
6
 * modify it under the terms of the GNU General Public License as   *
 
7
 * published by the Free Software Foundation; either version 2 of   *
 
8
 * the License, or (at your option) any later version.              *
 
9
 *                                                                  *
 
10
 * This program is distributed in the hope that it will be useful,  *
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
 
13
 * GNU General Public License for more details.                     *
 
14
 *                                                                  *
 
15
 * You should have received a copy of the GNU General Public License*
 
16
 * along with this program; if not, contact:                        *
 
17
 *                                                                  *
 
18
 * Free Software Foundation           Voice:  +1-617-542-5942       *
 
19
 * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
 
20
 * Boston, MA  02110-1301,  USA       gnu@gnu.org                   *
 
21
 *                                                                  *
 
22
\********************************************************************/
 
23
 
 
24
/** @addtogroup Query
 
25
    @{ */
 
26
 
 
27
/** @file qofquerycore.h
 
28
    @brief API for providing core Query data types
 
29
    @author Copyright (C) 2002 Derek Atkins <warlord@MIT.EDU>
 
30
*/
 
31
 
 
32
#ifndef QOF_QUERYCORE_H
 
33
#define QOF_QUERYCORE_H
 
34
 
 
35
#include "gnc-numeric.h"
 
36
#include "gnc-date.h"
 
37
#include "kvp_frame.h"
 
38
#include "qofclass.h"
 
39
 
 
40
/**
 
41
 * PREDICATE DATA TYPES: All the predicate data types are rolled up into
 
42
 * the union type PredicateData.  The "type" field specifies which type
 
43
 * the union is.
 
44
 */
 
45
typedef struct _QofQueryPredData QofQueryPredData;
 
46
 
 
47
/** Standard Query comparitors, for how to compare objects in a predicate.
 
48
 *  Note that not all core types implement all comparitors
 
49
 */
 
50
typedef enum {
 
51
  QOF_COMPARE_LT = 1,
 
52
  QOF_COMPARE_LTE,
 
53
  QOF_COMPARE_EQUAL,
 
54
  QOF_COMPARE_GT,
 
55
  QOF_COMPARE_GTE,
 
56
  QOF_COMPARE_NEQ
 
57
} QofQueryCompare;
 
58
 
 
59
/** List of known core query data-types...
 
60
 *  Each core query type defines it's set of optional "comparitor qualifiers".
 
61
 */
 
62
/* Comparisons for QOF_TYPE_STRING */
 
63
typedef enum {
 
64
  QOF_STRING_MATCH_NORMAL = 1,
 
65
  QOF_STRING_MATCH_CASEINSENSITIVE
 
66
} QofStringMatch;
 
67
 
 
68
/** Comparisons for QOF_TYPE_DATE
 
69
 * The QOF_DATE_MATCH_DAY comparison rounds the two time
 
70
 *     values to mid-day and then compares these rounded values.
 
71
 * The QOF_DATE_MATCH_NORMAL comparison matches the time values,
 
72
 *     down to the second.
 
73
 */
 
74
 
 
75
typedef enum {
 
76
  QOF_DATE_MATCH_NORMAL = 1,
 
77
  QOF_DATE_MATCH_DAY
 
78
} QofDateMatch;
 
79
 
 
80
/** Comparisons for QOF_TYPE_NUMERIC, QOF_TYPE_DEBCRED
 
81
 *
 
82
 * XXX Should be deprecated, or at least wrapped up as a convenience
 
83
 * function,  this is based on the old bill gribble code, which assumed
 
84
 * the amount was always positive, and then specified a funds-flow
 
85
 * direction (credit, debit, or either).
 
86
 *
 
87
 * The point being that 'match credit' is equivalent to the compound
 
88
 * predicate (amount >= 0) && (amount 'op' value) while the  'match
 
89
 * debit' predicate is equivalent to (amount <= 0) && (abs(amount) 'op' value)
 
90
*/
 
91
 
 
92
typedef enum {
 
93
  QOF_NUMERIC_MATCH_DEBIT = 1,
 
94
  QOF_NUMERIC_MATCH_CREDIT,
 
95
  QOF_NUMERIC_MATCH_ANY
 
96
} QofNumericMatch;
 
97
 
 
98
/* Comparisons for QOF_TYPE_GUID */
 
99
typedef enum {
 
100
  /** These expect a single object and expect the
 
101
   * QofAccessFunc returns GUID* */
 
102
  QOF_GUID_MATCH_ANY = 1,
 
103
  QOF_GUID_MATCH_NONE,
 
104
  QOF_GUID_MATCH_NULL,
 
105
  /** These expect a GList* of objects and calls the QofAccessFunc routine
 
106
   * on each item in the list to obtain a GUID* for each object */
 
107
  QOF_GUID_MATCH_ALL,
 
108
  /** These expect a single object and expect the QofAccessFunc function
 
109
   * to return a GList* of GUID* (the list is the property of the caller) */
 
110
  QOF_GUID_MATCH_LIST_ANY,
 
111
} QofGuidMatch;
 
112
 
 
113
/** A CHAR type is for a RECNCell, Comparisons for QOF_TYPE_CHAR
 
114
 *  'ANY' will match any charagter in the string.
 
115
 *
 
116
 * Match 'ANY' is a convenience/performance-enhanced predicate
 
117
 * for the compound statement (value==char1) || (value==char2) || etc.
 
118
 * Match 'NONE' is equivalent to
 
119
 * (value != char1) && (value != char2) && etc.
 
120
 */
 
121
typedef enum {
 
122
  QOF_CHAR_MATCH_ANY = 1,
 
123
  QOF_CHAR_MATCH_NONE
 
124
} QofCharMatch;
 
125
 
 
126
/** No extended comparisons for QOF_TYPE_INT32, QOF_TYPE_INT64,
 
127
 *  QOF_TYPE_DOUBLE, QOF_TYPE_BOOLEAN, QOF_TYPE_KVP
 
128
 */
 
129
 
 
130
/** Head of Predicate Data structures.  All PData must start like this. */
 
131
struct _QofQueryPredData {
 
132
  QofType               type_name;  /* QOF_TYPE_* */
 
133
  QofQueryCompare       how;
 
134
};
 
135
 
 
136
 
 
137
/** @name Core Data Type Predicates
 
138
    @{ */
 
139
QofQueryPredData *qof_query_string_predicate (QofQueryCompare how,
 
140
                                              const gchar *str,
 
141
                                              QofStringMatch options,
 
142
                                              gboolean is_regex);
 
143
 
 
144
QofQueryPredData *qof_query_date_predicate (QofQueryCompare how,
 
145
                                            QofDateMatch options,
 
146
                                            Timespec date);
 
147
 
 
148
QofQueryPredData *qof_query_numeric_predicate (QofQueryCompare how,
 
149
                                               QofNumericMatch options,
 
150
                                               gnc_numeric value);
 
151
 
 
152
QofQueryPredData *qof_query_guid_predicate (QofGuidMatch options, GList *guids);
 
153
QofQueryPredData *qof_query_int32_predicate (QofQueryCompare how, gint32 val);
 
154
QofQueryPredData *qof_query_int64_predicate (QofQueryCompare how, gint64 val);
 
155
QofQueryPredData *qof_query_double_predicate (QofQueryCompare how, double val);
 
156
QofQueryPredData *qof_query_boolean_predicate (QofQueryCompare how, gboolean val);
 
157
QofQueryPredData *qof_query_char_predicate (QofCharMatch options,
 
158
                                            const gchar *chars);
 
159
QofQueryPredData *qof_query_collect_predicate (QofGuidMatch options,
 
160
                                            QofCollection *coll);
 
161
QofQueryPredData *qof_query_choice_predicate  (QofGuidMatch options, GList *guids);
 
162
 
 
163
/** The qof_query_kvp_predicate() matches the object that has
 
164
 *  the value 'value' located at the path 'path'.  In a certain
 
165
 *  sense, the 'path' is handled as if it were a paramter.
 
166
 */
 
167
QofQueryPredData *qof_query_kvp_predicate (QofQueryCompare how,
 
168
                                           GSList *path,
 
169
                                           const KvpValue *value);
 
170
 
 
171
/** Same predicate as above, except that 'path' is assumed to be
 
172
 * a string containing slash-separated pathname. */
 
173
QofQueryPredData *qof_query_kvp_predicate_path (QofQueryCompare how,
 
174
                                                const gchar *path,
 
175
                                                const KvpValue *value);
 
176
 
 
177
/** Copy a predicate. */
 
178
QofQueryPredData *qof_query_core_predicate_copy (QofQueryPredData *pdata);
 
179
 
 
180
/** Destroy a predicate. */
 
181
void qof_query_core_predicate_free (QofQueryPredData *pdata);
 
182
 
 
183
/** Retrieve a predicate. */
 
184
gboolean qof_query_date_predicate_get_date (QofQueryPredData *pd, Timespec *date);
 
185
/** Return a printable string for a core data object.  Caller needs
 
186
 *  to g_free() the returned string.
 
187
 */
 
188
char * qof_query_core_to_string (QofType, gpointer object, QofParam *getter);
 
189
 
 
190
/** Compare two parameter(strings) as if they are numbers!
 
191
 *  the two objects, a and b, are the objects being compared
 
192
 *  this_param is the QofParam for this parameter in the objects
 
193
 */
 
194
int qof_string_number_compare_func (gpointer a, gpointer b, gint options,
 
195
                                    QofParam *this_param);
 
196
 
 
197
 
 
198
#endif /* QOF_QUERYCORE_H */
 
199
/* @} */
 
200
/* @} */