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

Generated by: LCOV version 1.10