LCOV - code coverage report
Current view: top level - codemaker/source/codemaker - typemanager.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 143 193 74.1 %
Date: 2012-08-25 Functions: 17 21 81.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 140 292 47.9 %

           Branch data     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 "rtl/alloc.h"
      22                 :            : #include "codemaker/typemanager.hxx"
      23                 :            : #include "registry/reader.hxx"
      24                 :            : #include "registry/version.h"
      25                 :            : 
      26                 :            : using ::rtl::OUString;
      27                 :            : using ::rtl::OString;
      28                 :            : using ::rtl::OStringToOUString;
      29                 :            : using ::rtl::OUStringToOString;
      30                 :            : 
      31                 :         28 : TypeManager::TypeManager()
      32                 :            : {
      33                 :         28 :     m_pImpl = new TypeManagerImpl();
      34                 :         28 :     acquire();
      35                 :         28 : }
      36                 :            : 
      37                 :         28 : TypeManager::~TypeManager()
      38                 :            : {
      39                 :         28 :     release();
      40         [ -  + ]:         28 : }
      41                 :            : 
      42                 :         56 : sal_Int32 TypeManager::acquire()
      43                 :            : {
      44                 :         56 :     return osl_incrementInterlockedCount(&m_pImpl->m_refCount);
      45                 :            : }
      46                 :            : 
      47                 :         56 : sal_Int32 TypeManager::release()
      48                 :            : {
      49                 :         56 :     sal_Int32 refCount = 0;
      50         [ +  + ]:         56 :     if (0 == (refCount = osl_decrementInterlockedCount(&m_pImpl->m_refCount)) )
      51                 :            :     {
      52                 :         28 :         delete m_pImpl;
      53                 :            :     }
      54                 :         56 :     return refCount;
      55                 :            : }
      56                 :            : 
      57                 :      53146 : sal_Bool TypeManager::isBaseType(const ::rtl::OString& name)
      58                 :            : {
      59         [ -  + ]:      53146 :     if ( name.equals(OString("short")) )
      60                 :          0 :         return sal_True;
      61         [ -  + ]:      53146 :     if ( name.equals(OString("unsigned short")) )
      62                 :          0 :         return sal_True;
      63         [ -  + ]:      53146 :     if ( name.equals(OString("long")) )
      64                 :          0 :         return sal_True;
      65         [ -  + ]:      53146 :     if ( name.equals(OString("unsigned long")) )
      66                 :          0 :         return sal_True;
      67         [ -  + ]:      53146 :     if ( name.equals(OString("hyper")) )
      68                 :          0 :         return sal_True;
      69         [ -  + ]:      53146 :     if ( name.equals(OString("unsigned hyper")) )
      70                 :          0 :         return sal_True;
      71         [ -  + ]:      53146 :     if ( name.equals(OString("string")) )
      72                 :          0 :         return sal_True;
      73         [ -  + ]:      53146 :     if ( name.equals(OString("boolean")) )
      74                 :          0 :         return sal_True;
      75         [ -  + ]:      53146 :     if ( name.equals(OString("char")) )
      76                 :          0 :         return sal_True;
      77         [ -  + ]:      53146 :     if ( name.equals(OString("byte")) )
      78                 :          0 :         return sal_True;
      79         [ -  + ]:      53146 :     if ( name.equals(OString("any")) )
      80                 :          0 :         return sal_True;
      81         [ -  + ]:      53146 :     if ( name.equals(OString("type")) )
      82                 :          0 :         return sal_True;
      83         [ -  + ]:      53146 :     if ( name.equals(OString("float")) )
      84                 :          0 :         return sal_True;
      85         [ -  + ]:      53146 :     if ( name.equals(OString("double")) )
      86                 :          0 :         return sal_True;
      87         [ -  + ]:      53146 :     if ( name.equals(OString("void")) )
      88                 :          0 :         return sal_True;
      89                 :            : 
      90                 :      53146 :     return sal_False;
      91                 :            : }
      92                 :            : 
      93                 :         28 : RegistryTypeManager::RegistryTypeManager()
      94                 :            : {
      95 [ +  - ][ +  - ]:         28 :     m_pImpl = new RegistryTypeManagerImpl();
      96         [ +  - ]:         28 :     acquire();
      97                 :         28 : }
      98                 :            : 
      99                 :         28 : RegistryTypeManager::~RegistryTypeManager()
     100                 :            : {
     101         [ +  - ]:         28 :     release();
     102         [ -  + ]:         28 : }
     103                 :            : 
     104                 :         28 : void RegistryTypeManager::acquire()
     105                 :            : {
     106                 :         28 :     TypeManager::acquire();
     107                 :         28 : }
     108                 :            : 
     109                 :         28 : void RegistryTypeManager::release()
     110                 :            : {
     111         [ -  + ]:         28 :     if (0 == TypeManager::release())
     112                 :            :     {
     113                 :          0 :         freeRegistries();
     114                 :            : 
     115         [ #  # ]:          0 :         delete m_pImpl;
     116                 :            :     }
     117                 :         28 : }
     118                 :            : 
     119                 :         28 : sal_Bool RegistryTypeManager::init(
     120                 :            :     const StringVector& regFiles,
     121                 :            :     StringVector const & extraFiles )
     122                 :            : {
     123         [ -  + ]:         28 :     if (regFiles.empty())
     124                 :          0 :         return sal_False;
     125                 :            : 
     126                 :         28 :     StringVector::const_iterator iter = regFiles.begin();
     127                 :            : 
     128         [ +  - ]:         28 :     Registry tmpReg;
     129 [ +  - ][ +  + ]:         56 :     while (iter != regFiles.end())
     130                 :            :     {
     131 [ +  - ][ +  - ]:         28 :         if (!tmpReg.open( convertToFileUrl(*iter), REG_READONLY))
                 [ +  - ]
     132 [ +  - ][ +  - ]:         28 :             m_pImpl->m_registries.push_back(new Registry(tmpReg));
                 [ +  - ]
     133                 :            :         else
     134                 :            :         {
     135         [ #  # ]:          0 :             freeRegistries();
     136                 :          0 :             return sal_False;
     137                 :            :         }
     138                 :         28 :         ++iter;
     139                 :            :     }
     140                 :         28 :     iter = extraFiles.begin();
     141 [ +  - ][ +  + ]:         50 :     while (iter != extraFiles.end())
     142                 :            :     {
     143 [ +  - ][ +  - ]:         22 :         if (!tmpReg.open( convertToFileUrl(*iter), REG_READONLY))
                 [ +  - ]
     144 [ +  - ][ +  - ]:         22 :             m_pImpl->m_extra_registries.push_back(new Registry(tmpReg));
                 [ +  - ]
     145                 :            :         else
     146                 :            :         {
     147         [ #  # ]:          0 :             freeRegistries();
     148                 :          0 :             return sal_False;
     149                 :            :         }
     150                 :         22 :         ++iter;
     151                 :            :     }
     152                 :            : 
     153         [ +  - ]:         28 :     return sal_True;
     154                 :            : }
     155                 :            : 
     156                 :      59184 : ::rtl::OString RegistryTypeManager::getTypeName(RegistryKey& rTypeKey) const
     157                 :            : {
     158         [ +  - ]:      59184 :     OString typeName = OUStringToOString(rTypeKey.getName(), RTL_TEXTENCODING_UTF8);
     159                 :            : 
     160         [ +  - ]:      59184 :     if (m_pImpl->m_base.getLength() > 1)
     161                 :      59184 :         typeName = typeName.copy(typeName.indexOf('/', 1) + 1);
     162                 :            :     else
     163                 :          0 :         typeName = typeName.copy(1);
     164                 :            : 
     165                 :      59184 :     return typeName;
     166                 :            : }
     167                 :            : 
     168                 :      61953 : typereg::Reader RegistryTypeManager::getTypeReader(
     169                 :            :     const OString& name, sal_Bool * pIsExtraType ) const
     170                 :            : {
     171                 :      61953 :     typereg::Reader reader;
     172         [ +  - ]:      61953 :     RegistryKey key(searchTypeKey(name, pIsExtraType));
     173                 :            : 
     174         [ +  + ]:      61953 :     if (key.isValid())
     175                 :            :     {
     176                 :            :         RegValueType    valueType;
     177                 :            :         sal_uInt32      valueSize;
     178                 :            : 
     179 [ +  - ][ +  - ]:      60317 :         if (!key.getValueInfo(OUString(), &valueType, &valueSize))
     180                 :            :         {
     181                 :      60317 :             sal_uInt8*  pBuffer = (sal_uInt8*)rtl_allocateMemory(valueSize);
     182 [ +  - ][ +  - ]:      60317 :             if (!key.getValue(OUString(), pBuffer))
     183                 :            :             {
     184                 :            :                 reader = typereg::Reader(
     185         [ +  - ]:      60317 :                     pBuffer, valueSize, true, TYPEREG_VERSION_1);
     186                 :            :             }
     187                 :      60317 :             rtl_freeMemory(pBuffer);
     188                 :            :         }
     189                 :            :     }
     190         [ +  - ]:      61953 :     return reader;
     191                 :            : }
     192                 :            : 
     193                 :      23556 : typereg::Reader RegistryTypeManager::getTypeReader(RegistryKey& rTypeKey) const
     194                 :            : {
     195                 :      23556 :     typereg::Reader reader;
     196                 :            : 
     197         [ +  - ]:      23556 :     if (rTypeKey.isValid())
     198                 :            :     {
     199                 :            :         RegValueType    valueType;
     200                 :            :         sal_uInt32      valueSize;
     201                 :            : 
     202 [ +  - ][ +  - ]:      23556 :         if (!rTypeKey.getValueInfo(OUString(), &valueType, &valueSize))
     203                 :            :         {
     204                 :      23556 :             sal_uInt8*  pBuffer = (sal_uInt8*)rtl_allocateMemory(valueSize);
     205 [ +  - ][ +  - ]:      23556 :             if (!rTypeKey.getValue(OUString(), pBuffer))
     206                 :            :             {
     207                 :            :                 reader = typereg::Reader(
     208         [ +  - ]:      23556 :                     pBuffer, valueSize, true, TYPEREG_VERSION_1);
     209                 :            :             }
     210                 :      23556 :             rtl_freeMemory(pBuffer);
     211                 :            :         }
     212                 :            :     }
     213                 :      23556 :     return reader;
     214                 :            : }
     215                 :            : 
     216                 :            : 
     217                 :     571574 : RTTypeClass RegistryTypeManager::getTypeClass(const OString& name) const
     218                 :            : {
     219         [ +  + ]:     571574 :     if (m_pImpl->m_t2TypeClass.count(name) > 0)
     220                 :            :     {
     221                 :     300478 :         return m_pImpl->m_t2TypeClass[name];
     222                 :            :     } else
     223                 :            :     {
     224         [ +  - ]:     271096 :         RegistryKey key(searchTypeKey(name));
     225                 :            : 
     226         [ +  + ]:     271096 :         if (key.isValid())
     227                 :            :         {
     228                 :            :             RegValueType    valueType;
     229                 :            :             sal_uInt32      valueSize;
     230                 :            : 
     231 [ +  - ][ +  - ]:      14562 :             if (!key.getValueInfo(OUString(), &valueType, &valueSize))
     232                 :            :             {
     233                 :      14562 :                 sal_uInt8*  pBuffer = (sal_uInt8*)rtl_allocateMemory(valueSize);
     234 [ +  - ][ +  - ]:      14562 :                 if (!key.getValue(OUString(), pBuffer))
     235                 :            :                 {
     236                 :            :                     typereg::Reader reader(
     237         [ +  - ]:      14562 :                         pBuffer, valueSize, false, TYPEREG_VERSION_1);
     238                 :            : 
     239                 :      14562 :                     RTTypeClass ret = reader.getTypeClass();
     240                 :            : 
     241                 :      14562 :                     rtl_freeMemory(pBuffer);
     242                 :            : 
     243         [ +  - ]:      14562 :                     m_pImpl->m_t2TypeClass[name] = ret;
     244                 :      14562 :                     return ret;
     245                 :            :                 }
     246                 :     256534 :                 rtl_freeMemory(pBuffer);
     247                 :            :             }
     248 [ +  - ][ +  + ]:     271096 :         }
     249                 :            :     }
     250                 :            : 
     251                 :     571574 :     return RT_TYPE_INVALID;
     252                 :            : }
     253                 :            : 
     254                 :          0 : RTTypeClass RegistryTypeManager::getTypeClass(RegistryKey& rTypeKey) const
     255                 :            : {
     256         [ #  # ]:          0 :     OString name = getTypeName(rTypeKey);
     257                 :            : 
     258 [ #  # ][ #  # ]:          0 :     if (m_pImpl->m_t2TypeClass.count(name) > 0)
     259                 :            :     {
     260         [ #  # ]:          0 :         return m_pImpl->m_t2TypeClass[name];
     261                 :            :     } else
     262                 :            :     {
     263         [ #  # ]:          0 :         if (rTypeKey.isValid())
     264                 :            :         {
     265                 :            :             RegValueType    valueType;
     266                 :            :             sal_uInt32      valueSize;
     267                 :            : 
     268 [ #  # ][ #  # ]:          0 :             if (!rTypeKey.getValueInfo(OUString(), &valueType, &valueSize))
     269                 :            :             {
     270                 :          0 :                 sal_uInt8*  pBuffer = (sal_uInt8*)rtl_allocateMemory(valueSize);
     271 [ #  # ][ #  # ]:          0 :                 if (!rTypeKey.getValue(OUString(), pBuffer))
     272                 :            :                 {
     273                 :            :                     typereg::Reader reader(
     274         [ #  # ]:          0 :                         pBuffer, valueSize, false, TYPEREG_VERSION_1);
     275                 :            : 
     276                 :          0 :                     RTTypeClass ret = reader.getTypeClass();
     277                 :            : 
     278                 :          0 :                     rtl_freeMemory(pBuffer);
     279                 :            : 
     280         [ #  # ]:          0 :                     m_pImpl->m_t2TypeClass[name] = ret;
     281                 :          0 :                     return ret;
     282                 :            :                 }
     283                 :          0 :                 rtl_freeMemory(pBuffer);
     284                 :            :             }
     285                 :            :         }
     286                 :            :     }
     287                 :            : 
     288                 :          0 :     return RT_TYPE_INVALID;
     289                 :            : }
     290                 :            : 
     291                 :         28 : void RegistryTypeManager::setBase(const OString& base)
     292                 :            : {
     293                 :            : 
     294         [ -  + ]:         28 :     if (base.lastIndexOf('/') == (base.getLength() - 1))
     295                 :          0 :         m_pImpl->m_base += base.copy(0, base.lastIndexOf('/') - 1);
     296                 :            :     else
     297                 :         28 :         m_pImpl->m_base += base;
     298                 :         28 : }
     299                 :            : 
     300                 :          0 : void RegistryTypeManager::freeRegistries()
     301                 :            : {
     302         [ #  # ]:          0 :     RegistryList::const_iterator iter = m_pImpl->m_registries.begin();
     303 [ #  # ][ #  # ]:          0 :     while (iter != m_pImpl->m_registries.end())
     304                 :            :     {
     305 [ #  # ][ #  # ]:          0 :         delete *iter;
     306                 :          0 :         ++iter;
     307                 :            :     }
     308         [ #  # ]:          0 :     iter = m_pImpl->m_extra_registries.begin();
     309 [ #  # ][ #  # ]:          0 :     while (iter != m_pImpl->m_extra_registries.end())
     310                 :            :     {
     311 [ #  # ][ #  # ]:          0 :         delete *iter;
     312                 :          0 :         ++iter;
     313                 :            :     }
     314                 :          0 : }
     315                 :            : 
     316                 :     333049 : RegistryKey RegistryTypeManager::searchTypeKey(const OString& name_, sal_Bool * pIsExtraType )
     317                 :            :     const
     318                 :            : {
     319         [ +  - ]:     333049 :     OUString name( OStringToOUString(m_pImpl->m_base + "/" + name_, RTL_TEXTENCODING_UTF8) );
     320 [ +  - ][ +  - ]:     333049 :     RegistryKey key, rootKey;
     321                 :            : 
     322         [ +  - ]:     333049 :     RegistryList::const_iterator iter = m_pImpl->m_registries.begin();
     323 [ +  - ][ +  + ]:     605386 :     while (iter != m_pImpl->m_registries.end())
     324                 :            :     {
     325 [ +  - ][ +  - ]:     333049 :         if (!(*iter)->openRootKey(rootKey))
     326                 :            :         {
     327 [ +  - ][ +  + ]:     333049 :             if (!rootKey.openKey(name, key))
     328                 :            :             {
     329         [ +  + ]:      60712 :                 if (pIsExtraType)
     330                 :       6044 :                     *pIsExtraType = sal_False;
     331                 :            :                 return key;
     332                 :            :             }
     333                 :            :         }
     334                 :     272337 :         ++iter;
     335                 :            :     }
     336         [ +  - ]:     272337 :     iter = m_pImpl->m_extra_registries.begin();
     337 [ +  - ][ +  + ]:     566318 :     while (iter != m_pImpl->m_extra_registries.end())
     338                 :            :     {
     339 [ +  - ][ +  - ]:     293981 :         if (!(*iter)->openRootKey(rootKey))
     340                 :            :         {
     341 [ +  - ][ +  + ]:     293981 :             if (!rootKey.openKey(name, key))
     342                 :            :             {
     343         [ +  + ]:      14167 :                 if (pIsExtraType)
     344                 :        600 :                     *pIsExtraType = sal_True;
     345                 :      14167 :                 break;
     346                 :            :             }
     347                 :            :         }
     348                 :     279814 :         ++iter;
     349                 :            :     }
     350                 :            : 
     351         [ +  - ]:     333049 :     return key;
     352                 :            : }
     353                 :            : 
     354                 :      29618 : RegistryKeyList RegistryTypeManager::getTypeKeys(const ::rtl::OString& name_) const
     355                 :            : {
     356         [ +  - ]:      29618 :     RegistryKeyList keyList= RegistryKeyList();
     357                 :      29618 :     OString tmpName;
     358 [ -  + ][ +  - ]:      29618 :     if ( name_.equals("/") || name_.equals(m_pImpl->m_base) ) {
         [ +  - ][ +  + ]
                 [ +  + ]
     359                 :         26 :         tmpName = m_pImpl->m_base;
     360                 :            :     } else {
     361         [ -  + ]:      29592 :         if ( m_pImpl->m_base.equals("/") )
     362                 :          0 :             tmpName = name_;
     363                 :            :         else
     364                 :      29592 :             tmpName = m_pImpl->m_base + "/" + name_;
     365                 :            :     }
     366                 :            : 
     367         [ +  - ]:      29618 :     OUString name( OStringToOUString(tmpName, RTL_TEXTENCODING_UTF8) );
     368 [ +  - ][ +  - ]:      29618 :     RegistryKey key, rootKey;
     369                 :            : 
     370         [ +  - ]:      29618 :     RegistryList::const_iterator iter = m_pImpl->m_registries.begin();
     371 [ +  - ][ +  + ]:      59236 :     while (iter != m_pImpl->m_registries.end())
     372                 :            :     {
     373 [ +  - ][ +  - ]:      29618 :         if (!(*iter)->openRootKey(rootKey))
     374                 :            :         {
     375 [ +  - ][ +  - ]:      29618 :             if (!rootKey.openKey(name, key))
     376                 :            :             {
     377 [ +  - ][ +  - ]:      29618 :                 keyList.push_back(KeyPair(key, sal_False));
                 [ +  - ]
     378                 :            :             }
     379                 :            :         }
     380                 :      29618 :         ++iter;
     381                 :            :     }
     382         [ +  - ]:      29618 :     iter = m_pImpl->m_extra_registries.begin();
     383 [ +  - ][ +  + ]:      58108 :     while (iter != m_pImpl->m_extra_registries.end())
     384                 :            :     {
     385 [ +  - ][ +  - ]:      28490 :         if (!(*iter)->openRootKey(rootKey))
     386                 :            :         {
     387 [ +  - ][ +  + ]:      28490 :             if (!rootKey.openKey(name, key))
     388                 :            :             {
     389 [ +  - ][ +  - ]:        117 :                 keyList.push_back(KeyPair(key, sal_True));
                 [ +  - ]
     390                 :            :             }
     391                 :            :         }
     392                 :      28490 :         ++iter;
     393                 :            :     }
     394                 :            : 
     395 [ +  - ][ +  - ]:      29618 :     return keyList;
     396                 :            : }
     397                 :            : 
     398                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10