merge the formfield patch from ooo-build
[ooovba.git] / registry / source / reflwrit.cxx
blobf0408bf6b41996a44c782ddfce1f17d7731952bb
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: reflwrit.cxx,v $
10 * $Revision: 1.15.10.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_registry.hxx"
34 #include <new>
35 #include <sal/types.h>
36 #include <sal/macros.h>
37 #include <osl/endian.h>
38 #include <rtl/alloc.h>
39 #include "rtl/string.hxx"
40 #include "rtl/ustring.hxx"
42 #include "registry/reflwrit.hxx"
43 #include "registry/version.h"
44 #include "registry/writer.h"
46 #include "reflcnst.hxx"
48 using namespace rtl;
50 namespace {
52 // Throws std::bad_alloc:
53 inline rtl::OString toByteString(rtl_uString const * str) {
54 return rtl::OString(
55 str->buffer, str->length, RTL_TEXTENCODING_UTF8,
56 OUSTRING_TO_OSTRING_CVTFLAGS);
61 static sal_Unicode NULL_WSTRING[1] = { 0 };
63 #if defined ( GCC ) && ( defined ( SCO ) )
64 ORealDynamicLoader* ODynamicLoader<RegistryTypeWriter_Api>::m_pLoader = NULL;
65 #endif
67 #define BLOP_OFFSET_MAGIC 0
68 #define BLOP_OFFSET_SIZE (BLOP_OFFSET_MAGIC + sizeof(sal_uInt32))
69 #define BLOP_OFFSET_MINOR (BLOP_OFFSET_SIZE + sizeof(sal_uInt32))
70 #define BLOP_OFFSET_MAJOR (BLOP_OFFSET_MINOR + sizeof(sal_uInt16))
71 #define BLOP_OFFSET_N_ENTRIES (BLOP_OFFSET_MAJOR + sizeof(sal_uInt16))
72 #define BLOP_OFFSET_TYPE_SOURCE (BLOP_OFFSET_N_ENTRIES + sizeof(sal_uInt16))
73 #define BLOP_OFFSET_TYPE_CLASS (BLOP_OFFSET_TYPE_SOURCE + sizeof(sal_uInt16))
74 #define BLOP_OFFSET_THIS (BLOP_OFFSET_TYPE_CLASS + sizeof(sal_uInt16))
75 #define BLOP_OFFSET_UIK (BLOP_OFFSET_THIS + sizeof(sal_uInt16))
76 #define BLOP_OFFSET_DOKU (BLOP_OFFSET_UIK + sizeof(sal_uInt16))
77 #define BLOP_OFFSET_FILENAME (BLOP_OFFSET_DOKU + sizeof(sal_uInt16))
78 #define BLOP_HEADER_N_ENTRIES 6
80 #define BLOP_OFFSET_N_SUPERTYPES 0
81 #define BLOP_OFFSET_SUPERTYPES (BLOP_OFFSET_N_SUPERTYPES + sizeof(sal_uInt16))
83 #define BLOP_FIELD_ENTRY_ACCESS 0
84 #define BLOP_FIELD_ENTRY_NAME (BLOP_FIELD_ENTRY_ACCESS + sizeof(sal_uInt16))
85 #define BLOP_FIELD_ENTRY_TYPE (BLOP_FIELD_ENTRY_NAME + sizeof(sal_uInt16))
86 #define BLOP_FIELD_ENTRY_VALUE (BLOP_FIELD_ENTRY_TYPE + sizeof(sal_uInt16))
87 #define BLOP_FIELD_ENTRY_DOKU (BLOP_FIELD_ENTRY_VALUE + sizeof(sal_uInt16))
88 #define BLOP_FIELD_ENTRY_FILENAME (BLOP_FIELD_ENTRY_DOKU + sizeof(sal_uInt16))
89 #define BLOP_FIELD_N_ENTRIES 6
91 #define BLOP_METHOD_SIZE 0
92 #define BLOP_METHOD_MODE (BLOP_METHOD_SIZE + sizeof(sal_uInt16))
93 #define BLOP_METHOD_NAME (BLOP_METHOD_MODE + sizeof(sal_uInt16))
94 #define BLOP_METHOD_RETURN (BLOP_METHOD_NAME + sizeof(sal_uInt16))
95 #define BLOP_METHOD_DOKU (BLOP_METHOD_RETURN + sizeof(sal_uInt16))
96 #define BLOP_METHOD_N_ENTRIES 5
98 #define BLOP_PARAM_TYPE 0
99 #define BLOP_PARAM_MODE (BLOP_PARAM_TYPE + sizeof(sal_uInt16))
100 #define BLOP_PARAM_NAME (BLOP_PARAM_MODE + sizeof(sal_uInt16))
101 #define BLOP_PARAM_N_ENTRIES 3
103 #define BLOP_REFERENCE_TYPE 0
104 #define BLOP_REFERENCE_NAME (BLOP_REFERENCE_TYPE + sizeof(sal_uInt16))
105 #define BLOP_REFERENCE_DOKU (BLOP_REFERENCE_NAME + sizeof(sal_uInt16))
106 #define BLOP_REFERENCE_ACCESS (BLOP_REFERENCE_DOKU + sizeof(sal_uInt16))
107 #define BLOP_REFERENCE_N_ENTRIES 4
109 sal_uInt32 UINT16StringLen(const sal_uInt8* wstring)
111 if (!wstring) return 0;
113 const sal_uInt8* b = wstring;
115 while (b[0] || b[1]) b += sizeof(sal_uInt16);
117 return ((b - wstring) / sizeof(sal_uInt16));
120 sal_uInt32 writeString(sal_uInt8* buffer, const sal_Unicode* v)
122 sal_uInt32 len = rtl_ustr_getLength(v) + 1;
123 sal_uInt32 i;
124 sal_uInt8* buff = buffer;
126 for (i = 0; i < len; i++)
128 buff += writeUINT16(buff, (sal_uInt16) v[i]);
131 return (buff - buffer);
134 sal_uInt32 readString(const sal_uInt8* buffer, sal_Unicode* v, sal_uInt32 maxSize)
136 sal_uInt32 len = SAL_MIN(UINT16StringLen(buffer) + 1, maxSize / 2);
137 sal_uInt32 i;
138 sal_uInt8* buff = (sal_uInt8*)buffer;
140 for (i = 0; i < (len - 1); i++)
142 sal_uInt16 aChar;
144 buff += readUINT16(buff, aChar);
146 v[i] = (sal_Unicode) aChar;
149 v[len - 1] = L'\0';
151 return (buff - ((sal_uInt8*)buffer));
154 sal_uInt32 writeFloat(sal_uInt8* buffer, float v)
156 union
158 float v;
159 sal_uInt32 b;
160 } x;
162 x.v = v;
164 #ifdef REGTYPE_IEEE_NATIVE
165 writeUINT32(buffer, x.b);
166 #else
167 # error no IEEE
168 #endif
170 return sizeof(sal_uInt32);
173 sal_uInt32 writeDouble(sal_uInt8* buffer, double v)
175 union
177 double v;
178 struct
180 sal_uInt32 b1;
181 sal_uInt32 b2;
182 } b;
183 } x;
185 x.v = v;
187 #ifdef REGTYPE_IEEE_NATIVE
188 # ifdef OSL_BIGENDIAN
189 writeUINT32(buffer, x.b.b1);
190 writeUINT32(buffer + sizeof(sal_uInt32), x.b.b2);
191 # else
192 writeUINT32(buffer, x.b.b2);
193 writeUINT32(buffer + sizeof(sal_uInt32), x.b.b1);
194 # endif
195 #else
196 # error no IEEE
197 #endif
199 return (sizeof(sal_uInt32) + sizeof(sal_uInt32));
202 /**************************************************************************
204 buffer write functions
206 **************************************************************************/
209 /**************************************************************************
211 struct CPInfo
213 **************************************************************************/
215 struct CPInfo
217 CPInfoTag m_tag;
218 union
220 const sal_Char* aUtf8;
221 RTUik* aUik;
222 RTConstValueUnion aConst;
223 } m_value;
225 sal_uInt16 m_index;
226 struct CPInfo* m_next;
228 CPInfo(CPInfoTag tag, struct CPInfo* prev);
230 sal_uInt32 getBlopSize();
232 sal_uInt32 toBlop(sal_uInt8* buffer);
235 CPInfo::CPInfo(CPInfoTag tag, struct CPInfo* prev)
236 : m_tag(tag)
237 , m_index(0)
238 , m_next(NULL)
240 if (prev)
242 m_index = prev->m_index + 1;
243 prev->m_next = this;
247 sal_uInt32 CPInfo::getBlopSize()
249 sal_uInt32 size = sizeof(sal_uInt32) /* size */ + sizeof(sal_uInt16) /* tag */;
251 switch (m_tag)
253 case CP_TAG_CONST_BOOL:
254 size += sizeof(sal_uInt8);
255 break;
256 case CP_TAG_CONST_BYTE:
257 size += sizeof(sal_uInt8);
258 break;
259 case CP_TAG_CONST_INT16:
260 size += sizeof(sal_Int16);
261 break;
262 case CP_TAG_CONST_UINT16:
263 size += sizeof(sal_uInt16);
264 break;
265 case CP_TAG_CONST_INT32:
266 size += sizeof(sal_Int32);
267 break;
268 case CP_TAG_CONST_UINT32:
269 size += sizeof(sal_uInt32);
270 break;
271 case CP_TAG_CONST_INT64:
272 size += sizeof(sal_Int64);
273 break;
274 case CP_TAG_CONST_UINT64:
275 size += sizeof(sal_uInt64);
276 break;
277 case CP_TAG_CONST_FLOAT:
278 size += sizeof(sal_uInt32);
279 break;
280 case CP_TAG_CONST_DOUBLE:
281 size += sizeof(sal_uInt32) + sizeof(sal_uInt32);
282 break;
283 case CP_TAG_CONST_STRING:
284 size += (rtl_ustr_getLength(m_value.aConst.aString) + 1) * sizeof(sal_uInt16);
285 break;
286 case CP_TAG_UTF8_NAME:
287 size += strlen(m_value.aUtf8) + 1;
288 break;
289 case CP_TAG_UIK:
290 size += sizeof(sal_uInt32) + sizeof(sal_uInt16) + sizeof(sal_uInt16) + sizeof(sal_uInt32) + sizeof(sal_uInt32);
291 break;
292 default:
293 break;
296 return size;
300 sal_uInt32 CPInfo::toBlop(sal_uInt8* buffer)
302 sal_uInt8* buff = buffer;
304 buff += writeUINT32(buff, getBlopSize());
305 buff += writeUINT16(buff, (sal_uInt16) m_tag);
307 switch (m_tag)
309 case CP_TAG_CONST_BOOL:
310 buff += writeBYTE(buff, (sal_uInt8) m_value.aConst.aBool);
311 break;
312 case CP_TAG_CONST_BYTE:
313 buff += writeBYTE(buff, m_value.aConst.aByte);
314 break;
315 case CP_TAG_CONST_INT16:
316 buff += writeINT16(buff, m_value.aConst.aShort);
317 break;
318 case CP_TAG_CONST_UINT16:
319 buff += writeINT16(buff, m_value.aConst.aUShort);
320 break;
321 case CP_TAG_CONST_INT32:
322 buff += writeINT32(buff, m_value.aConst.aLong);
323 break;
324 case CP_TAG_CONST_UINT32:
325 buff += writeUINT32(buff, m_value.aConst.aULong);
326 break;
327 case CP_TAG_CONST_INT64:
328 buff += writeUINT64(buff, m_value.aConst.aHyper);
329 break;
330 case CP_TAG_CONST_UINT64:
331 buff += writeUINT64(buff, m_value.aConst.aUHyper);
332 break;
333 case CP_TAG_CONST_FLOAT:
334 buff += writeFloat(buff, m_value.aConst.aFloat);
335 break;
336 case CP_TAG_CONST_DOUBLE:
337 buff += writeDouble(buff, m_value.aConst.aDouble);
338 break;
339 case CP_TAG_CONST_STRING:
340 buff += writeString(buff, m_value.aConst.aString);
341 break;
342 case CP_TAG_UTF8_NAME:
343 buff += writeUtf8(buff, m_value.aUtf8);
344 break;
345 case CP_TAG_UIK:
346 buff += writeUINT32(buff, m_value.aUik->m_Data1);
347 buff += writeUINT16(buff, m_value.aUik->m_Data2);
348 buff += writeUINT16(buff, m_value.aUik->m_Data3);
349 buff += writeUINT32(buff, m_value.aUik->m_Data4);
350 buff += writeUINT32(buff, m_value.aUik->m_Data5);
351 break;
352 default:
353 break;
356 return (buff - buffer);
360 /**************************************************************************
362 class FieldEntry
364 **************************************************************************/
366 class FieldEntry
369 public:
371 OString m_name;
372 OString m_typeName;
373 OString m_doku;
374 OString m_fileName;
375 RTFieldAccess m_access;
376 RTValueType m_constValueType;
377 RTConstValueUnion m_constValue;
379 FieldEntry();
380 ~FieldEntry();
382 void setData(const OString& name,
383 const OString& typeName,
384 const OString& doku,
385 const OString& fileName,
386 RTFieldAccess access,
387 RTValueType constValueType,
388 RTConstValueUnion constValue);
389 // throws std::bad_alloc
392 FieldEntry::FieldEntry()
393 : m_access(RT_ACCESS_INVALID)
394 , m_constValueType(RT_TYPE_NONE)
398 FieldEntry::~FieldEntry()
400 if (
401 (m_constValueType == RT_TYPE_STRING) &&
402 m_constValue.aString &&
403 (m_constValue.aString != NULL_WSTRING)
406 delete[] (sal_Unicode*)m_constValue.aString;
410 void FieldEntry::setData(const OString& name,
411 const OString& typeName,
412 const OString& doku,
413 const OString& fileName,
414 RTFieldAccess access,
415 RTValueType constValueType,
416 RTConstValueUnion constValue)
418 sal_Unicode * newValue = 0;
419 if (constValueType == RT_TYPE_STRING && constValue.aString != 0) {
420 sal_Int32 n = rtl_ustr_getLength(constValue.aString) + 1;
421 newValue = new sal_Unicode[n];
422 rtl_copyMemory(newValue, constValue.aString, n * sizeof (sal_Unicode));
425 m_name = name;
426 m_typeName = typeName;
427 m_doku = doku;
428 m_fileName = fileName;
430 if (
431 (m_constValueType == RT_TYPE_STRING) &&
432 m_constValue.aString &&
433 (m_constValue.aString != NULL_WSTRING)
436 delete[] (sal_Unicode*)m_constValue.aString;
439 m_access = access;
440 m_constValueType = constValueType;
442 if (m_constValueType == RT_TYPE_STRING)
444 if (constValue.aString == NULL)
445 m_constValue.aString = NULL_WSTRING;
446 else
448 m_constValue.aString = newValue;
451 else
453 m_constValue = constValue;
457 /**************************************************************************
459 class ParamEntry
461 **************************************************************************/
463 class ParamEntry
465 public:
467 OString m_typeName;
468 OString m_name;
469 RTParamMode m_mode;
471 ParamEntry();
472 ~ParamEntry();
474 void setData(const OString& typeName,
475 const OString& name,
476 RTParamMode mode);
479 ParamEntry::ParamEntry()
480 : m_mode(RT_PARAM_INVALID)
484 ParamEntry::~ParamEntry()
488 void ParamEntry::setData(const OString& typeName,
489 const OString& name,
490 RTParamMode mode)
492 m_name = name;
493 m_typeName = typeName;
494 m_mode = mode;
497 /**************************************************************************
499 class ReferenceEntry
501 **************************************************************************/
503 class ReferenceEntry
505 public:
507 OString m_name;
508 OString m_doku;
509 RTReferenceType m_type;
510 RTFieldAccess m_access;
512 ReferenceEntry();
513 ~ReferenceEntry();
515 void setData(const OString& name,
516 RTReferenceType refType,
517 const OString& doku,
518 RTFieldAccess access);
521 ReferenceEntry::ReferenceEntry()
522 : m_type(RT_REF_INVALID)
523 , m_access(RT_ACCESS_INVALID)
527 ReferenceEntry::~ReferenceEntry()
531 void ReferenceEntry::setData(const OString& name,
532 RTReferenceType refType,
533 const OString& doku,
534 RTFieldAccess access)
536 m_name = name;
537 m_doku = doku;
538 m_type = refType;
539 m_access = access;
542 /**************************************************************************
544 class MethodEntry
546 **************************************************************************/
548 class MethodEntry
550 public:
552 OString m_name;
553 OString m_returnTypeName;
554 RTMethodMode m_mode;
555 sal_uInt16 m_paramCount;
556 ParamEntry* m_params;
557 sal_uInt16 m_excCount;
558 OString* m_excNames;
559 OString m_doku;
561 MethodEntry();
562 ~MethodEntry();
564 void setData(const OString& name,
565 const OString& returnTypeName,
566 RTMethodMode mode,
567 sal_uInt16 paramCount,
568 sal_uInt16 excCount,
569 const OString& doku);
571 void setExcName(sal_uInt16 excIndex, const OString& name);
573 protected:
575 void reallocParams(sal_uInt16 size);
576 void reallocExcs(sal_uInt16 size);
579 MethodEntry::MethodEntry()
580 : m_mode(RT_MODE_INVALID)
581 , m_paramCount(0)
582 , m_params(NULL)
583 , m_excCount(0)
584 , m_excNames(NULL)
588 MethodEntry::~MethodEntry()
590 if (m_params)
591 delete[] m_params;
593 if (m_excNames)
594 delete[] m_excNames;
597 void MethodEntry::setData(const OString& name,
598 const OString& returnTypeName,
599 RTMethodMode mode,
600 sal_uInt16 paramCount,
601 sal_uInt16 excCount,
602 const OString& doku)
604 m_name = name;
605 m_returnTypeName = returnTypeName;
606 m_doku = doku;
608 m_mode = mode;
610 reallocParams(paramCount);
611 reallocExcs(excCount);
614 void MethodEntry::setExcName(sal_uInt16 excIndex, const OString& name)
616 if (excIndex < m_excCount)
618 m_excNames[excIndex] = name;
622 void MethodEntry::reallocParams(sal_uInt16 size)
624 ParamEntry* newParams;
626 if (size)
627 newParams = new ParamEntry[size];
628 else
629 newParams = NULL;
631 if (m_paramCount)
633 sal_uInt16 i;
635 for (i = 0; i < SAL_MIN(size, m_paramCount); i++)
637 newParams[i].setData(m_params[i].m_typeName, m_params[i].m_name, m_params[i].m_mode);
640 delete[] m_params;
643 m_paramCount = size;
644 m_params = newParams;
647 void MethodEntry::reallocExcs(sal_uInt16 size)
649 OString* newExcNames;
651 if (size)
652 newExcNames = new OString[size];
653 else
654 newExcNames = NULL;
656 sal_uInt16 i;
658 for (i = 0; i < SAL_MIN(size, m_excCount); i++)
660 newExcNames[i] = m_excNames[i];
663 delete[] m_excNames;
665 m_excCount = size;
666 m_excNames = newExcNames;
670 /**************************************************************************
672 class TypeRegistryEntry
674 **************************************************************************/
676 class TypeWriter
679 public:
681 sal_uInt32 m_refCount;
682 typereg_Version m_version;
683 RTTypeClass m_typeClass;
684 OString m_typeName;
685 sal_uInt16 m_nSuperTypes;
686 OString* m_superTypeNames;
687 RTUik* m_pUik;
688 OString m_doku;
689 OString m_fileName;
690 sal_uInt16 m_fieldCount;
691 FieldEntry* m_fields;
692 sal_uInt16 m_methodCount;
693 MethodEntry* m_methods;
694 sal_uInt16 m_referenceCount;
695 ReferenceEntry* m_references;
697 sal_uInt8* m_blop;
698 sal_uInt32 m_blopSize;
700 TypeWriter(typereg_Version version,
701 rtl::OString const & documentation,
702 rtl::OString const & fileName,
703 RTTypeClass RTTypeClass,
704 bool published,
705 const OString& typeName,
706 sal_uInt16 superTypeCount,
707 sal_uInt16 FieldCount,
708 sal_uInt16 methodCount,
709 sal_uInt16 referenceCount);
711 ~TypeWriter();
713 void setSuperType(sal_uInt16 index, OString const & name);
715 void createBlop(); // throws std::bad_alloc
718 TypeWriter::TypeWriter(typereg_Version version,
719 rtl::OString const & documentation,
720 rtl::OString const & fileName,
721 RTTypeClass RTTypeClass,
722 bool published,
723 const OString& typeName,
724 sal_uInt16 superTypeCount,
725 sal_uInt16 fieldCount,
726 sal_uInt16 methodCount,
727 sal_uInt16 referenceCount)
728 : m_refCount(1)
729 , m_version(version)
730 , m_typeClass(
731 static_cast< enum RTTypeClass >(
732 RTTypeClass | (published ? RT_TYPE_PUBLISHED : 0)))
733 , m_typeName(typeName)
734 , m_nSuperTypes(superTypeCount)
735 , m_pUik(NULL)
736 , m_doku(documentation)
737 , m_fileName(fileName)
738 , m_fieldCount(fieldCount)
739 , m_methodCount(methodCount)
740 , m_referenceCount(referenceCount)
741 , m_blop(NULL)
742 , m_blopSize(0)
744 if (m_nSuperTypes > 0)
746 m_superTypeNames = new OString[m_nSuperTypes];
747 } else
749 m_superTypeNames = NULL;
752 if (m_fieldCount)
753 m_fields = new FieldEntry[fieldCount];
755 if (m_methodCount)
756 m_methods = new MethodEntry[methodCount];
758 if (m_referenceCount)
759 m_references = new ReferenceEntry[referenceCount];
762 TypeWriter::~TypeWriter()
764 if (m_superTypeNames)
765 delete[] m_superTypeNames;
767 if (m_blop)
768 delete[] m_blop;
770 if (m_fieldCount)
771 delete[] m_fields;
773 if (m_methodCount)
774 delete[] m_methods;
776 if (m_referenceCount)
777 delete[] m_references;
779 if (m_pUik)
780 delete m_pUik;
783 void TypeWriter::setSuperType(sal_uInt16 index, OString const & name)
785 m_superTypeNames[index] = name;
788 void TypeWriter::createBlop()
790 //TODO: Fix memory leaks that occur when std::bad_alloc is thrown
792 sal_uInt8* pBlopFields = NULL;
793 sal_uInt8* pBlopMethods = NULL;
794 sal_uInt8* pBlopReferences = NULL;
795 sal_uInt8* pBuffer = NULL;
796 sal_uInt32 blopFieldsSize = 0;
797 sal_uInt32 blopMethodsSize = 0;
798 sal_uInt32 blopReferenceSize = 0;
800 CPInfo root(CP_TAG_INVALID, NULL);
801 sal_uInt16 cpIndexThisName = 0;
802 sal_uInt16* cpIndexSuperNames = NULL;
803 sal_uInt16 cpIndexUik = 0;
804 sal_uInt16 cpIndexDoku = 0;
805 sal_uInt16 cpIndexFileName = 0;
806 CPInfo* pInfo = NULL;
808 sal_uInt16 entrySize = sizeof(sal_uInt16);
809 sal_uInt32 blopHeaderEntrySize = BLOP_OFFSET_N_ENTRIES + entrySize + (BLOP_HEADER_N_ENTRIES * entrySize);
810 sal_uInt32 blopFieldEntrySize = BLOP_FIELD_N_ENTRIES * entrySize;
811 sal_uInt32 blopMethodEntrySize = BLOP_METHOD_N_ENTRIES * entrySize;
812 sal_uInt32 blopParamEntrySize = BLOP_PARAM_N_ENTRIES * entrySize;
813 sal_uInt32 blopReferenceEntrySize = BLOP_REFERENCE_N_ENTRIES * entrySize;
815 sal_uInt32 blopSize = blopHeaderEntrySize;
817 // create CP entry for this name
818 pInfo = new CPInfo(CP_TAG_UTF8_NAME, &root);
819 pInfo->m_value.aUtf8 = m_typeName.getStr();
820 cpIndexThisName = pInfo->m_index;
822 // nSuperTypes
823 blopSize += entrySize;
825 // create CP entry for super names
826 if (m_nSuperTypes)
828 blopSize += m_nSuperTypes * entrySize;
830 cpIndexSuperNames = new sal_uInt16[m_nSuperTypes];
832 for (sal_uInt32 i=0; i < m_nSuperTypes; i++)
834 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
835 pInfo->m_value.aUtf8 = m_superTypeNames[i].getStr();
836 cpIndexSuperNames[i] = pInfo->m_index;
840 // create CP entry for uik
841 if (m_pUik != NULL)
843 pInfo = new CPInfo(CP_TAG_UIK, pInfo);
844 pInfo->m_value.aUik = m_pUik;
845 cpIndexUik = pInfo->m_index;
848 // create CP entry for doku
849 if (m_doku.getLength())
851 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
852 pInfo->m_value.aUtf8 = m_doku.getStr();
853 cpIndexDoku = pInfo->m_index;
856 // create CP entry for idl source filename
857 if (m_fileName.getLength())
859 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
860 pInfo->m_value.aUtf8 = m_fileName.getStr();
861 cpIndexFileName = pInfo->m_index;
864 // fields blop
865 blopSize += sizeof(sal_uInt16); // fieldCount + nFieldEntries
867 if (m_fieldCount)
869 sal_uInt16 cpIndexName = 0;
870 sal_uInt16 cpIndexTypeName = 0;
871 sal_uInt16 cpIndexValue = 0;
872 sal_uInt16 cpIndexDoku2 = 0;
873 sal_uInt16 cpIndexFileName2 = 0;
875 // nFieldEntries + n fields
876 blopFieldsSize = sizeof(sal_uInt16) + (m_fieldCount * blopFieldEntrySize);
878 blopSize += blopFieldsSize;
880 pBlopFields = new sal_uInt8[blopFieldsSize];
881 pBuffer = pBlopFields;
883 pBuffer += writeUINT16(pBuffer, BLOP_FIELD_N_ENTRIES);
885 for (sal_uInt16 i = 0; i < m_fieldCount; i++)
887 cpIndexName = 0;
888 cpIndexTypeName = 0;
889 cpIndexValue = 0;
890 cpIndexDoku2 = 0;
891 cpIndexFileName2 = 0;
893 pBuffer += writeUINT16(pBuffer, m_fields[i].m_access);
895 if (m_fields[i].m_name.getLength())
897 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
898 pInfo->m_value.aUtf8 = m_fields[i].m_name.getStr();
899 cpIndexName = pInfo->m_index;
901 pBuffer += writeUINT16(pBuffer, cpIndexName);
903 if (m_fields[i].m_typeName.getLength())
905 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
906 pInfo->m_value.aUtf8 = m_fields[i].m_typeName.getStr();
907 cpIndexTypeName = pInfo->m_index;
909 pBuffer += writeUINT16(pBuffer, cpIndexTypeName);
911 if (m_fields[i].m_constValueType != RT_TYPE_NONE)
913 pInfo = new CPInfo((CPInfoTag)m_fields[i].m_constValueType, pInfo);
914 pInfo->m_value.aConst = m_fields[i].m_constValue;
915 cpIndexValue = pInfo->m_index;
917 pBuffer += writeUINT16(pBuffer, cpIndexValue);
919 if (m_fields[i].m_doku.getLength())
921 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
922 pInfo->m_value.aUtf8 = m_fields[i].m_doku.getStr();
923 cpIndexDoku2 = pInfo->m_index;
925 pBuffer += writeUINT16(pBuffer, cpIndexDoku2);
927 if (m_fields[i].m_fileName.getLength())
929 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
930 pInfo->m_value.aUtf8 = m_fields[i].m_fileName.getStr();
931 cpIndexFileName2 = pInfo->m_index;
933 pBuffer += writeUINT16(pBuffer, cpIndexFileName2);
937 // methods blop
938 blopSize += sizeof(sal_uInt16); // methodCount
940 if (m_methodCount)
942 sal_uInt16* pMethodEntrySize = new sal_uInt16[m_methodCount];
943 sal_uInt16 cpIndexName = 0;
944 sal_uInt16 cpIndexReturn = 0;
945 sal_uInt16 cpIndexDoku2 = 0;
947 // nMethodEntries + nParamEntries
948 blopMethodsSize = (2 * sizeof(sal_uInt16));
950 for (sal_uInt16 i = 0; i < m_methodCount; i++)
952 pMethodEntrySize[i] = (sal_uInt16)
953 ( blopMethodEntrySize + // header
954 sizeof(sal_uInt16) + // parameterCount
955 (m_methods[i].m_paramCount * blopParamEntrySize) + // exceptions
956 sizeof(sal_uInt16) + // exceptionCount
957 (m_methods[i].m_excCount * sizeof(sal_uInt16)) ); // exceptions
959 blopMethodsSize += pMethodEntrySize[i];
962 pBlopMethods = new sal_uInt8[blopMethodsSize];
964 blopSize += blopMethodsSize;
966 pBuffer = pBlopMethods;
968 pBuffer += writeUINT16(pBuffer, BLOP_METHOD_N_ENTRIES);
969 pBuffer += writeUINT16(pBuffer, BLOP_PARAM_N_ENTRIES );
971 for (sal_uInt16 i = 0; i < m_methodCount; i++)
973 cpIndexReturn = 0;
974 cpIndexDoku2 = 0;
976 pBuffer += writeUINT16(pBuffer, pMethodEntrySize[i]);
977 pBuffer += writeUINT16(
978 pBuffer,
979 sal::static_int_cast< sal_uInt16 >(m_methods[i].m_mode));
981 if (m_methods[i].m_name.getLength())
983 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
984 pInfo->m_value.aUtf8 = m_methods[i].m_name.getStr();
985 cpIndexName = pInfo->m_index;
987 pBuffer += writeUINT16(pBuffer, cpIndexName);
988 cpIndexName = 0;
990 if (m_methods[i].m_returnTypeName.getLength())
992 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
993 pInfo->m_value.aUtf8 = m_methods[i].m_returnTypeName.getStr();
994 cpIndexReturn = pInfo->m_index;
996 pBuffer += writeUINT16(pBuffer, cpIndexReturn);
998 if (m_methods[i].m_doku.getLength())
1000 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
1001 pInfo->m_value.aUtf8 = m_methods[i].m_doku.getStr();
1002 cpIndexDoku2 = pInfo->m_index;
1004 pBuffer += writeUINT16(pBuffer, cpIndexDoku2);
1006 sal_uInt16 j;
1008 pBuffer += writeUINT16(pBuffer, m_methods[i].m_paramCount);
1010 for (j = 0; j < m_methods[i].m_paramCount; j++)
1012 if (m_methods[i].m_params[j].m_typeName.getLength())
1014 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
1015 pInfo->m_value.aUtf8 = m_methods[i].m_params[j].m_typeName.getStr();
1016 cpIndexName = pInfo->m_index;
1018 pBuffer += writeUINT16(pBuffer, cpIndexName);
1019 cpIndexName = 0;
1021 pBuffer += writeUINT16(
1022 pBuffer,
1023 sal::static_int_cast< sal_uInt16 >(
1024 m_methods[i].m_params[j].m_mode));
1026 if (m_methods[i].m_params[j].m_name.getLength())
1028 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
1029 pInfo->m_value.aUtf8 = m_methods[i].m_params[j].m_name.getStr();
1030 cpIndexName = pInfo->m_index;
1032 pBuffer += writeUINT16(pBuffer, cpIndexName);
1033 cpIndexName = 0;
1036 pBuffer += writeUINT16(pBuffer, m_methods[i].m_excCount);
1038 for (j = 0; j < m_methods[i].m_excCount; j++)
1040 if (m_methods[i].m_excNames[j].getLength())
1042 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
1043 pInfo->m_value.aUtf8 = m_methods[i].m_excNames[j].getStr();
1044 cpIndexName = pInfo->m_index;
1046 pBuffer += writeUINT16(pBuffer, cpIndexName);
1047 cpIndexName = 0;
1051 delete[] pMethodEntrySize;
1054 // reference blop
1055 blopSize += entrySize; // referenceCount
1057 if (m_referenceCount)
1059 sal_uInt16 cpIndexName = 0;
1060 sal_uInt16 cpIndexDoku2 = 0;
1062 // nReferenceEntries + n references
1063 blopReferenceSize = entrySize + (m_referenceCount * blopReferenceEntrySize);
1065 blopSize += blopReferenceSize;
1067 pBlopReferences = new sal_uInt8[blopReferenceSize];
1068 pBuffer = pBlopReferences;
1070 pBuffer += writeUINT16(pBuffer, BLOP_REFERENCE_N_ENTRIES);
1072 for (sal_uInt16 i = 0; i < m_referenceCount; i++)
1074 pBuffer += writeUINT16(
1075 pBuffer,
1076 sal::static_int_cast< sal_uInt16 >(m_references[i].m_type));
1078 cpIndexName = 0;
1079 cpIndexDoku2 = 0;
1081 if (m_references[i].m_name.getLength())
1083 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
1084 pInfo->m_value.aUtf8 = m_references[i].m_name.getStr();
1085 cpIndexName = pInfo->m_index;
1087 pBuffer += writeUINT16(pBuffer, cpIndexName);
1089 if (m_references[i].m_doku.getLength())
1091 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
1092 pInfo->m_value.aUtf8 = m_references[i].m_doku.getStr();
1093 cpIndexDoku2 = pInfo->m_index;
1095 pBuffer += writeUINT16(pBuffer, cpIndexDoku2);
1097 pBuffer += writeUINT16(pBuffer, m_references[i].m_access);
1102 // get CP infos blop-length
1103 pInfo = root.m_next;
1104 sal_uInt32 cpBlopSize = 0;
1105 sal_uInt16 cpCount = 0;
1107 while (pInfo)
1109 cpBlopSize += pInfo->getBlopSize();
1110 cpCount++;
1111 pInfo = pInfo->m_next;
1114 blopSize += cpBlopSize;
1115 blopSize += sizeof(sal_uInt16); // constantPoolCount
1117 // write all in flat buffer
1119 sal_uInt8 * blop = new sal_uInt8[blopSize];
1121 pBuffer = blop;
1123 // Assumes two's complement arithmetic with modulo-semantics:
1124 pBuffer += writeUINT32(pBuffer, magic + m_version);
1125 pBuffer += writeUINT32(pBuffer, blopSize);
1126 pBuffer += writeUINT16(pBuffer, minorVersion);
1127 pBuffer += writeUINT16(pBuffer, majorVersion);
1128 pBuffer += writeUINT16(pBuffer, BLOP_HEADER_N_ENTRIES);
1130 pBuffer += writeUINT16(pBuffer, (sal_uInt16)RT_UNO_IDL);
1131 pBuffer += writeUINT16(pBuffer, (sal_uInt16)m_typeClass);
1132 pBuffer += writeUINT16(pBuffer, cpIndexThisName);
1133 pBuffer += writeUINT16(pBuffer, cpIndexUik);
1134 pBuffer += writeUINT16(pBuffer, cpIndexDoku);
1135 pBuffer += writeUINT16(pBuffer, cpIndexFileName);
1137 // write supertypes
1138 pBuffer += writeUINT16(pBuffer, m_nSuperTypes);
1139 if (m_nSuperTypes)
1141 for (sal_uInt32 i=0; i < m_nSuperTypes; i++)
1143 pBuffer += writeUINT16(pBuffer, cpIndexSuperNames[i]);
1145 delete[] cpIndexSuperNames;
1148 pBuffer += writeUINT16(pBuffer, cpCount);
1150 // write and delete CP infos
1151 pInfo = root.m_next;
1153 while (pInfo)
1155 CPInfo* pNextInfo = pInfo->m_next;
1157 pBuffer += pInfo->toBlop(pBuffer);
1158 delete pInfo;
1160 pInfo = pNextInfo;
1163 // write fields
1164 pBuffer += writeUINT16(pBuffer, m_fieldCount);
1165 if (blopFieldsSize)
1167 memcpy(pBuffer, pBlopFields, blopFieldsSize);
1168 pBuffer += blopFieldsSize;
1171 // write methods
1172 pBuffer += writeUINT16(pBuffer, m_methodCount);
1173 if (blopMethodsSize)
1175 memcpy(pBuffer, pBlopMethods, blopMethodsSize);
1176 pBuffer += blopMethodsSize;
1179 // write references
1180 pBuffer += writeUINT16(pBuffer, m_referenceCount);
1181 if (blopReferenceSize)
1183 memcpy(pBuffer, pBlopReferences, blopReferenceSize);
1184 pBuffer += blopReferenceSize;
1187 delete[] pBlopFields;
1188 delete[] pBlopMethods;
1189 delete[] pBlopReferences;
1191 delete[] m_blop;
1192 m_blop = blop;
1193 m_blopSize = blopSize;
1197 /**************************************************************************
1199 C-API
1201 **************************************************************************/
1203 extern "C" {
1205 static void TYPEREG_CALLTYPE acquire(TypeWriterImpl hEntry)
1207 TypeWriter* pEntry = (TypeWriter*) hEntry;
1209 if (pEntry != NULL)
1210 pEntry->m_refCount++;
1213 static void TYPEREG_CALLTYPE release(TypeWriterImpl hEntry)
1215 TypeWriter* pEntry = (TypeWriter*) hEntry;
1217 if (pEntry != NULL)
1219 if (--pEntry->m_refCount == 0)
1220 delete pEntry;
1224 static void TYPEREG_CALLTYPE setUik(TypeWriterImpl hEntry, const RTUik* uik)
1226 TypeWriter* pEntry = (TypeWriter*) hEntry;
1228 if (pEntry != NULL)
1230 if (pEntry->m_pUik)
1232 pEntry->m_pUik->m_Data1 = uik->m_Data1;
1233 pEntry->m_pUik->m_Data2 = uik->m_Data2;
1234 pEntry->m_pUik->m_Data3 = uik->m_Data3;
1235 pEntry->m_pUik->m_Data4 = uik->m_Data4;
1236 pEntry->m_pUik->m_Data5 = uik->m_Data5;
1238 else
1239 pEntry->m_pUik = new RTUik(*uik);
1243 static void TYPEREG_CALLTYPE setDoku(TypeWriterImpl hEntry, rtl_uString* doku)
1245 static_cast< TypeWriter * >(hEntry)->m_doku = toByteString(doku);
1248 static void TYPEREG_CALLTYPE setFileName(TypeWriterImpl hEntry, rtl_uString* fileName)
1250 static_cast< TypeWriter * >(hEntry)->m_fileName = toByteString(fileName);
1253 sal_Bool typereg_writer_setFieldData(
1254 void * handle, sal_uInt16 index, rtl_uString const * documentation,
1255 rtl_uString const * fileName, RTFieldAccess flags, rtl_uString const * name,
1256 rtl_uString const * typeName, RTValueType valueType,
1257 RTConstValueUnion valueValue)
1258 SAL_THROW_EXTERN_C()
1260 try {
1261 static_cast< TypeWriter * >(handle)->m_fields[index].setData(
1262 toByteString(name), toByteString(typeName),
1263 toByteString(documentation), toByteString(fileName), flags,
1264 valueType, valueValue);
1265 } catch (std::bad_alloc &) {
1266 return false;
1268 return true;
1271 static void TYPEREG_CALLTYPE setFieldData(TypeWriterImpl hEntry,
1272 sal_uInt16 index,
1273 rtl_uString* name,
1274 rtl_uString* typeName,
1275 rtl_uString* doku,
1276 rtl_uString* fileName,
1277 RTFieldAccess access,
1278 RTValueType valueType,
1279 RTConstValueUnion constValue)
1281 typereg_writer_setFieldData(
1282 hEntry, index, doku, fileName, access, name, typeName, valueType,
1283 constValue);
1286 sal_Bool typereg_writer_setMethodData(
1287 void * handle, sal_uInt16 index, rtl_uString const * documentation,
1288 RTMethodMode flags, rtl_uString const * name,
1289 rtl_uString const * returnTypeName, sal_uInt16 parameterCount,
1290 sal_uInt16 exceptionCount)
1291 SAL_THROW_EXTERN_C()
1293 try {
1294 static_cast< TypeWriter * >(handle)->m_methods[index].setData(
1295 toByteString(name), toByteString(returnTypeName), flags,
1296 parameterCount, exceptionCount, toByteString(documentation));
1297 } catch (std::bad_alloc &) {
1298 return false;
1300 return true;
1303 static void TYPEREG_CALLTYPE setMethodData(TypeWriterImpl hEntry,
1304 sal_uInt16 index,
1305 rtl_uString* name,
1306 rtl_uString* returnTypeName,
1307 RTMethodMode mode,
1308 sal_uInt16 paramCount,
1309 sal_uInt16 excCount,
1310 rtl_uString* doku)
1312 typereg_writer_setMethodData(
1313 hEntry, index, doku, mode, name, returnTypeName, paramCount, excCount);
1316 sal_Bool typereg_writer_setMethodParameterData(
1317 void * handle, sal_uInt16 methodIndex, sal_uInt16 parameterIndex,
1318 RTParamMode flags, rtl_uString const * name, rtl_uString const * typeName)
1319 SAL_THROW_EXTERN_C()
1321 try {
1322 static_cast< TypeWriter * >(handle)->
1323 m_methods[methodIndex].m_params[parameterIndex].setData(
1324 toByteString(typeName), toByteString(name), flags);
1325 } catch (std::bad_alloc &) {
1326 return false;
1328 return true;
1331 static void TYPEREG_CALLTYPE setParamData(TypeWriterImpl hEntry,
1332 sal_uInt16 index,
1333 sal_uInt16 paramIndex,
1334 rtl_uString* type,
1335 rtl_uString* name,
1336 RTParamMode mode)
1338 typereg_writer_setMethodParameterData(
1339 hEntry, index, paramIndex, mode, name, type);
1342 sal_Bool typereg_writer_setMethodExceptionTypeName(
1343 void * handle, sal_uInt16 methodIndex, sal_uInt16 exceptionIndex,
1344 rtl_uString const * typeName)
1345 SAL_THROW_EXTERN_C()
1347 try {
1348 static_cast< TypeWriter * >(handle)->m_methods[methodIndex].setExcName(
1349 exceptionIndex, toByteString(typeName));
1350 } catch (std::bad_alloc &) {
1351 return false;
1353 return true;
1356 static void TYPEREG_CALLTYPE setExcData(TypeWriterImpl hEntry,
1357 sal_uInt16 index,
1358 sal_uInt16 excIndex,
1359 rtl_uString* type)
1361 typereg_writer_setMethodExceptionTypeName(hEntry, index, excIndex, type);
1364 void const * typereg_writer_getBlob(void * handle, sal_uInt32 * size)
1365 SAL_THROW_EXTERN_C()
1367 TypeWriter * writer = static_cast< TypeWriter * >(handle);
1368 if (writer->m_blop == 0) {
1369 try {
1370 writer->createBlop();
1371 } catch (std::bad_alloc &) {
1372 return 0;
1375 *size = writer->m_blopSize;
1376 return writer->m_blop;
1379 static const sal_uInt8* TYPEREG_CALLTYPE getBlop(TypeWriterImpl hEntry)
1381 sal_uInt32 size;
1382 return static_cast< sal_uInt8 const * >(
1383 typereg_writer_getBlob(hEntry, &size));
1386 static sal_uInt32 TYPEREG_CALLTYPE getBlopSize(TypeWriterImpl hEntry)
1388 sal_uInt32 size;
1389 typereg_writer_getBlob(hEntry, &size);
1390 return size;
1393 sal_Bool typereg_writer_setReferenceData(
1394 void * handle, sal_uInt16 index, rtl_uString const * documentation,
1395 RTReferenceType sort, RTFieldAccess flags, rtl_uString const * typeName)
1396 SAL_THROW_EXTERN_C()
1398 try {
1399 static_cast< TypeWriter * >(handle)->m_references[index].setData(
1400 toByteString(typeName), sort, toByteString(documentation), flags);
1401 } catch (std::bad_alloc &) {
1402 return false;
1404 return true;
1407 static void TYPEREG_CALLTYPE setReferenceData(TypeWriterImpl hEntry,
1408 sal_uInt16 index,
1409 rtl_uString* name,
1410 RTReferenceType refType,
1411 rtl_uString* doku,
1412 RTFieldAccess access)
1414 typereg_writer_setReferenceData(hEntry, index, doku, refType, access, name);
1417 void * typereg_writer_create(
1418 typereg_Version version, rtl_uString const * documentation,
1419 rtl_uString const * fileName, RTTypeClass typeClass, sal_Bool published,
1420 rtl_uString const * typeName, sal_uInt16 superTypeCount,
1421 sal_uInt16 fieldCount, sal_uInt16 methodCount, sal_uInt16 referenceCount)
1422 SAL_THROW_EXTERN_C()
1424 try {
1425 return new TypeWriter(
1426 version, toByteString(documentation), toByteString(fileName),
1427 typeClass, published, toByteString(typeName), superTypeCount,
1428 fieldCount, methodCount, referenceCount);
1429 } catch (std::bad_alloc &) {
1430 return 0;
1434 void typereg_writer_destroy(void * handle) SAL_THROW_EXTERN_C() {
1435 delete static_cast< TypeWriter * >(handle);
1438 sal_Bool typereg_writer_setSuperTypeName(
1439 void * handle, sal_uInt16 index, rtl_uString const * typeName)
1440 SAL_THROW_EXTERN_C()
1442 try {
1443 static_cast< TypeWriter * >(handle)->setSuperType(
1444 index, toByteString(typeName));
1445 } catch (std::bad_alloc &) {
1446 return false;
1448 return true;
1451 static TypeWriterImpl TYPEREG_CALLTYPE createEntry(
1452 RTTypeClass typeClass, rtl_uString * typeName, rtl_uString * superTypeName,
1453 sal_uInt16 fieldCount, sal_uInt16 methodCount, sal_uInt16 referenceCount)
1455 rtl::OUString empty;
1456 sal_uInt16 superTypeCount = rtl_uString_getLength(superTypeName) == 0
1457 ? 0 : 1;
1458 TypeWriterImpl t = typereg_writer_create(
1459 TYPEREG_VERSION_0, empty.pData, empty.pData, typeClass, false, typeName,
1460 superTypeCount, fieldCount, methodCount, referenceCount);
1461 if (superTypeCount > 0) {
1462 typereg_writer_setSuperTypeName(t, 0, superTypeName);
1464 return t;
1467 RegistryTypeWriter_Api* TYPEREG_CALLTYPE initRegistryTypeWriter_Api(void)
1469 static RegistryTypeWriter_Api aApi= {0,0,0,0,0,0,0,0,0,0,0,0,0};
1470 if (!aApi.acquire)
1472 aApi.createEntry = &createEntry;
1473 aApi.acquire = &acquire;
1474 aApi.release = &release;
1475 aApi.setUik = &setUik;
1476 aApi.setDoku = &setDoku;
1477 aApi.setFileName = &setFileName;
1478 aApi.setFieldData = &setFieldData;
1479 aApi.setMethodData = &setMethodData;
1480 aApi.setParamData = &setParamData;
1481 aApi.setExcData = &setExcData;
1482 aApi.getBlop = &getBlop;
1483 aApi.getBlopSize = &getBlopSize;
1484 aApi.setReferenceData = &setReferenceData;
1486 return (&aApi);
1488 else
1490 return (&aApi);