1 /***************************************************************************
2     begin       : Mon Apr 05 2004
3     copyright   : (C) 2004 by Martin Preuss
4     email       : martin@libchipcard.de
5 
6  ***************************************************************************
7  * This file is part of the project "AqBanking".                           *
8  * Please see toplevel file COPYING of that project for license details.   *
9  ***************************************************************************/
10 
11 
12 #ifndef AB_VALUE_H
13 #define AB_VALUE_H
14 
15 #include <aqbanking/error.h>
16 
17 #include <gwenhywfar/buffer.h>
18 #include <gwenhywfar/db.h>
19 #include <gwenhywfar/list.h>
20 #include <gwenhywfar/types.h>
21 
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 typedef struct AB_VALUE AB_VALUE;
28 GWEN_LIST_FUNCTION_LIB_DEFS(AB_VALUE, AB_Value, AQBANKING_API)
29 
30 /** Creates a deep copy of an AB_VALUE_LIST object
31  *
32  */
33 AQBANKING_API AB_VALUE_LIST *AB_Value_List_dup(const AB_VALUE_LIST *vl);
34 
35 
36 AQBANKING_API AB_VALUE *AB_Value_new(void);
37 AQBANKING_API AB_VALUE *AB_Value_dup(const AB_VALUE *ov);
38 AQBANKING_API void AB_Value_free(AB_VALUE *v);
39 
40 /**
41  * This function reads a AB_VALUE from a string. Strings suitable as
42  * arguments are those created by @ref AB_Value_toString or simple
43  * floating point string (as in "123.45" or "-123.45").
44  */
45 AQBANKING_API AB_VALUE *AB_Value_fromString(const char *s);
46 
47 /**
48  * This function exports the value in a format which can be recognized
49  * by the function @ref AB_Value_fromString. You should not make any
50  * assumption about the format of the string created here.
51  */
52 AQBANKING_API void AB_Value_toString(const AB_VALUE *v, GWEN_BUFFER *buf);
53 
54 AQBANKING_API void AB_Value_toHumanReadableString(const AB_VALUE *v,
55                                                   GWEN_BUFFER *buf,
56                                                   int prec,
57                                                   int withCurrency);
58 
59 AQBANKING_API AB_VALUE *AB_Value_fromDouble(double i);
60 
61 /** Returns a newly allocated rational number, initialized to
62  * num/denom. */
63 AQBANKING_API AB_VALUE *AB_Value_fromInt(long int num, long int denom);
64 
65 
66 /** Create a value from the given GWEN_DB. */
67 AQBANKING_API AB_VALUE *AB_Value_fromDb(GWEN_DB_NODE *db);
68 
69 /** Write the given value into the given GWEN_DB. */
70 AQBANKING_API int AB_Value_toDb(const AB_VALUE *v, GWEN_DB_NODE *db);
71 
72 /** Write the given value into the given GWEN_DB (uses float instead of rational). */
73 AQBANKING_API int AB_Value_toDbFloat(const AB_VALUE *v, GWEN_DB_NODE *db);
74 
75 /**
76  * This function returns the value as a double.
77  * You should not feed another AB_VALUE from this double, because the
78  * conversion from an AB_VALUE to a double might be lossy!
79  */
80 AQBANKING_API double AB_Value_GetValueAsDouble(const AB_VALUE *v);
81 
82 
83 /**
84  * You should not use a double retrieved via
85  * @ref AB_Value_GetValueAsDouble as an argument to this function, because
86  * the conversion from AB_VALUE to double to AB_VALUE might change the
87  * real value.
88  */
89 AQBANKING_API void AB_Value_SetValueFromDouble(AB_VALUE *v, double i);
90 
91 /**
92  * Write the value (without the currency) in nominator/denominator
93  * form into the given buffer if possibly.
94  * This form looks like "12345/6789" (nominator/denominator).
95  */
96 AQBANKING_API int AB_Value_GetNumDenomString(const AB_VALUE *v,
97                                              char *buffer,
98                                              uint32_t buflen);
99 
100 AQBANKING_API void AB_Value_SetZero(AB_VALUE *v);
101 
102 AQBANKING_API int AB_Value_IsZero(const AB_VALUE *v);
103 AQBANKING_API int AB_Value_IsNegative(const AB_VALUE *v);
104 AQBANKING_API int AB_Value_IsPositive(const AB_VALUE *v);
105 AQBANKING_API int AB_Value_Compare(const AB_VALUE *v1, const AB_VALUE *v2);
106 
107 /** Returns non-zero if v1 and v2 are equal, zero if they are
108  * non-equal. Although AB_Value_Compare() can be used for the same
109  * purpose, this function is much faster.
110  */
111 AQBANKING_API int AB_Value_Equal(const AB_VALUE *v1, const AB_VALUE *v2);
112 
113 AQBANKING_API int AB_Value_AddValue(AB_VALUE *v1, const AB_VALUE *v2);
114 AQBANKING_API int AB_Value_SubValue(AB_VALUE *v1, const AB_VALUE *v2);
115 AQBANKING_API int AB_Value_MultValue(AB_VALUE *v1, const AB_VALUE *v2);
116 AQBANKING_API int AB_Value_DivValue(AB_VALUE *v1, const AB_VALUE *v2);
117 
118 AQBANKING_API int AB_Value_Negate(AB_VALUE *v);
119 
120 
121 AQBANKING_API const char *AB_Value_GetCurrency(const AB_VALUE *v);
122 AQBANKING_API void AB_Value_SetCurrency(AB_VALUE *v, const char *s);
123 
124 
125 AQBANKING_API void AB_Value_Dump(const AB_VALUE *v, FILE *f, unsigned int indent);
126 
127 /** Returns the numerator of the given rational number. */
128 AQBANKING_API long int AB_Value_Num(const AB_VALUE *v);
129 /** Returns the denominator of the given rational number. */
130 AQBANKING_API long int AB_Value_Denom(const AB_VALUE *v);
131 
132 
133 /** Write value to HBCI string (e.g. "11,90" is written as "11,9") */
134 AQBANKING_API void AB_Value_toHbciString(const AB_VALUE *v, GWEN_BUFFER *buf);
135 
136 
137 #ifdef __cplusplus
138 }
139 #endif
140 
141 
142 #endif /* AB_VALUE_H */
143 
144 
145 
146 
147 
148 
149 
150 
151