LCOV - code coverage report
Current view: top level - libreoffice/forms/source/xforms - datatypes.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 12 0.0 %
Date: 2012-12-27 Functions: 0 44 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 FORMS_SOURCE_XFORMS_DATATYPES_HXX
      21             : #define FORMS_SOURCE_XFORMS_DATATYPES_HXX
      22             : 
      23             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      24             : #include <com/sun/star/util/Date.hpp>
      25             : #include <com/sun/star/util/Time.hpp>
      26             : #include <com/sun/star/util/DateTime.hpp>
      27             : #include <com/sun/star/xsd/XDataType.hpp>
      28             : #include <com/sun/star/xsd/DataTypeClass.hpp>
      29             : #include <cppuhelper/implbase1.hxx>
      30             : #include <comphelper/uno3.hxx>
      31             : #include <comphelper/propertycontainer.hxx>
      32             : #include <comphelper/proparrhlp.hxx>
      33             : #include <comphelper/broadcasthelper.hxx>
      34             : #include "warnings_guard_unicode_regex.h"
      35             : 
      36             : #include <memory>
      37             : 
      38             : //........................................................................
      39             : namespace xforms
      40             : {
      41             : //........................................................................
      42             : 
      43             :     //====================================================================
      44             :     //= OXSDDataType
      45             :     //====================================================================
      46             :     typedef ::cppu::WeakImplHelper1             <   ::com::sun::star::xsd::XDataType
      47             :                                                 >   OXSDDataType_Base;
      48             :     typedef ::comphelper::OMutexAndBroadcastHelper  OXSDDataType_BBase;
      49             :     typedef ::comphelper::OPropertyContainer        OXSDDataType_PBase;
      50             : 
      51             :     class OXSDDataType  :public OXSDDataType_Base
      52             :                         ,public OXSDDataType_BBase         // order matters: OMutexAndBroadcastHelper before
      53             :                         ,public OXSDDataType_PBase         // OPropertyContainer
      54             :     {
      55             :     private:
      56             :         // <properties>
      57             :         sal_Bool        m_bIsBasic;
      58             :         sal_Int16       m_nTypeClass;
      59             :         ::rtl::OUString m_sName;
      60             :         ::rtl::OUString m_sPattern;
      61             :         sal_uInt16      m_nWST;
      62             :         // </properties>
      63             : 
      64             :         ::std::auto_ptr< U_NAMESPACE_QUALIFIER RegexMatcher >
      65             :                         m_pPatternMatcher;
      66             :         bool            m_bPatternMatcherDirty;
      67             : 
      68             :     protected:
      69             : 
      70             :         sal_Bool    isBasic() const         { return m_bIsBasic; }
      71           0 :         sal_Int16   getTypeClass() const    { return m_nTypeClass; }
      72             :         const ::rtl::OUString&
      73             :                     getName() const         { return m_sName; }
      74             : 
      75             :     private:
      76             :         OXSDDataType( );                                    // never implemented
      77             :         OXSDDataType( const OXSDDataType& );                // never implemented
      78             :         OXSDDataType& operator=( const OXSDDataType& );     // never implemented
      79             : 
      80             :     protected:
      81             :         // create basic data type
      82             :         OXSDDataType( const ::rtl::OUString& _rName, sal_Int16 _nTypeClass );
      83             :         ~OXSDDataType();
      84             : 
      85             :     public:
      86             :         DECLARE_XINTERFACE()
      87             :         DECLARE_XTYPEPROVIDER()
      88             : 
      89             :         virtual ::rtl::OUString SAL_CALL getName(  ) throw (::com::sun::star::uno::RuntimeException);
      90             :         virtual void SAL_CALL setName( const ::rtl::OUString& aName ) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::util::VetoException);
      91             :         virtual ::rtl::OUString SAL_CALL getPattern() throw (::com::sun::star::uno::RuntimeException);
      92             :         virtual void SAL_CALL setPattern( const ::rtl::OUString& _pattern ) throw (::com::sun::star::uno::RuntimeException);
      93             :         virtual sal_Int16 SAL_CALL getWhiteSpaceTreatment() throw (::com::sun::star::uno::RuntimeException);
      94             :         virtual void SAL_CALL setWhiteSpaceTreatment( sal_Int16 _whitespacetreatment ) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException);
      95             :         virtual sal_Bool SAL_CALL getIsBasic() throw (::com::sun::star::uno::RuntimeException);
      96             :         virtual sal_Int16 SAL_CALL getTypeClass() throw (::com::sun::star::uno::RuntimeException);
      97             : 
      98             :         virtual sal_Bool SAL_CALL validate( const ::rtl::OUString& value ) throw (::com::sun::star::uno::RuntimeException);
      99             :         virtual ::rtl::OUString SAL_CALL explainInvalid( const ::rtl::OUString& value ) throw (::com::sun::star::uno::RuntimeException);
     100             : 
     101             :         // XPropertySet - is a base of XDataType and needs to be disambiguated
     102             :         virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
     103             :         virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
     104             :         virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
     105             :         virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
     106             :         virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
     107             :         virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
     108             : 
     109             :     public:
     110             :         OXSDDataType* clone( const ::rtl::OUString& _rNewName ) const;
     111             : 
     112             :     protected:
     113             :         // XPropertySet and friends
     114             :         virtual sal_Bool SAL_CALL   convertFastPropertyValue( ::com::sun::star::uno::Any& _rConvertedValue, ::com::sun::star::uno::Any& _rOldValue, sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rValue ) throw(::com::sun::star::lang::IllegalArgumentException);
     115             :         virtual void SAL_CALL       setFastPropertyValue_NoBroadcast(
     116             :                                         sal_Int32 nHandle,
     117             :                                         const ::com::sun::star::uno::Any& rValue
     118             :                                     )
     119             :                                     throw (::com::sun::star::uno::Exception);
     120             : 
     121             :         // --- own overridables ---
     122             :         // helper for implementing cloning of data types
     123             :         virtual OXSDDataType*   createClone( const ::rtl::OUString& _rName ) const = 0;
     124             :         virtual void            initializeClone( const OXSDDataType& _rCloneSource );
     125             : 
     126             :         // helper method for validate and explainInvalid
     127             :         virtual sal_uInt16  _validate( const ::rtl::OUString& value );
     128             :         virtual ::rtl::OUString _explainInvalid( sal_uInt16 nReason );
     129             : 
     130             :         // helper method for checking properties values which are to be set
     131             :         virtual bool        checkPropertySanity( sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rNewValue, ::rtl::OUString& _rErrorMessage );
     132             : 
     133             :         // register properties implemented by this instance - call the base class when overriding
     134             :         virtual void        registerProperties();
     135             :     };
     136             : 
     137             :     //====================================================================
     138             :     //= helper for deriving from OXSDDataType
     139             :     //====================================================================
     140             : #define DECLARE_DEFAULT_CLONING( classname )        \
     141             :     virtual OXSDDataType* createClone( const ::rtl::OUString& _rName ) const;    \
     142             :     virtual void       initializeClone( const OXSDDataType& _rCloneSource ); \
     143             :             void       initializeTypedClone( const classname& _rCloneSource );
     144             : 
     145             : #define IMPLEMENT_DEFAULT_CLONING( classname, baseclass )   \
     146             :     OXSDDataType* classname::createClone( const ::rtl::OUString& _rName ) const              \
     147             :     {                                                       \
     148             :         return new classname( _rName );                     \
     149             :     }                                                       \
     150             :     void classname::initializeClone( const OXSDDataType& _rCloneSource ) \
     151             :     { \
     152             :         baseclass::initializeClone( _rCloneSource );        \
     153             :         initializeTypedClone( static_cast< const classname& >( _rCloneSource ) ); \
     154             :     } \
     155             : 
     156             : #define IMPLEMENT_DEFAULT_TYPED_CLONING( classname, baseclass )   \
     157             :     OXSDDataType* classname::createClone( const ::rtl::OUString& _rName ) const              \
     158             :     {                                                       \
     159             :         return new classname( _rName, getTypeClass() );     \
     160             :     }                                                       \
     161             :     void classname::initializeClone( const OXSDDataType& _rCloneSource ) \
     162             :     { \
     163             :         baseclass::initializeClone( _rCloneSource );        \
     164             :         initializeTypedClone( static_cast< const classname& >( _rCloneSource ) ); \
     165             :     } \
     166             : 
     167             : #define REGISTER_VOID_PROP( prop, memberAny, type ) \
     168             :     registerMayBeVoidProperty( PROPERTY_##prop, PROPERTY_ID_##prop, ::com::sun::star::beans::PropertyAttribute::BOUND | ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, \
     169             :         &memberAny, ::getCppuType( static_cast< type* >( NULL ) ) );
     170             : 
     171             :     //====================================================================
     172             :     //= OValueLimitedType_Base
     173             :     //====================================================================
     174           0 :     class OValueLimitedType_Base : public OXSDDataType
     175             :     {
     176             :     protected:
     177             :         ::com::sun::star::uno::Any m_aMaxInclusive;
     178             :         ::com::sun::star::uno::Any m_aMaxExclusive;
     179             :         ::com::sun::star::uno::Any m_aMinInclusive;
     180             :         ::com::sun::star::uno::Any m_aMinExclusive;
     181             : 
     182             :         double  m_fCachedMaxInclusive;
     183             :         double  m_fCachedMaxExclusive;
     184             :         double  m_fCachedMinInclusive;
     185             :         double  m_fCachedMinExclusive;
     186             : 
     187             :     protected:
     188             :         OValueLimitedType_Base( const ::rtl::OUString& _rName, sal_Int16 _nTypeClass );
     189             : 
     190             :         virtual void       initializeClone( const OXSDDataType& _rCloneSource );
     191             :                 void       initializeTypedClone( const OValueLimitedType_Base& _rCloneSource );
     192             : 
     193             :         // XPropertySet and friends
     194             :         virtual void SAL_CALL       setFastPropertyValue_NoBroadcast(
     195             :                                         sal_Int32 nHandle,
     196             :                                         const ::com::sun::star::uno::Any& rValue
     197             :                                     )
     198             :                                     throw (::com::sun::star::uno::Exception);
     199             : 
     200             :         // OXSDDataType overridables
     201             :         virtual bool            _getValue( const ::rtl::OUString& value, double& fValue );
     202             :         virtual sal_uInt16      _validate( const ::rtl::OUString& value );
     203             :         virtual ::rtl::OUString _explainInvalid( sal_uInt16 nReason );
     204             : 
     205             :         // own overridables
     206             :         /** translate a given value into a human-readable string
     207             : 
     208             :             The value is guaranteed to be not <NULL/>, and is of type <member>ValueType</member>
     209             :         */
     210             :         virtual ::rtl::OUString typedValueAsHumanReadableString( const ::com::sun::star::uno::Any& _rValue ) const = 0;
     211             : 
     212             :         /** translates a <member>ValueType</member> value into a double value
     213             : 
     214             :             The normalization must respect the "<" and "==" relations on the value
     215             :             space. That is, if two values are equal, their normalizations must be equal, too.
     216             :             Similarily, if <code>foo</code> is less than <code>bar</code>, the same
     217             :             must hold for their normalizations.
     218             : 
     219             :             @param _rValue
     220             :                 the value to translate. Guranteed to be not <NULL/>, and of type <member>ValueType</member>
     221             :             @param _rDoubleValue
     222             :                 output parameter to hold the resulting double value
     223             :         */
     224             :         virtual void normalizeValue( const ::com::sun::star::uno::Any& _rValue, double& _rDoubleValue ) const = 0;
     225             :     };
     226             : 
     227             :     //====================================================================
     228             :     //= OValueLimitedType
     229             :     //====================================================================
     230             :     template < typename VALUE_TYPE >
     231           0 :     class OValueLimitedType : public OValueLimitedType_Base
     232             :     {
     233             :     protected:
     234             :         typedef     VALUE_TYPE  ValueType;
     235             :         inline const ::com::sun::star::uno::Type&
     236           0 :             getCppuType() const { return ::getCppuType( static_cast< ValueType* >( NULL ) ); }
     237             : 
     238             :     protected:
     239             :         OValueLimitedType( const ::rtl::OUString& _rName, sal_Int16 _nTypeClass );
     240             : 
     241             :         // OXSDDataType overridables
     242             :         virtual void            registerProperties();
     243             :     };
     244             : 
     245             :     //====================================================================
     246             :     //= ODerivedDataType
     247             :     //====================================================================
     248             :     /** helper class for implementing interfaces derived from XDataType
     249             :     */
     250             :     template< typename CONCRETE_DATA_TYPE_IMPL, typename SUPERCLASS = OXSDDataType >
     251           0 :     class ODerivedDataType  :public SUPERCLASS
     252             :                             ,::comphelper::OPropertyArrayUsageHelper< CONCRETE_DATA_TYPE_IMPL >
     253             :     {
     254             :     private:
     255             :         bool    m_bPropertiesRegistered;
     256             : 
     257             :     protected:
     258             :         ODerivedDataType( const ::rtl::OUString& _rName, sal_Int16 _nTypeClass );
     259             : 
     260             :     protected:
     261             :         // OPropertyArrayUsageHelper
     262             :         virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
     263             : 
     264             :         // XPropertySet
     265             :         virtual com::sun::star::uno::Reference<com::sun::star::beans::XPropertySetInfo>  SAL_CALL getPropertySetInfo() throw(com::sun::star::uno::RuntimeException);
     266             :         virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
     267             :     };
     268             : 
     269             :     //====================================================================
     270             :     //= OBooleanType
     271             :     //====================================================================
     272             :     class OBooleanType;
     273             :     typedef ODerivedDataType< OBooleanType > OBooleanType_Base;
     274           0 :     class OBooleanType : public OBooleanType_Base
     275             :     {
     276             :     public:
     277             :         OBooleanType( const ::rtl::OUString& _rName );
     278             : 
     279             :     protected:
     280             :         DECLARE_DEFAULT_CLONING( OBooleanType )
     281             : 
     282             :         // OXSDDataType overridables
     283             :         virtual sal_uInt16      _validate( const ::rtl::OUString& value );
     284             :         virtual ::rtl::OUString _explainInvalid( sal_uInt16 nReason );
     285             :     };
     286             : 
     287             :     //====================================================================
     288             :     //= OStringType
     289             :     //====================================================================
     290             :     class OStringType;
     291             :     typedef ODerivedDataType< OStringType > OStringType_Base;
     292           0 :     class OStringType   :public OStringType_Base
     293             :     {
     294             :     protected:
     295             :         // <properties>
     296             :         ::com::sun::star::uno::Any m_aLength;
     297             :         ::com::sun::star::uno::Any m_aMinLength;
     298             :         ::com::sun::star::uno::Any m_aMaxLength;
     299             :         // </properties>
     300             : 
     301             :     public:
     302             :         OStringType( const ::rtl::OUString& _rName, sal_Int16 _nTypeClass /* = ::com::sun::star::xsd::DataTypeClass::STRING */ );
     303             : 
     304             :     protected:
     305             :         DECLARE_DEFAULT_CLONING( OStringType )
     306             : 
     307             :         // OXSDDataType overridables
     308             :         virtual sal_uInt16      _validate( const ::rtl::OUString& value );
     309             :         virtual ::rtl::OUString _explainInvalid( sal_uInt16 nReason );
     310             :         virtual bool            checkPropertySanity( sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rNewValue, ::rtl::OUString& _rErrorMessage );
     311             :         virtual void            registerProperties();
     312             :     };
     313             : 
     314             :     //====================================================================
     315             :     //= ODecimalType
     316             :     //====================================================================
     317             :     class ODecimalType;
     318             :     typedef ODerivedDataType< ODecimalType, OValueLimitedType< double > > ODecimalType_Base;
     319           0 :     class ODecimalType : public ODecimalType_Base
     320             :     {
     321             :     protected:
     322             :         ::com::sun::star::uno::Any m_aTotalDigits;
     323             :         ::com::sun::star::uno::Any m_aFractionDigits;
     324             : 
     325             :     public:
     326             :         ODecimalType( const ::rtl::OUString& _rName, sal_Int16 _nTypeClass /* = ::com::sun::star::xsd::DataTypeClass::DECIMAL */ );
     327             : 
     328             :     protected:
     329             :         DECLARE_DEFAULT_CLONING( ODecimalType )
     330             : 
     331             :         // OXSDDataType overridables
     332             :         virtual sal_uInt16      _validate( const ::rtl::OUString& value );
     333             :         virtual ::rtl::OUString _explainInvalid( sal_uInt16 nReason );
     334             :         virtual void            registerProperties();
     335             : 
     336             :         // OValueLimitedType overridables
     337             :         virtual ::rtl::OUString typedValueAsHumanReadableString( const ::com::sun::star::uno::Any& _rValue ) const;
     338             :         virtual void normalizeValue( const ::com::sun::star::uno::Any& _rValue, double& _rDoubleValue ) const;
     339             : 
     340             :     private:
     341             :         using ODecimalType_Base::initializeTypedClone;
     342             :     };
     343             : 
     344             :     //====================================================================
     345             :     //=
     346             :     //====================================================================
     347             : #define DEFAULT_DECLARE_SUBTYPE( classname, valuetype )         \
     348             :     class classname;                                            \
     349             :     typedef ODerivedDataType< classname, OValueLimitedType< valuetype > > classname##_Base;  \
     350             :     class classname : public classname##_Base                   \
     351             :     {                                                           \
     352             :     public:                                                     \
     353             :         classname( const ::rtl::OUString& _rName );             \
     354             :                                                                 \
     355             :     protected:                                                  \
     356             :         DECLARE_DEFAULT_CLONING( classname )                    \
     357             :                                                                 \
     358             :         /* OXSDDataType overridables */                         \
     359             :         virtual sal_uInt16          _validate( const ::rtl::OUString& value );  \
     360             :         virtual bool                _getValue( const ::rtl::OUString& value, double& fValue );  \
     361             :                                                                 \
     362             :         /* OValueLimitedType overridables */                    \
     363             :         virtual ::rtl::OUString     typedValueAsHumanReadableString( const ::com::sun::star::uno::Any& _rValue ) const;  \
     364             :         virtual void normalizeValue( const ::com::sun::star::uno::Any& _rValue, double& _rDoubleValue ) const; \
     365             :                                                                 \
     366             :     private:                                                    \
     367             :         using classname##_Base::initializeTypedClone;          \
     368             :     };
     369             : 
     370             :     //====================================================================
     371             :     //= ODateType
     372             :     //====================================================================
     373           0 :     DEFAULT_DECLARE_SUBTYPE( ODateType, ::com::sun::star::util::Date )
     374             : 
     375             :     //====================================================================
     376             :     //= OTimeType
     377             :     //====================================================================
     378           0 :     DEFAULT_DECLARE_SUBTYPE( OTimeType, ::com::sun::star::util::Time )
     379             : 
     380             :     //====================================================================
     381             :     //= ODateTimeType
     382             :     //====================================================================
     383           0 :     DEFAULT_DECLARE_SUBTYPE( ODateTimeType, ::com::sun::star::util::DateTime )
     384             : 
     385             :     //====================================================================
     386             :     //= OShortIntegerType
     387             :     //====================================================================
     388             :     class OShortIntegerType;
     389             :     typedef ODerivedDataType< OShortIntegerType, OValueLimitedType< sal_Int16 > > OShortIntegerType_Base;
     390           0 :     class OShortIntegerType : public OShortIntegerType_Base
     391             :     {
     392             :     public:
     393             :         OShortIntegerType( const ::rtl::OUString& _rName, sal_Int16 _nTypeClass );
     394             : 
     395             :     protected:
     396             :         DECLARE_DEFAULT_CLONING( OShortIntegerType )
     397             : 
     398             :         // OXSDDataType overridables
     399             :         virtual bool            _getValue( const ::rtl::OUString& value, double& fValue );
     400             : 
     401             :         // OValueLimitedType overridables
     402             :         virtual ::rtl::OUString typedValueAsHumanReadableString( const ::com::sun::star::uno::Any& _rValue ) const;
     403             :         virtual void normalizeValue( const ::com::sun::star::uno::Any& _rValue, double& _rDoubleValue ) const;
     404             : 
     405             :     private:
     406             :         using OShortIntegerType_Base::initializeTypedClone;
     407             :     };
     408             : 
     409             : //........................................................................
     410             : } // namespace xforms
     411             : //........................................................................
     412             : 
     413             : #endif // FORMS_SOURCE_XFORMS_DATATYPES_HXX
     414             : 
     415             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10