5405a8096a0684d7a8a08213a0963447a6680414
[reactos.git] / reactos / lib / oleaut32 / variant.h
1 /*
2 * Variant Inlines
3 *
4 * Copyright 2003 Jon Griffiths
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20 #define NONAMELESSUNION
21 #define NONAMELESSSTRUCT
22 #include "windef.h"
23 #include "winerror.h"
24 #include "objbase.h"
25 #include "oleauto.h"
26 #include <math.h>
27
28 /* Get just the type from a variant pointer */
29 #define V_TYPE(v) (V_VT((v)) & VT_TYPEMASK)
30
31 /* Flags set in V_VT, other than the actual type value */
32 #define VT_EXTRA_TYPE (VT_VECTOR|VT_ARRAY|VT_BYREF|VT_RESERVED)
33
34 /* Get the extra flags from a variant pointer */
35 #define V_EXTRA_TYPE(v) (V_VT((v)) & VT_EXTRA_TYPE)
36
37 extern const char* wine_vtypes[];
38 #define debugstr_vt(v) (((v)&VT_TYPEMASK) <= VT_CLSID ? wine_vtypes[((v)&VT_TYPEMASK)] : \
39 ((v)&VT_TYPEMASK) == VT_BSTR_BLOB ? "VT_BSTR_BLOB": "Invalid")
40 #define debugstr_VT(v) (!(v) ? "(null)" : debugstr_vt(V_TYPE((v))))
41
42 extern const char* wine_vflags[];
43 #define debugstr_vf(v) (wine_vflags[((v)&VT_EXTRA_TYPE)>>12])
44 #define debugstr_VF(v) (!(v) ? "(null)" : debugstr_vf(V_EXTRA_TYPE(v)))
45
46 /* Size constraints */
47 #define I1_MAX 0x7f
48 #define I1_MIN ((-I1_MAX)-1)
49 #define UI1_MAX 0xff
50 #define UI1_MIN 0
51 #define I2_MAX 0x7fff
52 #define I2_MIN ((-I2_MAX)-1)
53 #define UI2_MAX 0xffff
54 #define UI2_MIN 0
55 #define I4_MAX 0x7fffffff
56 #define I4_MIN ((-I4_MAX)-1)
57 #define UI4_MAX 0xffffffff
58 #define UI4_MIN 0
59 #define I8_MAX (((LONGLONG)I4_MAX << 32) | UI4_MAX)
60 #define I8_MIN ((-I8_MAX)-1)
61 #define UI8_MAX (((ULONGLONG)UI4_MAX << 32) | UI4_MAX)
62 #define UI8_MIN 0
63 #define DATE_MAX 2958465
64 #define DATE_MIN -657434
65 #define R4_MAX 3.402823567797336e38
66 #define R4_MIN 1.40129846432481707e-45
67 #define R8_MAX 1.79769313486231470e+308
68 #define R8_MIN 4.94065645841246544e-324
69
70 /* Value of sign for a positive decimal number */
71 #define DECIMAL_POS 0
72
73 /* Native headers don't change the union ordering for DECIMAL sign/scale (duh).
74 * This means that the signscale member is only useful for setting both members to 0.
75 * SIGNSCALE creates endian-correct values so that we can properly set both at once
76 * to values other than 0.
77 */
78 #ifdef WORDS_BIGENDIAN
79 #define SIGNSCALE(sign,scale) (((scale) << 8) | sign)
80 #else
81 #define SIGNSCALE(sign,scale) (((sign) << 8) | scale)
82 #endif
83
84 /* Macros for getting at a DECIMAL's parts */
85 #define DEC_SIGN(d) ((d)->sign)
86 #define DEC_SCALE(d) ((d)->scale)
87 #define DEC_SIGNSCALE(d) ((d)->signscale)
88 #define DEC_HI32(d) ((d)->Hi32)
89 #define DEC_MID32(d) ((d)->Mid32)
90 #define DEC_LO32(d) ((d)->Lo32)
91 #define DEC_LO64(d) ((d)->Lo64)
92
93 #define DEC_MAX_SCALE 28 /* Maximum scale for a decimal */
94
95 /* Internal flags for low level conversion functions */
96 #define VAR_BOOLONOFF 0x0400 /* Convert bool to "On"/"Off" */
97 #define VAR_BOOLYESNO 0x0800 /* Convert bool to "Yes"/"No" */
98 #define VAR_NEGATIVE 0x1000 /* Number is negative */
99
100 /* The localised characters that make up a valid number */
101 typedef struct tagVARIANT_NUMBER_CHARS
102 {
103 WCHAR cNegativeSymbol;
104 WCHAR cPositiveSymbol;
105 WCHAR cDecimalPoint;
106 WCHAR cDigitSeperator;
107 WCHAR cCurrencyLocal;
108 WCHAR cCurrencyLocal2;
109 WCHAR cCurrencyDecimalPoint;
110 WCHAR cCurrencyDigitSeperator;
111 } VARIANT_NUMBER_CHARS;
112
113 void VARIANT_GetLocalisedNumberChars(VARIANT_NUMBER_CHARS*,LCID,DWORD);