-
Notifications
You must be signed in to change notification settings - Fork 11
/
sdo_utils.cpp
194 lines (177 loc) · 6.24 KB
/
sdo_utils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
+----------------------------------------------------------------------+
| (c) Copyright IBM Corporation 2005. |
| All Rights Reserved. |
+----------------------------------------------------------------------+
| |
| Licensed under the Apache License, Version 2.0 (the "License"); you |
| may not use this file except in compliance with the License. You may |
| obtain a copy of the License at |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| implied. See the License for the specific language governing |
| permissions and limitations under the License. |
+----------------------------------------------------------------------+
| Author: Caroline Maynard |
+----------------------------------------------------------------------+
*/
static char rcs_id[] = "$Id: sdo_utils.cpp 229262 2007-02-07 11:26:44Z cem $";
/*
* Utility functions for internal use by the SDO extension
*/
#ifdef PHP_WIN32
#include <iostream>
#include <math.h>
#include "zend_config.w32.h"
#endif
#include "php.h"
#include "php_sdo_int.h"
/* {{{ sdo_make_long_class_constant
* creates a class constant
*/
void sdo_make_long_class_constant(zend_class_entry *ce, char *name, long value)
{
/* Cannot emalloc the storage for this constant, it must endure beyond the current request */
zval *z_constant = (zval *)malloc(sizeof(zval));
INIT_PZVAL(z_constant);
ZVAL_LONG(z_constant, value);
zend_hash_update(&ce->constants_table, name, 1 + strlen(name), &z_constant, sizeof(zval *), NULL);
}
/* }}} */
/* {{{ sdo_parse_offset_param
* internal function to get an sdo property offset from a zval parameter.
* The value may have been passed as a SDO_Model_Property, an xpath or a property index.
* Calling functions should catch SDORuntimeException.
*/
int sdo_parse_offset_param (DataObjectPtr dop, zval *z_offset,
const Property **return_property, const char **return_xpath,
int property_required,
int quiet TSRMLS_DC) {
long prop_index;
const Property *property_p;
const char *xpath;
// char *class_name;
// char *space;
if (!z_offset) {
/* get here with a statement like $sdo[] = 'some value'; */
if (!quiet) {
const char *space, *class_name = get_active_class_name(&space TSRMLS_CC);
sdo_throw_exception_ex (sdo_unsupportedoperationexception_class_entry, 0, 0 TSRMLS_CC,
"%s%s%s(): cannot append a value - this object is not many-valued",
class_name, space, get_active_function_name(TSRMLS_C));
}
return FAILURE;
}
switch(Z_TYPE_P(z_offset)) {
case IS_NULL:
if (!quiet) {
const char *space, *class_name = get_active_class_name(&space TSRMLS_CC);
sdo_throw_exception_ex (sdo_unsupportedoperationexception_class_entry, 0, 0 TSRMLS_CC,
"%s%s%s(): parameter is NULL",
class_name, space, get_active_function_name(TSRMLS_C));
}
return FAILURE;
case IS_STRING:
xpath = Z_STRVAL_P(z_offset);
/* If the type is open, then it's OK for the xpath offset to
* specify an unknown property. But even an open type may have
* defined properties, so we still need to try for one.
*/
if (property_required || dop->hasProperty(xpath)) {
/* exception will be thrown if xpath is invalid */
property_p = &dop->getProperty(xpath);
} else {
property_p = NULL;
}
break;
case IS_LONG:
case IS_BOOL:
case IS_RESOURCE:
case IS_DOUBLE:
if (Z_TYPE_P(z_offset) == IS_DOUBLE) {
if (!quiet) {
const char *space, *class_name = get_active_class_name(&space TSRMLS_CC);
php_error(E_WARNING, "%s%s%s(): double parameter %f rounded to %i",
class_name, space, get_active_function_name(TSRMLS_C),
Z_DVAL_P(z_offset), (long)Z_DVAL_P(z_offset));
}
prop_index =(long)Z_DVAL_P(z_offset);
} else {
prop_index = Z_LVAL_P(z_offset);
}
/* Note an open type may not be specified using a property index,
* so no need to repeat the check that was done for IS_STRING above.
*/
property_p = &dop->getProperty(prop_index);
xpath = property_p->getName();
break;
case IS_OBJECT:
if (!instanceof_function(Z_OBJCE_P(z_offset), sdo_model_property_class_entry TSRMLS_CC)) {
if (!quiet) {
const char *space, *class_name = get_active_class_name(&space TSRMLS_CC);
sdo_throw_exception_ex (sdo_unsupportedoperationexception_class_entry, 0, 0 TSRMLS_CC,
"%s%s%s(): expects object parameter to be SDO_Model_Property, %s given",
class_name, space, get_active_function_name(TSRMLS_C),
Z_OBJCE_P(z_offset)->name);
}
return FAILURE;
}
property_p = sdo_model_property_get_property(z_offset TSRMLS_CC);
xpath = property_p->getName();
break;
default:
if (!quiet) {
const char *space, *class_name = get_active_class_name(&space TSRMLS_CC);
php_error(E_ERROR, "%s%s%s(): internal error - invalid dimension type %i",
class_name, space, get_active_function_name(TSRMLS_C),
Z_TYPE_P(z_offset));
}
return FAILURE;
}
if (return_xpath) {
*return_xpath = xpath;
}
if (return_property) {
*return_property = property_p;
}
return SUCCESS;
}
/* }}} */
/* {{{ sdo_map_zval_type
* internal function to get an sdo property type from a zval parameter.
* This is needed when the zval is to be assigned into an open type, that is,
* when the target SDO property type is not predetermined by the model.
*/
Type::Types sdo_map_zval_type (zval *z_value) {
Type::Types type_enum;
switch(Z_TYPE_P(z_value)) {
case IS_DOUBLE:
type_enum = Type::DoubleType;
break;
case IS_BOOL:
type_enum = Type::BooleanType;
break;
case IS_OBJECT:
type_enum = Type::DataObjectType;
break;
case IS_STRING:
type_enum = Type::StringType;
break;
default:
type_enum = Type::IntegerType;
break;
}
return type_enum;
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/