LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/registry/source - reflwrit.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 430 581 74.0 %
Date: 2013-07-09 Functions: 34 51 66.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include <new>
      22             : #include <sal/types.h>
      23             : #include <sal/macros.h>
      24             : #include <osl/endian.h>
      25             : #include <rtl/alloc.h>
      26             : #include "rtl/string.hxx"
      27             : #include "rtl/ustring.hxx"
      28             : 
      29             : #include "registry/reflwrit.hxx"
      30             : #include "registry/version.h"
      31             : #include "registry/writer.h"
      32             : 
      33             : #include "reflcnst.hxx"
      34             : 
      35             : 
      36             : 
      37             : namespace {
      38             : 
      39      222819 : inline OString toByteString(rtl_uString const * str) {
      40             :     return OString(
      41             :         str->buffer, str->length, RTL_TEXTENCODING_UTF8,
      42      222819 :         OUSTRING_TO_OSTRING_CVTFLAGS);
      43             : }
      44             : 
      45             : }
      46             : 
      47             : static sal_Unicode NULL_WSTRING[1] = { 0 };
      48             : 
      49             : #define BLOP_OFFSET_MAGIC       0
      50             : #define BLOP_OFFSET_SIZE        (BLOP_OFFSET_MAGIC + sizeof(sal_uInt32))
      51             : #define BLOP_OFFSET_MINOR       (BLOP_OFFSET_SIZE + sizeof(sal_uInt32))
      52             : #define BLOP_OFFSET_MAJOR       (BLOP_OFFSET_MINOR + sizeof(sal_uInt16))
      53             : #define BLOP_OFFSET_N_ENTRIES   (BLOP_OFFSET_MAJOR + sizeof(sal_uInt16))
      54             : #define BLOP_HEADER_N_ENTRIES   6
      55             : 
      56             : #define BLOP_FIELD_N_ENTRIES        6
      57             : 
      58             : #define BLOP_METHOD_N_ENTRIES   5
      59             : 
      60             : #define BLOP_PARAM_N_ENTRIES    3
      61             : 
      62             : #define BLOP_REFERENCE_N_ENTRIES    4
      63             : 
      64           0 : sal_uInt32 UINT16StringLen(const sal_uInt8* wstring)
      65             : {
      66           0 :     if (!wstring) return 0;
      67             : 
      68           0 :     const sal_uInt8* b = wstring;
      69             : 
      70           0 :     while (b[0] || b[1]) b += sizeof(sal_uInt16);
      71             : 
      72           0 :     return ((b - wstring) / sizeof(sal_uInt16));
      73             : }
      74             : 
      75           0 : sal_uInt32 writeString(sal_uInt8* buffer, const sal_Unicode* v)
      76             : {
      77           0 :     sal_uInt32 len = rtl_ustr_getLength(v) + 1;
      78             :     sal_uInt32 i;
      79           0 :     sal_uInt8* buff = buffer;
      80             : 
      81           0 :     for (i = 0; i < len; i++)
      82             :     {
      83           0 :         buff += writeUINT16(buff, (sal_uInt16) v[i]);
      84             :     }
      85             : 
      86           0 :     return (buff - buffer);
      87             : }
      88             : 
      89           0 : sal_uInt32 readString(const sal_uInt8* buffer, sal_Unicode* v, sal_uInt32 maxSize)
      90             : {
      91           0 :     sal_uInt32 len = UINT16StringLen(buffer) + 1;
      92             :     sal_uInt32 i;
      93           0 :     sal_uInt8* buff = (sal_uInt8*)buffer;
      94             : 
      95           0 :     if(len > maxSize / 2)
      96             :     {
      97           0 :         len = maxSize / 2;
      98             :     }
      99             : 
     100           0 :     for (i = 0; i < (len - 1); i++)
     101             :     {
     102             :         sal_uInt16 aChar;
     103             : 
     104           0 :         buff += readUINT16(buff, aChar);
     105             : 
     106           0 :         v[i] = (sal_Unicode) aChar;
     107             :     }
     108             : 
     109           0 :     v[len - 1] = L'\0';
     110             : 
     111           0 :     return (buff - ((sal_uInt8*)buffer));
     112             : }
     113             : 
     114          21 : sal_uInt32 writeFloat(sal_uInt8* buffer, float v)
     115             : {
     116             :     union
     117             :     {
     118             :         float   v;
     119             :         sal_uInt32  b;
     120             :     } x;
     121             : 
     122          21 :     x.v = v;
     123             : 
     124             : #ifdef REGTYPE_IEEE_NATIVE
     125          21 :     writeUINT32(buffer, x.b);
     126             : #else
     127             : #   error no IEEE
     128             : #endif
     129             : 
     130          21 :     return sizeof(sal_uInt32);
     131             : }
     132             : 
     133           1 : sal_uInt32 writeDouble(sal_uInt8* buffer, double v)
     134             : {
     135             :     union
     136             :     {
     137             :         double v;
     138             :         struct
     139             :         {
     140             :             sal_uInt32  b1;
     141             :             sal_uInt32  b2;
     142             :         } b;
     143             :     } x;
     144             : 
     145           1 :     x.v = v;
     146             : 
     147             : #ifdef REGTYPE_IEEE_NATIVE
     148             : #   ifdef OSL_BIGENDIAN
     149             :     writeUINT32(buffer, x.b.b1);
     150             :     writeUINT32(buffer + sizeof(sal_uInt32), x.b.b2);
     151             : #   else
     152           1 :     writeUINT32(buffer, x.b.b2);
     153           1 :     writeUINT32(buffer + sizeof(sal_uInt32), x.b.b1);
     154             : #   endif
     155             : #else
     156             : #   error no IEEE
     157             : #endif
     158             : 
     159           1 :     return (sizeof(sal_uInt32) + sizeof(sal_uInt32));
     160             : }
     161             : 
     162             : /**************************************************************************
     163             : 
     164             :     buffer write functions
     165             : 
     166             : **************************************************************************/
     167             : 
     168             : 
     169             : /**************************************************************************
     170             : 
     171             :     struct CPInfo
     172             : 
     173             : **************************************************************************/
     174             : 
     175             : struct CPInfo
     176             : {
     177             :     CPInfoTag   m_tag;
     178             :     union
     179             :     {
     180             :         const sal_Char*     aUtf8;
     181             :         RTUik*              aUik;
     182             :         RTConstValueUnion   aConst;
     183             :     } m_value;
     184             : 
     185             :     sal_uInt16      m_index;
     186             :     struct CPInfo*  m_next;
     187             : 
     188             :     CPInfo(CPInfoTag tag, struct CPInfo* prev);
     189             : 
     190             :     sal_uInt32 getBlopSize();
     191             : 
     192             :     sal_uInt32 toBlop(sal_uInt8* buffer);
     193             : };
     194             : 
     195      154165 : CPInfo::CPInfo(CPInfoTag tag, struct CPInfo* prev)
     196             :     : m_tag(tag)
     197             :     , m_index(0)
     198      154165 :     , m_next(NULL)
     199             : {
     200      154165 :     if (prev)
     201             :     {
     202      121638 :         m_index = prev->m_index + 1;
     203      121638 :         prev->m_next = this;
     204             :     }
     205      154165 : }
     206             : 
     207      243276 : sal_uInt32 CPInfo::getBlopSize()
     208             : {
     209      243276 :     sal_uInt32 size = sizeof(sal_uInt32) /* size */ + sizeof(sal_uInt16) /* tag */;
     210             : 
     211      243276 :     switch (m_tag)
     212             :     {
     213             :         case CP_TAG_CONST_BOOL:
     214           2 :             size += sizeof(sal_uInt8);
     215           2 :             break;
     216             :         case CP_TAG_CONST_BYTE:
     217         510 :             size += sizeof(sal_uInt8);
     218         510 :             break;
     219             :         case CP_TAG_CONST_INT16:
     220        4106 :             size += sizeof(sal_Int16);
     221        4106 :             break;
     222             :         case CP_TAG_CONST_UINT16:
     223          16 :             size += sizeof(sal_uInt16);
     224          16 :             break;
     225             :         case CP_TAG_CONST_INT32:
     226       21640 :             size += sizeof(sal_Int32);
     227       21640 :             break;
     228             :         case CP_TAG_CONST_UINT32:
     229          16 :             size += sizeof(sal_uInt32);
     230          16 :             break;
     231             :         case CP_TAG_CONST_INT64:
     232          76 :               size += sizeof(sal_Int64);
     233          76 :             break;
     234             :         case CP_TAG_CONST_UINT64:
     235          16 :             size += sizeof(sal_uInt64);
     236          16 :             break;
     237             :         case CP_TAG_CONST_FLOAT:
     238          42 :             size += sizeof(sal_uInt32);
     239          42 :             break;
     240             :         case CP_TAG_CONST_DOUBLE:
     241           2 :             size += sizeof(sal_uInt32) + sizeof(sal_uInt32);
     242           2 :             break;
     243             :         case CP_TAG_CONST_STRING:
     244           0 :             size += (rtl_ustr_getLength(m_value.aConst.aString) + 1) * sizeof(sal_uInt16);
     245           0 :             break;
     246             :         case CP_TAG_UTF8_NAME:
     247      216850 :             size += strlen(m_value.aUtf8) + 1;
     248      216850 :             break;
     249             :         case CP_TAG_UIK:
     250           0 :             size += sizeof(sal_uInt32) + sizeof(sal_uInt16) + sizeof(sal_uInt16) + sizeof(sal_uInt32) + sizeof(sal_uInt32);
     251           0 :             break;
     252             :         default:
     253           0 :             break;
     254             :     }
     255             : 
     256      243276 :     return size;
     257             : }
     258             : 
     259             : 
     260      121638 : sal_uInt32 CPInfo::toBlop(sal_uInt8* buffer)
     261             : {
     262      121638 :     sal_uInt8* buff = buffer;
     263             : 
     264      121638 :     buff += writeUINT32(buff, getBlopSize());
     265      121638 :     buff += writeUINT16(buff, (sal_uInt16) m_tag);
     266             : 
     267      121638 :     switch (m_tag)
     268             :     {
     269             :         case CP_TAG_CONST_BOOL:
     270           1 :             buff += writeBYTE(buff, (sal_uInt8) m_value.aConst.aBool);
     271           1 :             break;
     272             :         case CP_TAG_CONST_BYTE:
     273             :             buff += writeBYTE(
     274         255 :                 buff, static_cast< sal_uInt8 >(m_value.aConst.aByte));
     275         255 :             break;
     276             :         case CP_TAG_CONST_INT16:
     277        2053 :             buff += writeINT16(buff, m_value.aConst.aShort);
     278        2053 :             break;
     279             :         case CP_TAG_CONST_UINT16:
     280           8 :             buff += writeINT16(buff, m_value.aConst.aUShort);
     281           8 :             break;
     282             :         case CP_TAG_CONST_INT32:
     283       10820 :             buff += writeINT32(buff, m_value.aConst.aLong);
     284       10820 :             break;
     285             :         case CP_TAG_CONST_UINT32:
     286           8 :             buff += writeUINT32(buff, m_value.aConst.aULong);
     287           8 :             break;
     288             :         case CP_TAG_CONST_INT64:
     289          38 :             buff += writeUINT64(buff, m_value.aConst.aHyper);
     290          38 :             break;
     291             :         case CP_TAG_CONST_UINT64:
     292           8 :             buff += writeUINT64(buff, m_value.aConst.aUHyper);
     293           8 :             break;
     294             :         case CP_TAG_CONST_FLOAT:
     295          21 :             buff += writeFloat(buff, m_value.aConst.aFloat);
     296          21 :             break;
     297             :         case CP_TAG_CONST_DOUBLE:
     298           1 :             buff += writeDouble(buff, m_value.aConst.aDouble);
     299           1 :             break;
     300             :         case CP_TAG_CONST_STRING:
     301           0 :             buff += writeString(buff, m_value.aConst.aString);
     302           0 :             break;
     303             :         case CP_TAG_UTF8_NAME:
     304      108425 :             buff += writeUtf8(buff, m_value.aUtf8);
     305      108425 :             break;
     306             :         case CP_TAG_UIK:
     307           0 :             buff += writeUINT32(buff, m_value.aUik->m_Data1);
     308           0 :             buff += writeUINT16(buff, m_value.aUik->m_Data2);
     309           0 :             buff += writeUINT16(buff, m_value.aUik->m_Data3);
     310           0 :             buff += writeUINT32(buff, m_value.aUik->m_Data4);
     311           0 :             buff += writeUINT32(buff, m_value.aUik->m_Data5);
     312           0 :             break;
     313             :         default:
     314           0 :             break;
     315             :     }
     316             : 
     317      121638 :     return (buff - buffer);
     318             : }
     319             : 
     320             : 
     321             : /**************************************************************************
     322             : 
     323             :     class FieldEntry
     324             : 
     325             : **************************************************************************/
     326             : 
     327             : class FieldEntry
     328             : {
     329             : 
     330             : public:
     331             : 
     332             :     OString           m_name;
     333             :     OString           m_typeName;
     334             :     OString           m_doku;
     335             :     OString           m_fileName;
     336             :     RTFieldAccess     m_access;
     337             :     RTValueType       m_constValueType;
     338             :     RTConstValueUnion m_constValue;
     339             : 
     340             :     FieldEntry();
     341             :     ~FieldEntry();
     342             : 
     343             :     void setData(const OString&    name,
     344             :                  const OString&    typeName,
     345             :                  const OString&    doku,
     346             :                  const OString&    fileName,
     347             :                  RTFieldAccess     access,
     348             :                  RTValueType       constValueType,
     349             :                  RTConstValueUnion constValue);
     350             :         // throws std::bad_alloc
     351             : };
     352             : 
     353       19212 : FieldEntry::FieldEntry()
     354             :     : m_access(RT_ACCESS_INVALID)
     355       19212 :     , m_constValueType(RT_TYPE_NONE)
     356             : {
     357       19212 : }
     358             : 
     359       38424 : FieldEntry::~FieldEntry()
     360             : {
     361       19212 :     if (
     362       19212 :         (m_constValueType == RT_TYPE_STRING) &&
     363           0 :         m_constValue.aString &&
     364           0 :         (m_constValue.aString != NULL_WSTRING)
     365             :        )
     366             :     {
     367           0 :         delete[] (sal_Unicode*)m_constValue.aString;
     368             :     }
     369       19212 : }
     370             : 
     371       19212 : void FieldEntry::setData(const OString&    name,
     372             :                          const OString&    typeName,
     373             :                          const OString&    doku,
     374             :                          const OString&    fileName,
     375             :                          RTFieldAccess      access,
     376             :                          RTValueType        constValueType,
     377             :                          RTConstValueUnion  constValue)
     378             : {
     379       19212 :     sal_Unicode * newValue = 0;
     380       19212 :     if (constValueType == RT_TYPE_STRING && constValue.aString != 0) {
     381           0 :         sal_Int32 n = rtl_ustr_getLength(constValue.aString) + 1;
     382           0 :         newValue = new sal_Unicode[n];
     383           0 :         memcpy(newValue, constValue.aString, n * sizeof (sal_Unicode));
     384             :     }
     385             : 
     386       19212 :     m_name = name;
     387       19212 :     m_typeName = typeName;
     388       19212 :     m_doku = doku;
     389       19212 :     m_fileName = fileName;
     390             : 
     391       19212 :     if (
     392       19212 :         (m_constValueType == RT_TYPE_STRING) &&
     393           0 :         m_constValue.aString &&
     394           0 :         (m_constValue.aString != NULL_WSTRING)
     395             :        )
     396             :     {
     397           0 :         delete[] (sal_Unicode*)m_constValue.aString;
     398             :     }
     399             : 
     400       19212 :     m_access = access;
     401       19212 :     m_constValueType = constValueType;
     402             : 
     403       19212 :     if (m_constValueType == RT_TYPE_STRING)
     404             :     {
     405           0 :         if (constValue.aString == NULL)
     406           0 :             m_constValue.aString = NULL_WSTRING;
     407             :         else
     408             :         {
     409           0 :             m_constValue.aString = newValue;
     410             :         }
     411             :     }
     412             :     else
     413             :     {
     414       19212 :         m_constValue = constValue;
     415             :     }
     416       19212 : }
     417             : 
     418             : /**************************************************************************
     419             : 
     420             :     class ParamEntry
     421             : 
     422             : **************************************************************************/
     423             : 
     424             : class ParamEntry
     425             : {
     426             : public:
     427             : 
     428             :     OString     m_typeName;
     429             :     OString     m_name;
     430             :     RTParamMode m_mode;
     431             : 
     432             :     ParamEntry();
     433             :     ~ParamEntry();
     434             : 
     435             :     void setData(const OString& typeName,
     436             :                  const OString& name,
     437             :                  RTParamMode    mode);
     438             : };
     439             : 
     440        7555 : ParamEntry::ParamEntry()
     441        7555 :     : m_mode(RT_PARAM_INVALID)
     442             : {
     443        7555 : }
     444             : 
     445        7555 : ParamEntry::~ParamEntry()
     446             : {
     447        7555 : }
     448             : 
     449        7555 : void ParamEntry::setData(const OString& typeName,
     450             :                          const OString& name,
     451             :                          RTParamMode    mode)
     452             : {
     453        7555 :     m_name = name;
     454        7555 :     m_typeName = typeName;
     455        7555 :     m_mode = mode;
     456        7555 : }
     457             : 
     458             : /**************************************************************************
     459             : 
     460             :     class ReferenceEntry
     461             : 
     462             : **************************************************************************/
     463             : 
     464             : class ReferenceEntry
     465             : {
     466             : public:
     467             : 
     468             :     OString         m_name;
     469             :     OString         m_doku;
     470             :     RTReferenceType m_type;
     471             :     RTFieldAccess   m_access;
     472             : 
     473             :     ReferenceEntry();
     474             :     ~ReferenceEntry();
     475             : 
     476             :     void setData(const OString&     name,
     477             :                  RTReferenceType    refType,
     478             :                  const OString&     doku,
     479             :                  RTFieldAccess      access);
     480             : };
     481             : 
     482        2722 : ReferenceEntry::ReferenceEntry()
     483             :     : m_type(RT_REF_INVALID)
     484        2722 :     , m_access(RT_ACCESS_INVALID)
     485             : {
     486        2722 : }
     487             : 
     488        2722 : ReferenceEntry::~ReferenceEntry()
     489             : {
     490        2722 : }
     491             : 
     492        2722 : void ReferenceEntry::setData(const OString&    name,
     493             :                              RTReferenceType   refType,
     494             :                              const OString&    doku,
     495             :                              RTFieldAccess     access)
     496             : {
     497        2722 :     m_name = name;
     498        2722 :     m_doku = doku;
     499        2722 :     m_type = refType;
     500        2722 :     m_access = access;
     501        2722 : }
     502             : 
     503             : /**************************************************************************
     504             : 
     505             :     class MethodEntry
     506             : 
     507             : **************************************************************************/
     508             : 
     509             : class MethodEntry
     510             : {
     511             : public:
     512             : 
     513             :     OString         m_name;
     514             :     OString         m_returnTypeName;
     515             :     RTMethodMode    m_mode;
     516             :     sal_uInt16      m_paramCount;
     517             :     ParamEntry*     m_params;
     518             :     sal_uInt16      m_excCount;
     519             :     OString*        m_excNames;
     520             :     OString         m_doku;
     521             : 
     522             :     MethodEntry();
     523             :     ~MethodEntry();
     524             : 
     525             :     void setData(const OString&    name,
     526             :                  const OString&    returnTypeName,
     527             :                  RTMethodMode      mode,
     528             :                  sal_uInt16        paramCount,
     529             :                  sal_uInt16        excCount,
     530             :                  const OString&    doku);
     531             : 
     532             :     void setExcName(sal_uInt16 excIndex, const OString& name);
     533             : 
     534             : protected:
     535             : 
     536             :     void reallocParams(sal_uInt16 size);
     537             :     void reallocExcs(sal_uInt16 size);
     538             : };
     539             : 
     540        7073 : MethodEntry::MethodEntry()
     541             :     : m_mode(RT_MODE_INVALID)
     542             :     , m_paramCount(0)
     543             :     , m_params(NULL)
     544             :     , m_excCount(0)
     545        7073 :     , m_excNames(NULL)
     546             : {
     547        7073 : }
     548             : 
     549       14146 : MethodEntry::~MethodEntry()
     550             : {
     551        7073 :     if (m_params)
     552        4297 :         delete[] m_params;
     553             : 
     554        7073 :     if (m_excNames)
     555        2375 :         delete[] m_excNames;
     556        7073 : }
     557             : 
     558        7073 : void MethodEntry::setData(const OString&    name,
     559             :                           const OString&    returnTypeName,
     560             :                           RTMethodMode      mode,
     561             :                           sal_uInt16        paramCount,
     562             :                           sal_uInt16        excCount,
     563             :                           const OString&    doku)
     564             : {
     565        7073 :     m_name = name;
     566        7073 :     m_returnTypeName = returnTypeName;
     567        7073 :     m_doku = doku;
     568             : 
     569        7073 :     m_mode = mode;
     570             : 
     571        7073 :     reallocParams(paramCount);
     572        7073 :     reallocExcs(excCount);
     573        7073 : }
     574             : 
     575        3226 : void MethodEntry::setExcName(sal_uInt16 excIndex, const OString& name)
     576             : {
     577        3226 :     if (excIndex < m_excCount)
     578             :     {
     579        3226 :         m_excNames[excIndex] = name;
     580             :     }
     581        3226 : }
     582             : 
     583        7073 : void MethodEntry::reallocParams(sal_uInt16 size)
     584             : {
     585             :     ParamEntry* newParams;
     586             : 
     587        7073 :     if (size)
     588        4297 :         newParams = new ParamEntry[size];
     589             :     else
     590        2776 :         newParams = NULL;
     591             : 
     592        7073 :     if (m_paramCount)
     593             :     {
     594             :         sal_uInt16 i;
     595           0 :         sal_uInt16 mn = size < m_paramCount ? size : m_paramCount;
     596             : 
     597           0 :         for (i = 0; i < mn; i++)
     598             :         {
     599           0 :             newParams[i].setData(m_params[i].m_typeName, m_params[i].m_name, m_params[i].m_mode);
     600             :         }
     601             : 
     602           0 :         delete[] m_params;
     603             :     }
     604             : 
     605        7073 :     m_paramCount = size;
     606        7073 :     m_params = newParams;
     607        7073 : }
     608             : 
     609        7073 : void MethodEntry::reallocExcs(sal_uInt16 size)
     610             : {
     611             :     OString* newExcNames;
     612             : 
     613        7073 :     if (size)
     614        2375 :         newExcNames = new OString[size];
     615             :     else
     616        4698 :         newExcNames = NULL;
     617             : 
     618             :     sal_uInt16 i;
     619        7073 :     sal_uInt16 mn = size < m_excCount ? size : m_excCount;
     620             : 
     621        7073 :     for (i = 0; i < mn; i++)
     622             :     {
     623           0 :         newExcNames[i] = m_excNames[i];
     624             :     }
     625             : 
     626        7073 :     delete[] m_excNames;
     627             : 
     628        7073 :     m_excCount = size;
     629        7073 :     m_excNames = newExcNames;
     630        7073 : }
     631             : 
     632             : 
     633             : /**************************************************************************
     634             : 
     635             :     class TypeRegistryEntry
     636             : 
     637             : **************************************************************************/
     638             : 
     639             : class TypeWriter
     640             : {
     641             : 
     642             : public:
     643             : 
     644             :     sal_uInt32          m_refCount;
     645             :     typereg_Version     m_version;
     646             :     RTTypeClass         m_typeClass;
     647             :     OString             m_typeName;
     648             :     sal_uInt16          m_nSuperTypes;
     649             :     OString*            m_superTypeNames;
     650             :     RTUik*              m_pUik;
     651             :     OString             m_doku;
     652             :     OString             m_fileName;
     653             :     sal_uInt16          m_fieldCount;
     654             :     FieldEntry*         m_fields;
     655             :     sal_uInt16          m_methodCount;
     656             :     MethodEntry*        m_methods;
     657             :     sal_uInt16          m_referenceCount;
     658             :     ReferenceEntry*     m_references;
     659             : 
     660             :     sal_uInt8*          m_blop;
     661             :     sal_uInt32          m_blopSize;
     662             : 
     663             :     TypeWriter(typereg_Version version,
     664             :                OString const & documentation,
     665             :                OString const & fileName,
     666             :                RTTypeClass      RTTypeClass,
     667             :                bool             published,
     668             :                const OString&   typeName,
     669             :                sal_uInt16       superTypeCount,
     670             :                sal_uInt16       FieldCount,
     671             :                sal_uInt16       methodCount,
     672             :                sal_uInt16       referenceCount);
     673             : 
     674             :     ~TypeWriter();
     675             : 
     676             :     void setSuperType(sal_uInt16 index, OString const & name);
     677             : 
     678             :     void createBlop(); // throws std::bad_alloc
     679             : };
     680             : 
     681       32527 : TypeWriter::TypeWriter(typereg_Version version,
     682             :                        OString const & documentation,
     683             :                        OString const & fileName,
     684             :                        RTTypeClass      RTTypeClass,
     685             :                        bool             published,
     686             :                        const OString&   typeName,
     687             :                        sal_uInt16       superTypeCount,
     688             :                        sal_uInt16       fieldCount,
     689             :                        sal_uInt16       methodCount,
     690             :                        sal_uInt16       referenceCount)
     691             :     : m_refCount(1)
     692             :     , m_version(version)
     693             :     , m_typeClass(
     694             :         static_cast< enum RTTypeClass >(
     695       32527 :             RTTypeClass | (published ? RT_TYPE_PUBLISHED : 0)))
     696             :      , m_typeName(typeName)
     697             :     , m_nSuperTypes(superTypeCount)
     698             :     , m_pUik(NULL)
     699             :     , m_doku(documentation)
     700             :     , m_fileName(fileName)
     701             :     , m_fieldCount(fieldCount)
     702             :     , m_methodCount(methodCount)
     703             :     , m_referenceCount(referenceCount)
     704             :     , m_blop(NULL)
     705       65054 :     , m_blopSize(0)
     706             : {
     707       32527 :     if (m_nSuperTypes > 0)
     708             :     {
     709        3138 :         m_superTypeNames = new OString[m_nSuperTypes];
     710             :     } else
     711             :     {
     712       29389 :         m_superTypeNames = NULL;
     713             :     }
     714             : 
     715       32527 :     if (m_fieldCount)
     716        2647 :         m_fields = new FieldEntry[fieldCount];
     717             : 
     718       32527 :     if (m_methodCount)
     719        2200 :         m_methods = new MethodEntry[methodCount];
     720             : 
     721       32527 :     if (m_referenceCount)
     722        1027 :         m_references = new ReferenceEntry[referenceCount];
     723       32527 : }
     724             : 
     725       65054 : TypeWriter::~TypeWriter()
     726             : {
     727       32527 :     if (m_superTypeNames)
     728        3138 :         delete[] m_superTypeNames;
     729             : 
     730       32527 :     if (m_blop)
     731       32527 :         delete[] m_blop;
     732             : 
     733       32527 :     if (m_fieldCount)
     734        2647 :         delete[] m_fields;
     735             : 
     736       32527 :     if (m_methodCount)
     737        2200 :         delete[] m_methods;
     738             : 
     739       32527 :     if (m_referenceCount)
     740        1027 :         delete[] m_references;
     741             : 
     742       32527 :     if (m_pUik)
     743           0 :         delete m_pUik;
     744       32527 : }
     745             : 
     746        3391 : void TypeWriter::setSuperType(sal_uInt16 index, OString const & name)
     747             : {
     748        3391 :     m_superTypeNames[index] = name;
     749        3391 : }
     750             : 
     751       32527 : void TypeWriter::createBlop()
     752             : {
     753             :     //TODO: Fix memory leaks that occur when std::bad_alloc is thrown
     754             : 
     755       32527 :     sal_uInt8*  pBlopFields         = NULL;
     756       32527 :     sal_uInt8*  pBlopMethods        = NULL;
     757       32527 :     sal_uInt8*  pBlopReferences     = NULL;
     758       32527 :     sal_uInt8*  pBuffer             = NULL;
     759       32527 :     sal_uInt32  blopFieldsSize      = 0;
     760       32527 :     sal_uInt32  blopMethodsSize     = 0;
     761       32527 :     sal_uInt32  blopReferenceSize   = 0;
     762             : 
     763       32527 :     CPInfo  root(CP_TAG_INVALID, NULL);
     764       32527 :     sal_uInt16  cpIndexThisName = 0;
     765       32527 :     sal_uInt16* cpIndexSuperNames = NULL;
     766       32527 :     sal_uInt16  cpIndexUik = 0;
     767       32527 :     sal_uInt16  cpIndexDoku = 0;
     768       32527 :     sal_uInt16  cpIndexFileName = 0;
     769       32527 :     CPInfo* pInfo = NULL;
     770             : 
     771       32527 :     sal_uInt16  entrySize = sizeof(sal_uInt16);
     772       32527 :     sal_uInt32  blopHeaderEntrySize = BLOP_OFFSET_N_ENTRIES + entrySize + (BLOP_HEADER_N_ENTRIES * entrySize);
     773       32527 :     sal_uInt32  blopFieldEntrySize = BLOP_FIELD_N_ENTRIES * entrySize;
     774       32527 :     sal_uInt32  blopMethodEntrySize = BLOP_METHOD_N_ENTRIES * entrySize;
     775       32527 :     sal_uInt32  blopParamEntrySize = BLOP_PARAM_N_ENTRIES * entrySize;
     776       32527 :     sal_uInt32  blopReferenceEntrySize = BLOP_REFERENCE_N_ENTRIES * entrySize;
     777             : 
     778       32527 :     sal_uInt32 blopSize = blopHeaderEntrySize;
     779             : 
     780             :     // create CP entry for this name
     781       32527 :     pInfo = new CPInfo(CP_TAG_UTF8_NAME, &root);
     782       32527 :     pInfo->m_value.aUtf8 = m_typeName.getStr();
     783       32527 :     cpIndexThisName = pInfo->m_index;
     784             : 
     785             :     // nSuperTypes
     786       32527 :     blopSize += entrySize;
     787             : 
     788             :     // create CP entry for super names
     789       32527 :     if (m_nSuperTypes)
     790             :     {
     791        3138 :         blopSize += m_nSuperTypes * entrySize;
     792             : 
     793        3138 :         cpIndexSuperNames = new sal_uInt16[m_nSuperTypes];
     794             : 
     795        6529 :         for (sal_uInt32 i=0; i < m_nSuperTypes; i++)
     796             :         {
     797        3391 :             pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
     798        3391 :             pInfo->m_value.aUtf8 = m_superTypeNames[i].getStr();
     799        3391 :             cpIndexSuperNames[i] = pInfo->m_index;
     800             :         }
     801             :     }
     802             : 
     803             :     // create CP entry for uik
     804       32527 :     if (m_pUik != NULL)
     805             :     {
     806           0 :         pInfo = new CPInfo(CP_TAG_UIK, pInfo);
     807           0 :         pInfo->m_value.aUik = m_pUik;
     808           0 :         cpIndexUik = pInfo->m_index;
     809             :     }
     810             : 
     811             :     // create CP entry for doku
     812       32527 :     if (!m_doku.isEmpty())
     813             :     {
     814         184 :         pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
     815         184 :         pInfo->m_value.aUtf8 = m_doku.getStr();
     816         184 :         cpIndexDoku = pInfo->m_index;
     817             :     }
     818             : 
     819             :     // create CP entry for idl source filename
     820       32527 :     if (!m_fileName.isEmpty())
     821             :     {
     822           0 :         pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
     823           0 :         pInfo->m_value.aUtf8 = m_fileName.getStr();
     824           0 :         cpIndexFileName = pInfo->m_index;
     825             :     }
     826             : 
     827             :     // fields blop
     828       32527 :     blopSize += sizeof(sal_uInt16); // fieldCount + nFieldEntries
     829             : 
     830       32527 :     if (m_fieldCount)
     831             :     {
     832        2647 :         sal_uInt16 cpIndexName = 0;
     833        2647 :         sal_uInt16 cpIndexTypeName = 0;
     834        2647 :         sal_uInt16 cpIndexValue = 0;
     835        2647 :         sal_uInt16 cpIndexDoku2 = 0;
     836        2647 :         sal_uInt16 cpIndexFileName2 = 0;
     837             : 
     838             :         // nFieldEntries + n fields
     839        2647 :         blopFieldsSize = sizeof(sal_uInt16) + (m_fieldCount * blopFieldEntrySize);
     840             : 
     841        2647 :         blopSize += blopFieldsSize;
     842             : 
     843        2647 :         pBlopFields = new sal_uInt8[blopFieldsSize];
     844        2647 :         pBuffer = pBlopFields;
     845             : 
     846        2647 :         pBuffer += writeUINT16(pBuffer, BLOP_FIELD_N_ENTRIES);
     847             : 
     848       21859 :         for (sal_uInt16 i = 0; i < m_fieldCount; i++)
     849             :         {
     850       19212 :             cpIndexName = 0;
     851       19212 :             cpIndexTypeName = 0;
     852       19212 :             cpIndexValue = 0;
     853       19212 :             cpIndexDoku2 = 0;
     854       19212 :             cpIndexFileName2 = 0;
     855             : 
     856       19212 :             pBuffer += writeUINT16(pBuffer, m_fields[i].m_access);
     857             : 
     858       19212 :             if (!m_fields[i].m_name.isEmpty())
     859             :             {
     860       19212 :                 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
     861       19212 :                 pInfo->m_value.aUtf8 = m_fields[i].m_name.getStr();
     862       19212 :                 cpIndexName = pInfo->m_index;
     863             :             }
     864       19212 :             pBuffer += writeUINT16(pBuffer, cpIndexName);
     865             : 
     866       19212 :             if (!m_fields[i].m_typeName.isEmpty())
     867             :             {
     868       17864 :                 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
     869       17864 :                 pInfo->m_value.aUtf8 = m_fields[i].m_typeName.getStr();
     870       17864 :                 cpIndexTypeName = pInfo->m_index;
     871             :             }
     872       19212 :             pBuffer += writeUINT16(pBuffer, cpIndexTypeName);
     873             : 
     874       19212 :             if (m_fields[i].m_constValueType != RT_TYPE_NONE)
     875             :             {
     876       13213 :                 pInfo = new CPInfo((CPInfoTag)m_fields[i].m_constValueType, pInfo);
     877       13213 :                 pInfo->m_value.aConst = m_fields[i].m_constValue;
     878       13213 :                 cpIndexValue = pInfo->m_index;
     879             :             }
     880       19212 :             pBuffer += writeUINT16(pBuffer, cpIndexValue);
     881             : 
     882       19212 :             if (!m_fields[i].m_doku.isEmpty())
     883             :             {
     884          38 :                 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
     885          38 :                 pInfo->m_value.aUtf8 = m_fields[i].m_doku.getStr();
     886          38 :                 cpIndexDoku2 = pInfo->m_index;
     887             :             }
     888       19212 :             pBuffer += writeUINT16(pBuffer, cpIndexDoku2);
     889             : 
     890       19212 :             if (!m_fields[i].m_fileName.isEmpty())
     891             :             {
     892           0 :                 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
     893           0 :                 pInfo->m_value.aUtf8 = m_fields[i].m_fileName.getStr();
     894           0 :                 cpIndexFileName2 = pInfo->m_index;
     895             :             }
     896       19212 :             pBuffer += writeUINT16(pBuffer, cpIndexFileName2);
     897             :         }
     898             :     }
     899             : 
     900             :     // methods blop
     901       32527 :     blopSize += sizeof(sal_uInt16); // methodCount
     902             : 
     903       32527 :     if (m_methodCount)
     904             :     {
     905        2200 :         sal_uInt16* pMethodEntrySize = new sal_uInt16[m_methodCount];
     906        2200 :         sal_uInt16  cpIndexName = 0;
     907        2200 :         sal_uInt16  cpIndexReturn = 0;
     908        2200 :         sal_uInt16  cpIndexDoku2 = 0;
     909             : 
     910             :         // nMethodEntries + nParamEntries
     911        2200 :         blopMethodsSize = (2 * sizeof(sal_uInt16));
     912             : 
     913        9273 :         for (sal_uInt16 i = 0; i < m_methodCount; i++)
     914             :         {
     915        7073 :             pMethodEntrySize[i] = (sal_uInt16)
     916             :                 ( blopMethodEntrySize +                                 // header
     917             :                   sizeof(sal_uInt16) +                                  // parameterCount
     918        7073 :                   (m_methods[i].m_paramCount * blopParamEntrySize) +    // exceptions
     919             :                   sizeof(sal_uInt16) +                                  // exceptionCount
     920        7073 :                   (m_methods[i].m_excCount * sizeof(sal_uInt16)) );     // exceptions
     921             : 
     922        7073 :             blopMethodsSize += pMethodEntrySize[i];
     923             :         }
     924             : 
     925        2200 :         pBlopMethods = new sal_uInt8[blopMethodsSize];
     926             : 
     927        2200 :         blopSize += blopMethodsSize;
     928             : 
     929        2200 :         pBuffer = pBlopMethods;
     930             : 
     931        2200 :         pBuffer += writeUINT16(pBuffer, BLOP_METHOD_N_ENTRIES);
     932        2200 :         pBuffer += writeUINT16(pBuffer, BLOP_PARAM_N_ENTRIES );
     933             : 
     934        9273 :         for (sal_uInt16 i = 0; i < m_methodCount; i++)
     935             :         {
     936        7073 :             cpIndexReturn = 0;
     937        7073 :             cpIndexDoku2 = 0;
     938             : 
     939        7073 :             pBuffer += writeUINT16(pBuffer, pMethodEntrySize[i]);
     940             :             pBuffer += writeUINT16(
     941             :                 pBuffer,
     942        7073 :                 sal::static_int_cast< sal_uInt16 >(m_methods[i].m_mode));
     943             : 
     944        7073 :             if (!m_methods[i].m_name.isEmpty())
     945             :             {
     946        6836 :                 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
     947        6836 :                 pInfo->m_value.aUtf8 = m_methods[i].m_name.getStr();
     948        6836 :                 cpIndexName = pInfo->m_index;
     949             :             }
     950        7073 :             pBuffer += writeUINT16(pBuffer, cpIndexName);
     951        7073 :             cpIndexName = 0;
     952             : 
     953        7073 :             if (!m_methods[i].m_returnTypeName.isEmpty())
     954             :             {
     955        7073 :                 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
     956        7073 :                 pInfo->m_value.aUtf8 = m_methods[i].m_returnTypeName.getStr();
     957        7073 :                 cpIndexReturn = pInfo->m_index;
     958             :             }
     959        7073 :             pBuffer += writeUINT16(pBuffer, cpIndexReturn);
     960             : 
     961        7073 :             if (!m_methods[i].m_doku.isEmpty())
     962             :             {
     963         223 :                 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
     964         223 :                 pInfo->m_value.aUtf8 = m_methods[i].m_doku.getStr();
     965         223 :                 cpIndexDoku2 = pInfo->m_index;
     966             :             }
     967        7073 :             pBuffer += writeUINT16(pBuffer, cpIndexDoku2);
     968             : 
     969             :             sal_uInt16 j;
     970             : 
     971        7073 :             pBuffer += writeUINT16(pBuffer, m_methods[i].m_paramCount);
     972             : 
     973       14628 :             for (j = 0; j < m_methods[i].m_paramCount; j++)
     974             :             {
     975        7555 :                 if (!m_methods[i].m_params[j].m_typeName.isEmpty())
     976             :                 {
     977        7555 :                     pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
     978        7555 :                     pInfo->m_value.aUtf8 = m_methods[i].m_params[j].m_typeName.getStr();
     979        7555 :                     cpIndexName = pInfo->m_index;
     980             :                 }
     981        7555 :                 pBuffer += writeUINT16(pBuffer, cpIndexName);
     982        7555 :                 cpIndexName = 0;
     983             : 
     984             :                 pBuffer += writeUINT16(
     985             :                     pBuffer,
     986             :                     sal::static_int_cast< sal_uInt16 >(
     987        7555 :                         m_methods[i].m_params[j].m_mode));
     988             : 
     989        7555 :                 if (!m_methods[i].m_params[j].m_name.isEmpty())
     990             :                 {
     991        7555 :                     pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
     992        7555 :                     pInfo->m_value.aUtf8 = m_methods[i].m_params[j].m_name.getStr();
     993        7555 :                     cpIndexName = pInfo->m_index;
     994             :                 }
     995        7555 :                 pBuffer += writeUINT16(pBuffer, cpIndexName);
     996        7555 :                 cpIndexName = 0;
     997             :             }
     998             : 
     999        7073 :             pBuffer += writeUINT16(pBuffer, m_methods[i].m_excCount);
    1000             : 
    1001       10299 :             for (j = 0; j < m_methods[i].m_excCount; j++)
    1002             :             {
    1003        3226 :                 if (!m_methods[i].m_excNames[j].isEmpty())
    1004             :                 {
    1005        3226 :                     pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
    1006        3226 :                     pInfo->m_value.aUtf8 = m_methods[i].m_excNames[j].getStr();
    1007        3226 :                     cpIndexName = pInfo->m_index;
    1008             :                 }
    1009        3226 :                 pBuffer += writeUINT16(pBuffer, cpIndexName);
    1010        3226 :                 cpIndexName = 0;
    1011             :             }
    1012             :         }
    1013             : 
    1014        2200 :         delete[] pMethodEntrySize;
    1015             :     }
    1016             : 
    1017             :     // reference blop
    1018       32527 :     blopSize += entrySize; // referenceCount
    1019             : 
    1020       32527 :     if (m_referenceCount)
    1021             :     {
    1022        1027 :         sal_uInt16 cpIndexName = 0;
    1023        1027 :         sal_uInt16 cpIndexDoku2 = 0;
    1024             : 
    1025             :         // nReferenceEntries + n references
    1026        1027 :         blopReferenceSize = entrySize + (m_referenceCount * blopReferenceEntrySize);
    1027             : 
    1028        1027 :         blopSize += blopReferenceSize;
    1029             : 
    1030        1027 :         pBlopReferences = new sal_uInt8[blopReferenceSize];
    1031        1027 :         pBuffer = pBlopReferences;
    1032             : 
    1033        1027 :         pBuffer += writeUINT16(pBuffer, BLOP_REFERENCE_N_ENTRIES);
    1034             : 
    1035        3749 :         for (sal_uInt16 i = 0; i < m_referenceCount; i++)
    1036             :         {
    1037             :             pBuffer += writeUINT16(
    1038             :                 pBuffer,
    1039        2722 :                 sal::static_int_cast< sal_uInt16 >(m_references[i].m_type));
    1040             : 
    1041        2722 :             cpIndexName = 0;
    1042        2722 :             cpIndexDoku2 = 0;
    1043             : 
    1044        2722 :             if (!m_references[i].m_name.isEmpty())
    1045             :             {
    1046        2722 :                 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
    1047        2722 :                 pInfo->m_value.aUtf8 = m_references[i].m_name.getStr();
    1048        2722 :                 cpIndexName = pInfo->m_index;
    1049             :             }
    1050        2722 :             pBuffer += writeUINT16(pBuffer, cpIndexName);
    1051             : 
    1052        2722 :             if (!m_references[i].m_doku.isEmpty())
    1053             :             {
    1054          19 :                 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
    1055          19 :                 pInfo->m_value.aUtf8 = m_references[i].m_doku.getStr();
    1056          19 :                 cpIndexDoku2 = pInfo->m_index;
    1057             :             }
    1058        2722 :             pBuffer += writeUINT16(pBuffer, cpIndexDoku2);
    1059             : 
    1060        2722 :             pBuffer += writeUINT16(pBuffer, m_references[i].m_access);
    1061             :         }
    1062             :     }
    1063             : 
    1064             : 
    1065             :     // get CP infos blop-length
    1066       32527 :     pInfo = root.m_next;
    1067       32527 :     sal_uInt32 cpBlopSize = 0;
    1068       32527 :     sal_uInt16 cpCount = 0;
    1069             : 
    1070      186692 :     while (pInfo)
    1071             :     {
    1072      121638 :         cpBlopSize += pInfo->getBlopSize();
    1073      121638 :         cpCount++;
    1074      121638 :         pInfo = pInfo->m_next;
    1075             :     }
    1076             : 
    1077       32527 :     blopSize += cpBlopSize;
    1078       32527 :     blopSize += sizeof(sal_uInt16);   // constantPoolCount
    1079             : 
    1080             :     // write all in flat buffer
    1081             : 
    1082       32527 :     sal_uInt8 * blop = new sal_uInt8[blopSize];
    1083             : 
    1084       32527 :     pBuffer = blop;
    1085             : 
    1086             :     // Assumes two's complement arithmetic with modulo-semantics:
    1087       32527 :     pBuffer += writeUINT32(pBuffer, magic + m_version);
    1088       32527 :     pBuffer += writeUINT32(pBuffer, blopSize);
    1089       32527 :     pBuffer += writeUINT16(pBuffer, minorVersion);
    1090       32527 :     pBuffer += writeUINT16(pBuffer, majorVersion);
    1091       32527 :     pBuffer += writeUINT16(pBuffer, BLOP_HEADER_N_ENTRIES);
    1092             : 
    1093       32527 :     pBuffer += writeUINT16(pBuffer, (sal_uInt16)RT_UNO_IDL);
    1094       32527 :     pBuffer += writeUINT16(pBuffer, (sal_uInt16)m_typeClass);
    1095       32527 :     pBuffer += writeUINT16(pBuffer, cpIndexThisName);
    1096       32527 :     pBuffer += writeUINT16(pBuffer, cpIndexUik);
    1097       32527 :     pBuffer += writeUINT16(pBuffer, cpIndexDoku);
    1098       32527 :     pBuffer += writeUINT16(pBuffer, cpIndexFileName);
    1099             : 
    1100             :     // write supertypes
    1101       32527 :     pBuffer += writeUINT16(pBuffer, m_nSuperTypes);
    1102       32527 :     if (m_nSuperTypes)
    1103             :     {
    1104        6529 :         for (sal_uInt32 i=0; i < m_nSuperTypes; i++)
    1105             :         {
    1106        3391 :             pBuffer += writeUINT16(pBuffer, cpIndexSuperNames[i]);
    1107             :         }
    1108        3138 :         delete[] cpIndexSuperNames;
    1109             :     }
    1110             : 
    1111       32527 :     pBuffer += writeUINT16(pBuffer, cpCount);
    1112             : 
    1113             :     // write and delete CP infos
    1114       32527 :     pInfo = root.m_next;
    1115             : 
    1116      186692 :     while (pInfo)
    1117             :     {
    1118      121638 :         CPInfo* pNextInfo = pInfo->m_next;
    1119             : 
    1120      121638 :         pBuffer += pInfo->toBlop(pBuffer);
    1121      121638 :         delete pInfo;
    1122             : 
    1123      121638 :         pInfo = pNextInfo;
    1124             :     }
    1125             : 
    1126             :     // write fields
    1127       32527 :     pBuffer += writeUINT16(pBuffer, m_fieldCount);
    1128       32527 :     if (blopFieldsSize)
    1129             :     {
    1130        2647 :         memcpy(pBuffer, pBlopFields, blopFieldsSize);
    1131        2647 :         pBuffer += blopFieldsSize;
    1132             :     }
    1133             : 
    1134             :     // write methods
    1135       32527 :     pBuffer += writeUINT16(pBuffer, m_methodCount);
    1136       32527 :     if (blopMethodsSize)
    1137             :     {
    1138        2200 :         memcpy(pBuffer, pBlopMethods, blopMethodsSize);
    1139        2200 :         pBuffer += blopMethodsSize;
    1140             :     }
    1141             : 
    1142             :     // write references
    1143       32527 :     pBuffer += writeUINT16(pBuffer, m_referenceCount);
    1144       32527 :     if (blopReferenceSize)
    1145             :     {
    1146        1027 :         memcpy(pBuffer, pBlopReferences, blopReferenceSize);
    1147        1027 :         pBuffer += blopReferenceSize;
    1148             :     }
    1149             : 
    1150       32527 :     delete[] pBlopFields;
    1151       32527 :     delete[] pBlopMethods;
    1152       32527 :     delete[] pBlopReferences;
    1153             : 
    1154       32527 :     delete[] m_blop;
    1155       32527 :     m_blop = blop;
    1156       32527 :     m_blopSize = blopSize;
    1157       32527 : }
    1158             : 
    1159             : 
    1160             : /**************************************************************************
    1161             : 
    1162             :     C-API
    1163             : 
    1164             : **************************************************************************/
    1165             : 
    1166             : extern "C" {
    1167             : 
    1168           0 : static void TYPEREG_CALLTYPE acquire(TypeWriterImpl hEntry)
    1169             : {
    1170           0 :     TypeWriter* pEntry = (TypeWriter*) hEntry;
    1171             : 
    1172           0 :     if (pEntry != NULL)
    1173           0 :         pEntry->m_refCount++;
    1174           0 : }
    1175             : 
    1176           0 : static void TYPEREG_CALLTYPE release(TypeWriterImpl hEntry)
    1177             : {
    1178           0 :     TypeWriter* pEntry = (TypeWriter*) hEntry;
    1179             : 
    1180           0 :     if (pEntry != NULL)
    1181             :     {
    1182           0 :         if (--pEntry->m_refCount == 0)
    1183           0 :             delete pEntry;
    1184             :     }
    1185           0 : }
    1186             : 
    1187           0 : static void TYPEREG_CALLTYPE setUik(TypeWriterImpl  hEntry, const RTUik* uik)
    1188             : {
    1189           0 :     TypeWriter* pEntry = (TypeWriter*) hEntry;
    1190             : 
    1191           0 :     if (pEntry != NULL)
    1192             :     {
    1193           0 :         if (pEntry->m_pUik)
    1194             :         {
    1195           0 :             pEntry->m_pUik->m_Data1 = uik->m_Data1;
    1196           0 :             pEntry->m_pUik->m_Data2 = uik->m_Data2;
    1197           0 :             pEntry->m_pUik->m_Data3 = uik->m_Data3;
    1198           0 :             pEntry->m_pUik->m_Data4 = uik->m_Data4;
    1199           0 :             pEntry->m_pUik->m_Data5 = uik->m_Data5;
    1200             :         }
    1201             :         else
    1202           0 :             pEntry->m_pUik = new RTUik(*uik);
    1203             :     }
    1204           0 : }
    1205             : 
    1206           0 : static void TYPEREG_CALLTYPE setDoku(TypeWriterImpl hEntry, rtl_uString* doku)
    1207             : {
    1208           0 :     static_cast< TypeWriter * >(hEntry)->m_doku = toByteString(doku);
    1209           0 : }
    1210             : 
    1211           0 : static void TYPEREG_CALLTYPE setFileName(TypeWriterImpl hEntry, rtl_uString* fileName)
    1212             : {
    1213           0 :     static_cast< TypeWriter * >(hEntry)->m_fileName = toByteString(fileName);
    1214           0 : }
    1215             : 
    1216       19212 : REG_DLLPUBLIC sal_Bool TYPEREG_CALLTYPE typereg_writer_setFieldData(
    1217             :     void * handle, sal_uInt16 index, rtl_uString const * documentation,
    1218             :     rtl_uString const * fileName, RTFieldAccess flags, rtl_uString const * name,
    1219             :     rtl_uString const * typeName, RTValueType valueType,
    1220             :     RTConstValueUnion valueValue)
    1221             :     SAL_THROW_EXTERN_C()
    1222             : {
    1223             :     try {
    1224             :         static_cast< TypeWriter * >(handle)->m_fields[index].setData(
    1225             :             toByteString(name), toByteString(typeName),
    1226             :             toByteString(documentation), toByteString(fileName), flags,
    1227       19212 :             valueType, valueValue);
    1228           0 :     } catch (std::bad_alloc &) {
    1229           0 :         return false;
    1230             :     }
    1231       19212 :     return true;
    1232             : }
    1233             : 
    1234           0 : static void TYPEREG_CALLTYPE setFieldData(TypeWriterImpl    hEntry,
    1235             :                                           sal_uInt16        index,
    1236             :                                           rtl_uString*      name,
    1237             :                                           rtl_uString*      typeName,
    1238             :                                           rtl_uString*      doku,
    1239             :                                           rtl_uString*      fileName,
    1240             :                                           RTFieldAccess     access,
    1241             :                                           RTValueType       valueType,
    1242             :                                           RTConstValueUnion constValue)
    1243             : {
    1244             :     typereg_writer_setFieldData(
    1245             :         hEntry, index, doku, fileName, access, name, typeName, valueType,
    1246           0 :         constValue);
    1247           0 : }
    1248             : 
    1249        7073 : REG_DLLPUBLIC sal_Bool TYPEREG_CALLTYPE typereg_writer_setMethodData(
    1250             :     void * handle, sal_uInt16 index, rtl_uString const * documentation,
    1251             :     RTMethodMode flags, rtl_uString const * name,
    1252             :     rtl_uString const * returnTypeName, sal_uInt16 parameterCount,
    1253             :     sal_uInt16 exceptionCount)
    1254             :     SAL_THROW_EXTERN_C()
    1255             : {
    1256             :     try {
    1257             :         static_cast< TypeWriter * >(handle)->m_methods[index].setData(
    1258             :             toByteString(name), toByteString(returnTypeName), flags,
    1259        7073 :             parameterCount, exceptionCount, toByteString(documentation));
    1260           0 :     } catch (std::bad_alloc &) {
    1261           0 :         return false;
    1262             :     }
    1263        7073 :     return true;
    1264             : }
    1265             : 
    1266           0 : static void TYPEREG_CALLTYPE setMethodData(TypeWriterImpl   hEntry,
    1267             :                                            sal_uInt16       index,
    1268             :                                            rtl_uString*     name,
    1269             :                                            rtl_uString*     returnTypeName,
    1270             :                                            RTMethodMode     mode,
    1271             :                                            sal_uInt16       paramCount,
    1272             :                                            sal_uInt16       excCount,
    1273             :                                            rtl_uString*     doku)
    1274             : {
    1275             :     typereg_writer_setMethodData(
    1276           0 :         hEntry, index, doku, mode, name, returnTypeName, paramCount, excCount);
    1277           0 : }
    1278             : 
    1279        7555 : REG_DLLPUBLIC sal_Bool TYPEREG_CALLTYPE typereg_writer_setMethodParameterData(
    1280             :     void * handle, sal_uInt16 methodIndex, sal_uInt16 parameterIndex,
    1281             :     RTParamMode flags, rtl_uString const * name, rtl_uString const * typeName)
    1282             :     SAL_THROW_EXTERN_C()
    1283             : {
    1284             :     try {
    1285             :         static_cast< TypeWriter * >(handle)->
    1286        7555 :             m_methods[methodIndex].m_params[parameterIndex].setData(
    1287       15110 :                 toByteString(typeName), toByteString(name), flags);
    1288           0 :     } catch (std::bad_alloc &) {
    1289           0 :         return false;
    1290             :     }
    1291        7555 :     return true;
    1292             : }
    1293             : 
    1294           0 : static void TYPEREG_CALLTYPE setParamData(TypeWriterImpl    hEntry,
    1295             :                                           sal_uInt16        index,
    1296             :                                           sal_uInt16        paramIndex,
    1297             :                                           rtl_uString*      type,
    1298             :                                           rtl_uString*      name,
    1299             :                                           RTParamMode       mode)
    1300             : {
    1301             :     typereg_writer_setMethodParameterData(
    1302           0 :         hEntry, index, paramIndex, mode, name, type);
    1303           0 : }
    1304             : 
    1305        3226 : REG_DLLPUBLIC sal_Bool TYPEREG_CALLTYPE typereg_writer_setMethodExceptionTypeName(
    1306             :     void * handle, sal_uInt16 methodIndex, sal_uInt16 exceptionIndex,
    1307             :     rtl_uString const * typeName)
    1308             :     SAL_THROW_EXTERN_C()
    1309             : {
    1310             :     try {
    1311             :         static_cast< TypeWriter * >(handle)->m_methods[methodIndex].setExcName(
    1312        3226 :             exceptionIndex, toByteString(typeName));
    1313           0 :     } catch (std::bad_alloc &) {
    1314           0 :         return false;
    1315             :     }
    1316        3226 :     return true;
    1317             : }
    1318             : 
    1319           0 : static void TYPEREG_CALLTYPE setExcData(TypeWriterImpl  hEntry,
    1320             :                                         sal_uInt16      index,
    1321             :                                         sal_uInt16      excIndex,
    1322             :                                         rtl_uString*    type)
    1323             : {
    1324           0 :     typereg_writer_setMethodExceptionTypeName(hEntry, index, excIndex, type);
    1325           0 : }
    1326             : 
    1327       32527 : REG_DLLPUBLIC void const * TYPEREG_CALLTYPE typereg_writer_getBlob(void * handle, sal_uInt32 * size)
    1328             :     SAL_THROW_EXTERN_C()
    1329             : {
    1330       32527 :     TypeWriter * writer = static_cast< TypeWriter * >(handle);
    1331       32527 :     if (writer->m_blop == 0) {
    1332             :         try {
    1333       32527 :             writer->createBlop();
    1334           0 :         } catch (std::bad_alloc &) {
    1335           0 :             return 0;
    1336             :         }
    1337             :     }
    1338       32527 :     *size = writer->m_blopSize;
    1339       32527 :     return writer->m_blop;
    1340             : }
    1341             : 
    1342           0 : static const sal_uInt8* TYPEREG_CALLTYPE getBlop(TypeWriterImpl hEntry)
    1343             : {
    1344             :     sal_uInt32 size;
    1345             :     return static_cast< sal_uInt8 const * >(
    1346           0 :         typereg_writer_getBlob(hEntry, &size));
    1347             : }
    1348             : 
    1349           0 : static sal_uInt32 TYPEREG_CALLTYPE getBlopSize(TypeWriterImpl hEntry)
    1350             : {
    1351             :     sal_uInt32 size;
    1352           0 :     typereg_writer_getBlob(hEntry, &size);
    1353           0 :     return size;
    1354             : }
    1355             : 
    1356        2722 : REG_DLLPUBLIC sal_Bool TYPEREG_CALLTYPE typereg_writer_setReferenceData(
    1357             :     void * handle, sal_uInt16 index, rtl_uString const * documentation,
    1358             :     RTReferenceType sort, RTFieldAccess flags, rtl_uString const * typeName)
    1359             :     SAL_THROW_EXTERN_C()
    1360             : {
    1361             :     try {
    1362             :         static_cast< TypeWriter * >(handle)->m_references[index].setData(
    1363        2722 :             toByteString(typeName), sort, toByteString(documentation), flags);
    1364           0 :     } catch (std::bad_alloc &) {
    1365           0 :         return false;
    1366             :     }
    1367        2722 :     return true;
    1368             : }
    1369             : 
    1370           0 : static void TYPEREG_CALLTYPE setReferenceData(TypeWriterImpl    hEntry,
    1371             :                                               sal_uInt16        index,
    1372             :                                               rtl_uString*      name,
    1373             :                                               RTReferenceType   refType,
    1374             :                                               rtl_uString*      doku,
    1375             :                                               RTFieldAccess     access)
    1376             : {
    1377           0 :     typereg_writer_setReferenceData(hEntry, index, doku, refType, access, name);
    1378           0 : }
    1379             : 
    1380       32527 : REG_DLLPUBLIC void * TYPEREG_CALLTYPE typereg_writer_create(
    1381             :     typereg_Version version, rtl_uString const * documentation,
    1382             :     rtl_uString const * fileName, RTTypeClass typeClass, sal_Bool published,
    1383             :     rtl_uString const * typeName, sal_uInt16 superTypeCount,
    1384             :     sal_uInt16 fieldCount, sal_uInt16 methodCount, sal_uInt16 referenceCount)
    1385             :     SAL_THROW_EXTERN_C()
    1386             : {
    1387             :     try {
    1388             :         return new TypeWriter(
    1389             :             version, toByteString(documentation), toByteString(fileName),
    1390             :             typeClass, published, toByteString(typeName), superTypeCount,
    1391       32527 :             fieldCount, methodCount, referenceCount);
    1392           0 :     } catch (std::bad_alloc &) {
    1393           0 :         return 0;
    1394             :     }
    1395             : }
    1396             : 
    1397       32527 : REG_DLLPUBLIC void TYPEREG_CALLTYPE typereg_writer_destroy(void * handle) SAL_THROW_EXTERN_C() {
    1398       32527 :     delete static_cast< TypeWriter * >(handle);
    1399       32527 : }
    1400             : 
    1401        3391 : REG_DLLPUBLIC sal_Bool TYPEREG_CALLTYPE typereg_writer_setSuperTypeName(
    1402             :     void * handle, sal_uInt16 index, rtl_uString const * typeName)
    1403             :     SAL_THROW_EXTERN_C()
    1404             : {
    1405             :     try {
    1406             :         static_cast< TypeWriter * >(handle)->setSuperType(
    1407        3391 :             index, toByteString(typeName));
    1408           0 :     } catch (std::bad_alloc &) {
    1409           0 :         return false;
    1410             :     }
    1411        3391 :     return true;
    1412             : }
    1413             : 
    1414           0 : static TypeWriterImpl TYPEREG_CALLTYPE createEntry(
    1415             :     RTTypeClass typeClass, rtl_uString * typeName, rtl_uString * superTypeName,
    1416             :     sal_uInt16 fieldCount, sal_uInt16 methodCount, sal_uInt16 referenceCount)
    1417             : {
    1418           0 :     OUString empty;
    1419           0 :     sal_uInt16 superTypeCount = rtl_uString_getLength(superTypeName) == 0
    1420           0 :         ? 0 : 1;
    1421             :     TypeWriterImpl t = typereg_writer_create(
    1422             :         TYPEREG_VERSION_0, empty.pData, empty.pData, typeClass, false, typeName,
    1423           0 :         superTypeCount, fieldCount, methodCount, referenceCount);
    1424           0 :     if (superTypeCount > 0) {
    1425           0 :         typereg_writer_setSuperTypeName(t, 0, superTypeName);
    1426             :     }
    1427           0 :     return t;
    1428             : }
    1429             : 
    1430           0 : REG_DLLPUBLIC RegistryTypeWriter_Api* TYPEREG_CALLTYPE initRegistryTypeWriter_Api(void)
    1431             : {
    1432             :     static RegistryTypeWriter_Api aApi= {0,0,0,0,0,0,0,0,0,0,0,0,0};
    1433           0 :     if (!aApi.acquire)
    1434             :     {
    1435           0 :         aApi.createEntry        = &createEntry;
    1436           0 :         aApi.acquire            = &acquire;
    1437           0 :         aApi.release            = &release;
    1438           0 :         aApi.setUik             = &setUik;
    1439           0 :         aApi.setDoku            = &setDoku;
    1440           0 :         aApi.setFileName        = &setFileName;
    1441           0 :         aApi.setFieldData       = &setFieldData;
    1442           0 :         aApi.setMethodData      = &setMethodData;
    1443           0 :         aApi.setParamData       = &setParamData;
    1444           0 :         aApi.setExcData         = &setExcData;
    1445           0 :         aApi.getBlop            = &getBlop;
    1446           0 :         aApi.getBlopSize        = &getBlopSize;
    1447           0 :         aApi.setReferenceData   = &setReferenceData;
    1448             : 
    1449           0 :         return (&aApi);
    1450             :     }
    1451             :     else
    1452             :     {
    1453           0 :         return (&aApi);
    1454             :     }
    1455             : }
    1456             : 
    1457             : }
    1458             : 
    1459             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10