1 : /**********************************************************************
2 : * $Id: iom_attr.cpp 12582 2007-10-29 09:38:21Z pka $
3 : *
4 : * Project: iom - The INTERLIS Object Model
5 : * Purpose: For more information, please see <http://iom.sourceforge.net>
6 : * Author: Claude Eisenhut
7 : *
8 : **********************************************************************
9 : * Copyright (c) 2007, Claude Eisenhut
10 : *
11 : * Permission is hereby granted, free of charge, to any person obtaining a
12 : * copy of this software and associated documentation files (the "Software"),
13 : * to deal in the Software without restriction, including without limitation
14 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 : * and/or sell copies of the Software, and to permit persons to whom the
16 : * Software is furnished to do so, subject to the following conditions:
17 : *
18 : * The above copyright notice and this permission notice shall be included
19 : * in all copies or substantial portions of the Software.
20 : *
21 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 : * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 : * DEALINGS IN THE SOFTWARE.
28 : ****************************************************************************/
29 :
30 :
31 : /** @file
32 : * implementation of object attribute
33 : * @defgroup attribute attribute level functions
34 : * @{
35 : */
36 : #include <string.h>
37 : #include <iom/iom_p.h>
38 :
39 : /** gets the number of attributes, roles and embedded roles
40 : * of an object.
41 : */
42 0 : extern "C" int iom_getattrcount(IOM_OBJECT object)
43 : {
44 0 : return object->getAttrCount();
45 : }
46 :
47 : /** gets the name of an attribute, role or embedded role.
48 : * returns a pointer to a static buffer.
49 : */
50 0 : extern "C" IOM_TAG iom_getattrname(IOM_OBJECT object,int index)
51 : {
52 : static char *name=0;
53 0 : int tag=object->getAttrName(index);
54 0 : if(name){
55 0 : XMLString::release(&name);
56 : }
57 0 : const XMLCh *const name_w=ParserHandler::getTagName(tag);
58 0 : name=XMLString::transcode(name_w);
59 0 : return name;
60 : }
61 :
62 : /** gets the number of values of an attribute.
63 : */
64 0 : extern "C" int iom_getattrvaluecount(IOM_OBJECT object,IOM_TAG attrName)
65 : {
66 0 : int tag=ParserHandler::getTagId(attrName);
67 0 : return object->getAttrValueCount(tag);
68 : }
69 :
70 : /** gets the value of a primitive type attribute.
71 : * returns 0 if the attribute doesn't exist or has no value
72 : * Returns a pointer to a static buffer.
73 : */
74 0 : extern "C" char *iom_getattrvalue(IOM_OBJECT object,IOM_TAG attrName)
75 : {
76 : static char *value=0;
77 0 : if(value){
78 0 : XMLString::release(&value);
79 : }
80 0 : int nameId=ParserHandler::getTagId(attrName);
81 0 : if(!nameId) return 0;
82 0 : const XMLCh *ret=object->getAttrValue(nameId);
83 0 : if(!ret)return 0;
84 0 : value=XMLString::transcode(ret);
85 0 : return value;
86 : }
87 :
88 : /** gets the value of a primitive type attribute.
89 : * returns 0 if the attribute doesn't exist or has no value
90 : * Returns a pointer to a static buffer.
91 : */
92 0 : extern "C" char *iom_getattrvalueUTF8(IOM_OBJECT object,IOM_TAG attrName)
93 : {
94 : static char *value=0;
95 0 : if(value){
96 0 : XMLString::release(&value);
97 : }
98 0 : int nameId=ParserHandler::getTagId(attrName);
99 0 : if(!nameId) return 0;
100 0 : const XMLCh *ret=object->getAttrValue(nameId);
101 0 : if(!ret)return 0;
102 0 : value=iom_toUTF8(ret);
103 0 : return value;
104 : }
105 :
106 : /** sets the value of a primitive type attribute.
107 : * If value==0, the attribute is set to undefined.
108 : */
109 0 : extern "C" void iom_setattrvalue(IOM_OBJECT object,IOM_TAG attrName,const char *value)
110 : {
111 0 : if(value){
112 0 : object->setAttrValue(ParserHandler::getTagId(attrName),X(value));
113 : }else{
114 0 : object->setAttrValue(ParserHandler::getTagId(attrName),0);
115 : }
116 0 : }
117 : /** sets the value of a primitive type attribute.
118 : * If value==0, the attribute is set to undefined.
119 : */
120 0 : extern "C" void iom_setattrvalueUTF8(IOM_OBJECT object,IOM_TAG attrName,const char *value)
121 : {
122 0 : if(value){
123 0 : XMLCh *unicodeForm=iom_fromUTF8(value);
124 0 : object->setAttrValue(ParserHandler::getTagId(attrName),unicodeForm);
125 0 : XMLString::release(&unicodeForm);
126 : }else{
127 0 : object->setAttrValue(ParserHandler::getTagId(attrName),0);
128 : }
129 0 : }
130 :
131 : /** sets the attribute to undefined.
132 : */
133 0 : extern "C" void iom_setattrundefined(IOM_OBJECT object,IOM_TAG attrName)
134 : {
135 0 : object->setAttrUndefined(ParserHandler::getTagId(attrName));
136 0 : }
137 :
138 : /** gets the value of a primitive type attribute.
139 : * returns 0 if the attribute doesn't exist or has no value
140 : * Returns a pointer to a static buffer.
141 : */
142 0 : extern "C" char *iom_getattrprim(IOM_OBJECT object,IOM_TAG attrName,int index)
143 : {
144 : static char *value=0;
145 0 : if(value){
146 0 : XMLString::release(&value);
147 : }
148 0 : int tag=ParserHandler::getTagId(attrName);
149 0 : const XMLCh *ret=object->getAttrPrim(tag,index);
150 0 : if(!ret)return 0;
151 0 : value=XMLString::transcode(ret);
152 0 : return value;
153 : }
154 : /** gets the value of a primitive type attribute.
155 : * returns 0 if the attribute doesn't exist or has no value
156 : * Returns a pointer to a static buffer.
157 : */
158 0 : extern "C" char *iom_getattrprimUTF8(IOM_OBJECT object,IOM_TAG attrName,int index)
159 : {
160 : static char *value=0;
161 0 : if(value){
162 0 : XMLString::release(&value);
163 : }
164 0 : int tag=ParserHandler::getTagId(attrName);
165 0 : const XMLCh *ret=object->getAttrPrim(tag,index);
166 0 : if(!ret)return 0;
167 0 : value=iom_toUTF8(ret);
168 0 : return value;
169 : }
170 :
171 : /** gets the value of a object type attribute.
172 : * returns 0 if the attribute doesn't exist or has no value
173 : * It is the responsibility of the caller to release the returned object.
174 : */
175 0 : extern "C" IOM_OBJECT iom_getattrobj(IOM_OBJECT object,IOM_TAG attrName,int index)
176 : {
177 0 : int tag=ParserHandler::getTagId(attrName);
178 0 : IomObject ret=object->getAttrObj(tag,index);
179 0 : return ret.isNull() ? 0 : ret->getRef();
180 : }
181 :
182 : /** replaces the value of an object type attribute.
183 : */
184 0 : extern "C" IOM_OBJECT iom_changeattrobj(IOM_OBJECT object,IOM_TAG attrName,int index,IOM_TAG type)
185 : {
186 0 : IomObject ret=new iom_object();
187 0 : ret->setTag(ParserHandler::getTagId(type));
188 0 : object->setAttrObj(ParserHandler::getTagId(attrName),index,ret);
189 0 : return ret->getRef();
190 : }
191 :
192 : /** insert a new value of an object type attribute.
193 : */
194 0 : extern "C" IOM_OBJECT iom_insertattrobj(IOM_OBJECT object,IOM_TAG attrName,int index,IOM_TAG type)
195 : {
196 0 : IomObject ret=new iom_object();
197 0 : ret->setTag(ParserHandler::getTagId(type));
198 0 : object->insertAttrObj(ParserHandler::getTagId(attrName),index,ret);
199 0 : return ret->getRef();
200 : }
201 :
202 : /** add a new value of an object type attribute to end of list.
203 : */
204 0 : extern "C" IOM_OBJECT iom_addattrobj(IOM_OBJECT object,IOM_TAG attrName,IOM_TAG type)
205 : {
206 0 : IomObject ret=new iom_object();
207 0 : ret->setTag(ParserHandler::getTagId(type));
208 0 : object->addAttrObj(ParserHandler::getTagId(attrName),ret);
209 0 : return ret->getRef();
210 : }
211 :
212 : /** remove a value of an object type attribute from the list.
213 : */
214 0 : extern "C" void iom_deleteattrobj(IOM_OBJECT object,IOM_TAG attrName,int index)
215 : {
216 0 : object->removeAttrObj(ParserHandler::getTagId(attrName),index);
217 0 : }
218 :
219 : /** gets the number of xml-elements of an object.
220 : * This function can only be called after reading a file.
221 : */
222 0 : extern "C" int iom_getxmlelecount(IOM_OBJECT object)
223 : {
224 0 : return object->getXmleleCount();
225 : }
226 :
227 : /** gets the attribute name of an xml-element of an object.
228 : * To get the value use iom_getattrprim(), iom_getattrobj().
229 : * This function can only be called after reading a file.
230 : */
231 0 : extern "C" IOM_TAG iom_getxmleleattrname(IOM_OBJECT object,int index)
232 : {
233 : static char *name=0;
234 0 : int tag=object->getXmleleAttrName(index);
235 0 : if(name){
236 0 : XMLString::release(&name);
237 : }
238 0 : const XMLCh *const name_w=ParserHandler::getTagName(tag);
239 0 : name=XMLString::transcode(name_w);
240 0 : return name;
241 : }
242 :
243 : /** gets the index of the value of an xml-element of an object.
244 : * This function can only be called after reading a file.
245 : * To get the value use iom_getattrprim(), iom_getattrobj().
246 : */
247 0 : extern "C" int iom_getxmlelevalueidx(IOM_OBJECT object,int index)
248 : {
249 0 : return object->getXmleleValueIdx(index);
250 : }
251 :
252 : /** gets the value of a primitive type attribute.
253 : * returns 0 if the attribute doesn't exist or has no value
254 : * Returns a pointer to a static buffer.
255 : */
256 0 : extern "C" char *iom_getxmleleprim(IOM_OBJECT object,int index)
257 : {
258 : static char *value=0;
259 0 : if(value){
260 0 : XMLString::release(&value);
261 : }
262 0 : int tag=object->getXmleleAttrName(index);
263 0 : int val_index=object->getXmleleValueIdx(index);
264 0 : const XMLCh *ret=object->getAttrPrim(tag,val_index);
265 0 : if(!ret)return 0;
266 0 : value=XMLString::transcode(ret);
267 0 : return value;
268 : }
269 : /** gets the value of a primitive type attribute.
270 : * returns 0 if the attribute doesn't exist or has no value
271 : * Returns a pointer to a static buffer.
272 : */
273 0 : extern "C" char *iom_getxmleleprimUTF8(IOM_OBJECT object,int index)
274 : {
275 : static char *value=0;
276 0 : if(value){
277 0 : XMLString::release(&value);
278 : }
279 0 : int tag=object->getXmleleAttrName(index);
280 0 : int val_index=object->getXmleleValueIdx(index);
281 0 : const XMLCh *ret=object->getAttrPrim(tag,val_index);
282 0 : if(!ret)return 0;
283 0 : value=iom_toUTF8(ret);
284 0 : return value;
285 : }
286 :
287 : /** gets the value of a object type attribute.
288 : * returns 0 if the attribute doesn't exist or has no value
289 : * It is the responsibility of the caller to release the returned object.
290 : */
291 0 : extern "C" IOM_OBJECT iom_getxmleleobj(IOM_OBJECT object,int index)
292 : {
293 0 : int tag=object->getXmleleAttrName(index);
294 0 : int val_index=object->getXmleleValueIdx(index);
295 0 : return object->getAttrObj(tag,val_index)->getRef();
296 896 : }
297 448 :
298 : /** @}
299 : */
300 :
|