0
|
1 /*
|
|
2 long_double.c
|
|
3
|
|
4 Custom serializer for the long double (extended double) type as
|
|
5 xsd:decimal.
|
|
6
|
|
7 Compile this file and link it with your code.
|
|
8
|
|
9 gSOAP XML Web services tools
|
|
10 Copyright (C) 2000-2007, Robert van Engelen, Genivia Inc., All Rights Reserved.
|
|
11 This part of the software is released under ONE of the following licenses:
|
|
12 GPL, the gSOAP public license, OR Genivia's license for commercial use.
|
|
13 --------------------------------------------------------------------------------
|
|
14 gSOAP public license.
|
|
15
|
|
16 The contents of this file are subject to the gSOAP Public License Version 1.3
|
|
17 (the "License"); you may not use this file except in compliance with the
|
|
18 License. You may obtain a copy of the License at
|
|
19 http://www.cs.fsu.edu/~engelen/soaplicense.html
|
|
20 Software distributed under the License is distributed on an "AS IS" basis,
|
|
21 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
22 for the specific language governing rights and limitations under the License.
|
|
23
|
|
24 The Initial Developer of the Original Code is Robert A. van Engelen.
|
|
25 Copyright (C) 2000-2007, Robert van Engelen, Genivia, Inc., All Rights Reserved.
|
|
26 --------------------------------------------------------------------------------
|
|
27 GPL license.
|
|
28
|
|
29 This program is free software; you can redistribute it and/or modify it under
|
|
30 the terms of the GNU General Public License as published by the Free Software
|
|
31 Foundation; either version 2 of the License, or (at your option) any later
|
|
32 version.
|
|
33
|
|
34 This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
35 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
36 PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
37
|
|
38 You should have received a copy of the GNU General Public License along with
|
|
39 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
|
40 Place, Suite 330, Boston, MA 02111-1307 USA
|
|
41
|
|
42 Author contact information:
|
|
43 engelen@genivia.com / engelen@acm.org
|
|
44
|
|
45 This program is released under the GPL with the additional exemption that
|
|
46 compiling, linking, and/or using OpenSSL is allowed.
|
|
47 --------------------------------------------------------------------------------
|
|
48 A commercial use license is available from Genivia, Inc., contact@genivia.com
|
|
49 --------------------------------------------------------------------------------
|
|
50 */
|
|
51
|
|
52 /* soapH.h generated by soapcpp2: */
|
|
53 #include "soapH.h"
|
|
54 #include <float.h>
|
|
55
|
|
56 int soap_s2decimal(struct soap *soap, const char *s, long double *p)
|
|
57 { if (s)
|
|
58 { if (!*s)
|
|
59 return soap->error = SOAP_TYPE;
|
|
60 if (!soap_tag_cmp(s, "INF"))
|
|
61 *p = (long double)DBL_PINFTY;
|
|
62 else if (!soap_tag_cmp(s, "+INF"))
|
|
63 *p = (long double)DBL_PINFTY;
|
|
64 else if (!soap_tag_cmp(s, "-INF"))
|
|
65 *p = (long double)DBL_NINFTY;
|
|
66 else if (!soap_tag_cmp(s, "NaN"))
|
|
67 *p = (long double)DBL_NAN;
|
|
68 else
|
|
69 {
|
|
70 #if defined(HAVE_STRTOLD_L)
|
|
71 char *r;
|
|
72 *p = strtold_l(s, &r, NULL);
|
|
73 if (*r)
|
|
74 #elif defined(HAVE_STRTOLD)
|
|
75 char *r;
|
|
76 *p = strtold(s, &r);
|
|
77 if (*r)
|
|
78 #endif
|
|
79 #if defined(HAVE_SSCANF_L)
|
|
80 if (sscanf_l(s, NULL, "%Lg", p) != 1)
|
|
81 soap->error = SOAP_TYPE;
|
|
82 #elif defined(HAVE_SSCANF)
|
|
83 if (sscanf(s, "%Lg", p) != 1)
|
|
84 soap->error = SOAP_TYPE;
|
|
85 #else
|
|
86 soap->error = SOAP_TYPE;
|
|
87 #endif
|
|
88 }
|
|
89 }
|
|
90 return soap->error;
|
|
91 }
|
|
92
|
|
93 const char *soap_decimal2s(struct soap *soap, long double n)
|
|
94 { char *s;
|
|
95 if (soap_isnan(n))
|
|
96 return "NaN";
|
|
97 if (soap_ispinfd(n))
|
|
98 return "INF";
|
|
99 if (soap_isninfd(n))
|
|
100 return "-INF";
|
|
101 s = soap->tmpbuf;
|
|
102 #if defined(HAVE_SPRINTF_L)
|
|
103 sprintf_l(s, NULL, "%.*Lg", LDBL_DIG, n);
|
|
104 #else
|
|
105 sprintf(s, "%.*Lg", LDBL_DIG, n);
|
|
106 s = strchr(s, ','); /* convert decimal comma to DP */
|
|
107 if (s)
|
|
108 *s = '.';
|
|
109 #endif
|
|
110 return soap->tmpbuf;
|
|
111 }
|
|
112
|
|
113 int
|
|
114 soap_outdecimal(struct soap *soap, const char *tag, int id, const long double *p, const char *type, int n)
|
|
115 { if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
|
|
116 || soap_string_out(soap, soap_decimal2s(soap, *p), 0))
|
|
117 return soap->error;
|
|
118 return soap_element_end_out(soap, tag);
|
|
119 }
|
|
120
|
|
121 long double *
|
|
122 soap_indecimal(struct soap *soap, const char *tag, long double *p, const char *type, int t)
|
|
123 { if (soap_element_begin_in(soap, tag, 0, type))
|
|
124 return NULL;
|
|
125 p = (long double*)soap_id_enter(soap, soap->id, p, t, sizeof(long double), 0, NULL, NULL, NULL);
|
|
126 if (*soap->href)
|
|
127 p = (long double*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(long double), 0, NULL);
|
|
128 else if (p)
|
|
129 { if (soap_s2decimal(soap, soap_value(soap), p))
|
|
130 return NULL;
|
|
131 }
|
|
132 if (soap->body && soap_element_end_in(soap, tag))
|
|
133 return NULL;
|
|
134 return p;
|
|
135 }
|