LCOV - code coverage report
Current view: top level - include/registry - reader.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 139 0.0 %
Date: 2014-04-14 Functions: 0 34 0.0 %
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             : #ifndef INCLUDED_registry_reader_hxx
      21             : #define INCLUDED_registry_reader_hxx
      22             : 
      23             : #include <registry/reader.h>
      24             : #include <registry/refltype.hxx>
      25             : #include <registry/types.h>
      26             : #include <registry/version.h>
      27             : 
      28             : #include <rtl/ustring.hxx>
      29             : #include <sal/types.h>
      30             : 
      31             : #include <algorithm>
      32             : #include <new>
      33             : 
      34             : namespace typereg {
      35             : 
      36             : /**
      37             :    A type reader working on a binary blob that represents a UNOIDL type.
      38             : 
      39             :    <p>Instances of this class are not multi-thread&ndash;safe.</p>
      40             : 
      41             :    @since UDK 3.2.0
      42             :  */
      43             : class Reader {
      44             : public:
      45             :     /**
      46             :        Creates an invalid type reader.
      47             :      */
      48             :     Reader(): m_handle(0) {}
      49             : 
      50             :     /**
      51             :        Creates a type reader.
      52             : 
      53             :        <p>If the given binary blob is malformed, or of a version larger than
      54             :        <code>maxVersion</code>, the created type reader is flagged as
      55             :        invalid.</p>
      56             : 
      57             :        @param buffer the binary blob representing the type; must point to at
      58             :        least <code>length</code> bytes, and need only be byte-aligned
      59             : 
      60             :        @param length the size in bytes of the binary blob representing the type
      61             : 
      62             :        @param copy if true, the type reader creates an internal copy of the
      63             :        given buffer, and the given buffer is not accessed after this constructor
      64             :        returns; if false, the type reader works directly on the given buffer,
      65             :        which must remain available unmodified until the underlying type reader
      66             :        is destroyed (note that the lifetime of the underlying type reader can be
      67             :        different from the lifetime of this <code>Reader</code> instance)
      68             : 
      69             :        @param maxVersion the maximum binary blob version the client is prepared
      70             :        to handle; must not be negative
      71             : 
      72             :        @exception std::bad_alloc is raised if an out-of-memory condition occurs
      73             :      */
      74           0 :     Reader(
      75             :         void const * buffer, sal_uInt32 length, bool copy,
      76             :         typereg_Version maxVersion)
      77             :     {
      78           0 :         if (!typereg_reader_create(buffer, length, copy, maxVersion, &m_handle))
      79             :         {
      80           0 :             throw std::bad_alloc();
      81             :         }
      82           0 :     }
      83             : 
      84             :     /**
      85             :        Shares a type reader between two <code>Reader</code> instances.
      86             : 
      87             :        @param other another <code>Reader</code> instance
      88             :      */
      89             :     Reader(Reader const & other): m_handle(other.m_handle) {
      90             :         typereg_reader_acquire(m_handle);
      91             :     }
      92             : 
      93             :     /**
      94             :        Destroys this <code>Reader</code> instance.
      95             : 
      96             :        <p>The underlying type reader is only destroyed if this instance was its
      97             :        last user.</p>
      98             :      */
      99           0 :     ~Reader() {
     100           0 :         typereg_reader_release(m_handle);
     101           0 :     }
     102             : 
     103             :     /**
     104             :        Replaces the underlying type reader.
     105             : 
     106             :        @param other any <code>Reader</code> instance
     107             : 
     108             :        @return this <code>Reader</code> instance
     109             :      */
     110             :     Reader & operator =(Reader const & other) {
     111             :         Reader temp(other);
     112             :         std::swap(this->m_handle, temp.m_handle);
     113             :         return *this;
     114             :     }
     115             : 
     116             :     /**
     117             :        Returns whether this type reader is valid.
     118             : 
     119             :        @return true iff this type reader is valid
     120             :      */
     121           0 :     bool isValid() const {
     122           0 :         return m_handle != 0;
     123             :     }
     124             : 
     125             :     /**
     126             :        Returns the binary blob version of this type reader.
     127             : 
     128             :        @return the version of the binary blob from which this type reader was
     129             :        constructed; if this type reader is invalid,
     130             :        <code>TYPEREG_VERSION_0</code> is returned
     131             :      */
     132           0 :     typereg_Version getVersion() const {
     133           0 :         return typereg_reader_getVersion(m_handle);
     134             :     }
     135             : 
     136             :     /**
     137             :        Returns the documentation of this type reader.
     138             : 
     139             :        @return the documentation of this type reader; if this type reader is
     140             :        invalid, an empty string is returned
     141             : 
     142             :        @exception std::bad_alloc is raised if an out-of-memory condition occurs
     143             :      */
     144           0 :     rtl::OUString getDocumentation() const {
     145           0 :         rtl_uString * s = 0;
     146           0 :         typereg_reader_getDocumentation(m_handle, &s);
     147           0 :         if (s == 0) {
     148           0 :             throw std::bad_alloc();
     149             :         }
     150           0 :         return rtl::OUString(s, SAL_NO_ACQUIRE);
     151             :     }
     152             : 
     153             :     /**
     154             :        Returns the file name of this type reader.
     155             : 
     156             :        @return the file name of this type reader; if this type reader is
     157             :        invalid, an empty string is returned
     158             : 
     159             :        @exception std::bad_alloc is raised if an out-of-memory condition occurs
     160             :        @deprecated
     161             :      */
     162           0 :     rtl::OUString getFileName() const {
     163           0 :         rtl_uString * s = 0;
     164           0 :         typereg_reader_getFileName(m_handle, &s);
     165           0 :         if (s == 0) {
     166           0 :             throw std::bad_alloc();
     167             :         }
     168           0 :         return rtl::OUString(s, SAL_NO_ACQUIRE);
     169             :     }
     170             : 
     171             :     /**
     172             :        Returns the type class of this type reader.
     173             : 
     174             :        <p>This function will always return the type class without the internal
     175             :        <code>RT_TYPE_PUBLISHED</code> flag set.  Use <code>isPublished</code> to
     176             :        determine whether this type reader is published.</p>
     177             : 
     178             :        @return the type class of this type reader; if this type reader is
     179             :        invalid, <code>RT_TYPE_INVALID</code> is returned
     180             :      */
     181           0 :     RTTypeClass getTypeClass() const {
     182           0 :         return typereg_reader_getTypeClass(m_handle);
     183             :     }
     184             : 
     185             :     /**
     186             :        Returns whether this type reader is published.
     187             : 
     188             :        @return whether this type reader is published; if this type reader is
     189             :        invalid, <code>false</code> is returned
     190             :      */
     191           0 :     bool isPublished() const {
     192           0 :         return typereg_reader_isPublished(m_handle);
     193             :     }
     194             : 
     195             :     /**
     196             :        Returns the type name of this type reader.
     197             : 
     198             :        @return the type name of this type reader; if this type reader is
     199             :        invalid, an empty string is returned
     200             : 
     201             :        @exception std::bad_alloc is raised if an out-of-memory condition occurs
     202             :      */
     203           0 :     rtl::OUString getTypeName() const {
     204           0 :         rtl_uString * s = 0;
     205           0 :         typereg_reader_getTypeName(m_handle, &s);
     206           0 :         if (s == 0) {
     207           0 :             throw std::bad_alloc();
     208             :         }
     209           0 :         return rtl::OUString(s, SAL_NO_ACQUIRE);
     210             :     }
     211             : 
     212             :     /**
     213             :        Returns the number of super types of this type reader.
     214             : 
     215             :        @return the number of super types of this type reader; if this type
     216             :        reader is invalid, zero is returned
     217             :      */
     218           0 :     sal_uInt16 getSuperTypeCount() const {
     219           0 :         return typereg_reader_getSuperTypeCount(m_handle);
     220             :     }
     221             : 
     222             :     /**
     223             :        Returns the type name of a super type of this type reader.
     224             : 
     225             :        @param index a valid index into the range of super types of this type
     226             :        reader
     227             : 
     228             :        @return the type name of the given super type
     229             : 
     230             :        @exception std::bad_alloc is raised if an out-of-memory condition occurs
     231             :      */
     232           0 :     rtl::OUString getSuperTypeName(sal_uInt16 index) const {
     233           0 :         rtl_uString * s = 0;
     234           0 :         typereg_reader_getSuperTypeName(m_handle, &s, index);
     235           0 :         if (s == 0) {
     236           0 :             throw std::bad_alloc();
     237             :         }
     238           0 :         return rtl::OUString(s, SAL_NO_ACQUIRE);
     239             :     }
     240             : 
     241             :     /**
     242             :        Returns the number of fields of this type reader.
     243             : 
     244             :        @return the number of fields of this type reader; if this type reader is
     245             :        invalid, zero is returned
     246             :      */
     247           0 :     sal_uInt16 getFieldCount() const {
     248           0 :         return typereg_reader_getFieldCount(m_handle);
     249             :     }
     250             : 
     251             :     /**
     252             :        Returns the documentation of a field of this type reader.
     253             : 
     254             :        @param index a valid index into the range of fields of this type reader
     255             : 
     256             :        @return the documentation of the given field
     257             : 
     258             :        @exception std::bad_alloc is raised if an out-of-memory condition occurs
     259             :      */
     260           0 :     rtl::OUString getFieldDocumentation(sal_uInt16 index) const {
     261           0 :         rtl_uString * s = 0;
     262           0 :         typereg_reader_getFieldDocumentation(m_handle, &s, index);
     263           0 :         if (s == 0) {
     264           0 :             throw std::bad_alloc();
     265             :         }
     266           0 :         return rtl::OUString(s, SAL_NO_ACQUIRE);
     267             :     }
     268             : 
     269             :     /**
     270             :        Returns the file name of a field of this type reader.
     271             : 
     272             :        @param index a valid index into the range of fields of this type reader
     273             : 
     274             :        @return the file name of the given field
     275             : 
     276             :        @exception std::bad_alloc is raised if an out-of-memory condition occurs
     277             :        @deprecated
     278             :      */
     279           0 :     rtl::OUString getFieldFileName(sal_uInt16 index) const {
     280           0 :         rtl_uString * s = 0;
     281           0 :         typereg_reader_getFieldFileName(m_handle, &s, index);
     282           0 :         if (s == 0) {
     283           0 :             throw std::bad_alloc();
     284             :         }
     285           0 :         return rtl::OUString(s, SAL_NO_ACQUIRE);
     286             :     }
     287             : 
     288             :     /**
     289             :        Returns the flags of a field of this type reader.
     290             : 
     291             :        @param index a valid index into the range of fields of this type reader
     292             : 
     293             :        @return the flags of the given field
     294             :      */
     295           0 :     RTFieldAccess getFieldFlags(sal_uInt16 index) const {
     296           0 :         return typereg_reader_getFieldFlags(m_handle, index);
     297             :     }
     298             : 
     299             :     /**
     300             :        Returns the name of a field of this type reader.
     301             : 
     302             :        @param index a valid index into the range of fields of this type reader
     303             : 
     304             :        @return the name of the given field
     305             : 
     306             :        @exception std::bad_alloc is raised if an out-of-memory condition occurs
     307             :      */
     308           0 :     rtl::OUString getFieldName(sal_uInt16 index) const {
     309           0 :         rtl_uString * s = 0;
     310           0 :         typereg_reader_getFieldName(m_handle, &s, index);
     311           0 :         if (s == 0) {
     312           0 :             throw std::bad_alloc();
     313             :         }
     314           0 :         return rtl::OUString(s, SAL_NO_ACQUIRE);
     315             :     }
     316             : 
     317             :     /**
     318             :        Returns the type name of a field of this type reader.
     319             : 
     320             :        @param index a valid index into the range of fields of this type reader
     321             : 
     322             :        @return the type name of the given field
     323             : 
     324             :        @exception std::bad_alloc is raised if an out-of-memory condition occurs
     325             :      */
     326           0 :     rtl::OUString getFieldTypeName(sal_uInt16 index) const {
     327           0 :         rtl_uString * s = 0;
     328           0 :         typereg_reader_getFieldTypeName(m_handle, &s, index);
     329           0 :         if (s == 0) {
     330           0 :             throw std::bad_alloc();
     331             :         }
     332           0 :         return rtl::OUString(s, SAL_NO_ACQUIRE);
     333             :     }
     334             : 
     335             :     /**
     336             :        Returns the value of a field of this type reader.
     337             : 
     338             :        @param index a valid index into the range of fields of this type reader
     339             : 
     340             :        @return the value of the given field
     341             : 
     342             :        @exception std::bad_alloc is raised if an out-of-memory condition occurs
     343             :      */
     344           0 :     RTConstValue getFieldValue(sal_uInt16 index) const {
     345           0 :         RTConstValue v;
     346           0 :         if (!typereg_reader_getFieldValue(
     347           0 :                 m_handle, index, &v.m_type, &v.m_value))
     348             :         {
     349           0 :             throw std::bad_alloc();
     350             :         }
     351           0 :         return v;
     352             :     }
     353             : 
     354             :     /**
     355             :        Returns the number of methods of this type reader.
     356             : 
     357             :        @return the number of methods of this type reader; if this type reader is
     358             :        invalid, zero is returned
     359             :      */
     360           0 :     sal_uInt16 getMethodCount() const {
     361           0 :         return typereg_reader_getMethodCount(m_handle);
     362             :     }
     363             : 
     364             :     /**
     365             :        Returns the documentation of a method of this type reader.
     366             : 
     367             :        @param index a valid index into the range of methods of this type reader
     368             : 
     369             :        @return the documentation of the given method
     370             : 
     371             :        @exception std::bad_alloc is raised if an out-of-memory condition occurs
     372             :      */
     373           0 :     rtl::OUString getMethodDocumentation(sal_uInt16 index) const {
     374           0 :         rtl_uString * s = 0;
     375           0 :         typereg_reader_getMethodDocumentation(m_handle, &s, index);
     376           0 :         if (s == 0) {
     377           0 :             throw std::bad_alloc();
     378             :         }
     379           0 :         return rtl::OUString(s, SAL_NO_ACQUIRE);
     380             :     }
     381             : 
     382             :     /**
     383             :        Returns the flags of a method of this type reader.
     384             : 
     385             :        @param index a valid index into the range of methods of this type reader
     386             : 
     387             :        @return the flags of the given method
     388             :      */
     389           0 :     RTMethodMode getMethodFlags(sal_uInt16 index) const {
     390           0 :         return typereg_reader_getMethodFlags(m_handle, index);
     391             :     }
     392             : 
     393             :     /**
     394             :        Returns the name of a method of this type reader.
     395             : 
     396             :        @param index a valid index into the range of methods of this type reader
     397             : 
     398             :        @return the name of the given method
     399             : 
     400             :        @exception std::bad_alloc is raised if an out-of-memory condition occurs
     401             :      */
     402           0 :     rtl::OUString getMethodName(sal_uInt16 index) const {
     403           0 :         rtl_uString * s = 0;
     404           0 :         typereg_reader_getMethodName(m_handle, &s, index);
     405           0 :         if (s == 0) {
     406           0 :             throw std::bad_alloc();
     407             :         }
     408           0 :         return rtl::OUString(s, SAL_NO_ACQUIRE);
     409             :     }
     410             : 
     411             :     /**
     412             :        Returns the return type name of a method of this type reader.
     413             : 
     414             :        @param index a valid index into the range of methods of this type reader
     415             : 
     416             :        @return the return type name of the given method
     417             : 
     418             :        @exception std::bad_alloc is raised if an out-of-memory condition occurs
     419             :      */
     420           0 :     rtl::OUString getMethodReturnTypeName(sal_uInt16 index) const {
     421           0 :         rtl_uString * s = 0;
     422           0 :         typereg_reader_getMethodReturnTypeName(m_handle, &s, index);
     423           0 :         if (s == 0) {
     424           0 :             throw std::bad_alloc();
     425             :         }
     426           0 :         return rtl::OUString(s, SAL_NO_ACQUIRE);
     427             :     }
     428             : 
     429             :     /**
     430             :        Returns the number of parameters of a method of this type reader.
     431             : 
     432             :        @param index a valid index into the range of methods of this type reader
     433             : 
     434             :        @return the number of parameters of the given method
     435             :      */
     436           0 :     sal_uInt16 getMethodParameterCount(sal_uInt16 index) const {
     437           0 :         return typereg_reader_getMethodParameterCount(m_handle, index);
     438             :     }
     439             : 
     440             :     /**
     441             :        Returns the flags of a parameter of a method of this type reader.
     442             : 
     443             :        @param methodIndex a valid index into the range of methods of this type
     444             :        reader
     445             : 
     446             :        @param parameterIndex a valid index into the range of parameters of the
     447             :        given method
     448             : 
     449             :        @return the flags of the given method parameter
     450             :      */
     451           0 :     RTParamMode getMethodParameterFlags(
     452             :         sal_uInt16 methodIndex, sal_uInt16 parameterIndex) const
     453             :     {
     454             :         return typereg_reader_getMethodParameterFlags(
     455           0 :             m_handle, methodIndex, parameterIndex);
     456             :     }
     457             : 
     458             :     /**
     459             :        Returns the name of a parameter of a method of this type reader.
     460             : 
     461             :        @param methodIndex a valid index into the range of methods of this type
     462             :        reader
     463             : 
     464             :        @param parameterIndex a valid index into the range of parameters of the
     465             :        given method
     466             : 
     467             :        @return the name of the given method parameter
     468             : 
     469             :        @exception std::bad_alloc is raised if an out-of-memory condition occurs
     470             :      */
     471           0 :     rtl::OUString getMethodParameterName(
     472             :         sal_uInt16 methodIndex, sal_uInt16 parameterIndex) const
     473             :     {
     474           0 :         rtl_uString * s = 0;
     475             :         typereg_reader_getMethodParameterName(
     476           0 :             m_handle, &s, methodIndex, parameterIndex);
     477           0 :         if (s == 0) {
     478           0 :             throw std::bad_alloc();
     479             :         }
     480           0 :         return rtl::OUString(s, SAL_NO_ACQUIRE);
     481             :     }
     482             : 
     483             :     /**
     484             :        Returns the type name of a parameter of a method of this type reader.
     485             : 
     486             :        @param methodIndex a valid index into the range of methods of this type
     487             :        reader
     488             : 
     489             :        @param parameterIndex a valid index into the range of parameters of the
     490             :        given method
     491             : 
     492             :        @return the type name of the given method parameter
     493             : 
     494             :        @exception std::bad_alloc is raised if an out-of-memory condition occurs
     495             :      */
     496           0 :     rtl::OUString getMethodParameterTypeName(
     497             :         sal_uInt16 methodIndex, sal_uInt16 parameterIndex) const
     498             :     {
     499           0 :         rtl_uString * s = 0;
     500             :         typereg_reader_getMethodParameterTypeName(
     501           0 :             m_handle, &s, methodIndex, parameterIndex);
     502           0 :         if (s == 0) {
     503           0 :             throw std::bad_alloc();
     504             :         }
     505           0 :         return rtl::OUString(s, SAL_NO_ACQUIRE);
     506             :     }
     507             : 
     508             :     /**
     509             :        Returns the number of exceptions of a method of this type reader.
     510             : 
     511             :        @param index a valid index into the range of methods of this type reader
     512             : 
     513             :        @return the number of exceptions of the given method
     514             :      */
     515           0 :     sal_uInt16 getMethodExceptionCount(sal_uInt16 index) const {
     516           0 :         return typereg_reader_getMethodExceptionCount(m_handle, index);
     517             :     }
     518             : 
     519             :     /**
     520             :        Returns the type name of an exception of a method of this type reader.
     521             : 
     522             :        @param methodIndex a valid index into the range of methods of this type
     523             :        reader
     524             : 
     525             :        @param exceptionIndex a valid index into the range of exceptions of the
     526             :        given method
     527             : 
     528             :        @return the type name of the given method exception
     529             : 
     530             :        @exception std::bad_alloc is raised if an out-of-memory condition occurs
     531             :      */
     532           0 :     rtl::OUString getMethodExceptionTypeName(
     533             :         sal_uInt16 methodIndex, sal_uInt16 exceptionIndex) const
     534             :     {
     535           0 :         rtl_uString * s = 0;
     536             :         typereg_reader_getMethodExceptionTypeName(
     537           0 :             m_handle, &s, methodIndex, exceptionIndex);
     538           0 :         if (s == 0) {
     539           0 :             throw std::bad_alloc();
     540             :         }
     541           0 :         return rtl::OUString(s, SAL_NO_ACQUIRE);
     542             :     }
     543             : 
     544             :     /**
     545             :        Returns the number of references of this type reader.
     546             : 
     547             :        @return the number of references of this type reader; if this type reader
     548             :        is invalid, zero is returned
     549             :      */
     550           0 :     sal_uInt16 getReferenceCount() const {
     551           0 :         return typereg_reader_getReferenceCount(m_handle);
     552             :     }
     553             : 
     554             :     /**
     555             :        Returns the documentation of a reference of this type reader.
     556             : 
     557             :        @param index a valid index into the range of references of this type
     558             :        reader
     559             : 
     560             :        @return the documentation of the given reference
     561             : 
     562             :        @exception std::bad_alloc is raised if an out-of-memory condition occurs
     563             :      */
     564           0 :     rtl::OUString getReferenceDocumentation(sal_uInt16 index) const {
     565           0 :         rtl_uString * s = 0;
     566           0 :         typereg_reader_getReferenceDocumentation(m_handle, &s, index);
     567           0 :         if (s == 0) {
     568           0 :             throw std::bad_alloc();
     569             :         }
     570           0 :         return rtl::OUString(s, SAL_NO_ACQUIRE);
     571             :     }
     572             : 
     573             :     /**
     574             :        Returns the flags of a reference of this type reader.
     575             : 
     576             :        @param index a valid index into the range of references of this type
     577             :        reader
     578             : 
     579             :        @return the flags of the given reference
     580             :      */
     581           0 :     RTFieldAccess getReferenceFlags(sal_uInt16 index) const {
     582           0 :         return typereg_reader_getReferenceFlags(m_handle, index);
     583             :     }
     584             : 
     585             :     /**
     586             :        Returns the sort of a reference of this type reader.
     587             : 
     588             :        @param index a valid index into the range of references of this type
     589             :        reader
     590             : 
     591             :        @return the sort of the given reference
     592             :      */
     593           0 :     RTReferenceType getReferenceSort(sal_uInt16 index) const {
     594           0 :         return typereg_reader_getReferenceSort(m_handle, index);
     595             :     }
     596             : 
     597             :     /**
     598             :        Returns the type name of a reference of this type reader.
     599             : 
     600             :        @param index a valid index into the range of references of this type
     601             :        reader
     602             : 
     603             :        @return the type name of the given reference
     604             : 
     605             :        @exception std::bad_alloc is raised if an out-of-memory condition occurs
     606             :      */
     607           0 :     rtl::OUString getReferenceTypeName(sal_uInt16 index) const {
     608           0 :         rtl_uString * s = 0;
     609           0 :         typereg_reader_getReferenceTypeName(m_handle, &s, index);
     610           0 :         if (s == 0) {
     611           0 :             throw std::bad_alloc();
     612             :         }
     613           0 :         return rtl::OUString(s, SAL_NO_ACQUIRE);
     614             :     }
     615             : 
     616             : private:
     617             :     void * m_handle;
     618             : };
     619             : 
     620             : }
     621             : 
     622             : #endif
     623             : 
     624             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10