LCOV - code coverage report
Current view: top level - forms/source/xforms - datatypes.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 12 0.0 %
Date: 2014-11-03 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             :         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::unique_ptr< U_NAMESPACE_QUALIFIER RegexMatcher >
      66             :                         m_pPatternMatcher;
      67             :         bool            m_bPatternMatcherDirty;
      68             : 
      69             :     protected:
      70             : 
      71             :         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           0 :     class OValueLimitedType_Base : public OXSDDataType
     173             :     {
     174             :     protected:
     175             :         ::com::sun::star::uno::Any m_aMaxInclusive;
     176             :         ::com::sun::star::uno::Any m_aMaxExclusive;
     177             :         ::com::sun::star::uno::Any m_aMinInclusive;
     178             :         ::com::sun::star::uno::Any m_aMinExclusive;
     179             : 
     180             :         double  m_fCachedMaxInclusive;
     181             :         double  m_fCachedMaxExclusive;
     182             :         double  m_fCachedMinInclusive;
     183             :         double  m_fCachedMinExclusive;
     184             : 
     185             :     protected:
     186             :         OValueLimitedType_Base( const OUString& _rName, sal_Int16 _nTypeClass );
     187             : 
     188             :         virtual void       initializeClone( const OXSDDataType& _rCloneSource ) SAL_OVERRIDE;
     189             :                 void       initializeTypedClone( const OValueLimitedType_Base& _rCloneSource );
     190             : 
     191             :         // XPropertySet and friends
     192             :         virtual void SAL_CALL       setFastPropertyValue_NoBroadcast(
     193             :                                         sal_Int32 nHandle,
     194             :                                         const ::com::sun::star::uno::Any& rValue
     195             :                                     )
     196             :                                     throw (::com::sun::star::uno::Exception, std::exception) SAL_OVERRIDE;
     197             : 
     198             :         // OXSDDataType overridables
     199             :         virtual bool            _getValue( const OUString& value, double& fValue );
     200             :         virtual sal_uInt16      _validate( const OUString& value ) SAL_OVERRIDE;
     201             :         virtual OUString _explainInvalid( sal_uInt16 nReason ) SAL_OVERRIDE;
     202             : 
     203             :         // own overridables
     204             :         /** translate a given value into a human-readable string
     205             : 
     206             :             The value is guaranteed to be not <NULL/>, and is of type <member>ValueType</member>
     207             :         */
     208             :         virtual OUString typedValueAsHumanReadableString( const ::com::sun::star::uno::Any& _rValue ) const = 0;
     209             : 
     210             :         /** translates a <member>ValueType</member> value into a double value
     211             : 
     212             :             The normalization must respect the "<" and "==" relations on the value
     213             :             space. That is, if two values are equal, their normalizations must be equal, too.
     214             :             Similarly, if <code>foo</code> is less than <code>bar</code>, the same
     215             :             must hold for their normalizations.
     216             : 
     217             :             @param _rValue
     218             :                 the value to translate. Guaranteed to be not <NULL/>, and of type <member>ValueType</member>
     219             :             @param _rDoubleValue
     220             :                 output parameter to hold the resulting double value
     221             :         */
     222             :         virtual void normalizeValue( const ::com::sun::star::uno::Any& _rValue, double& _rDoubleValue ) const = 0;
     223             :     };
     224             : 
     225             :     template < typename VALUE_TYPE >
     226           0 :     class OValueLimitedType : public OValueLimitedType_Base
     227             :     {
     228             :     protected:
     229             :         typedef     VALUE_TYPE  ValueType;
     230             :         inline const ::com::sun::star::uno::Type&
     231           0 :             getCppuType() const { return cppu::UnoType<ValueType>::get(); }
     232             : 
     233             :     protected:
     234             :         OValueLimitedType( const OUString& _rName, sal_Int16 _nTypeClass );
     235             : 
     236             :         // OXSDDataType overridables
     237             :         virtual void            registerProperties() SAL_OVERRIDE;
     238             :     };
     239             : 
     240             :     /** helper class for implementing interfaces derived from XDataType
     241             :     */
     242             :     template< typename CONCRETE_DATA_TYPE_IMPL, typename SUPERCLASS = OXSDDataType >
     243           0 :     class ODerivedDataType  :public SUPERCLASS
     244             :                             ,::comphelper::OPropertyArrayUsageHelper< CONCRETE_DATA_TYPE_IMPL >
     245             :     {
     246             :     private:
     247             :         bool    m_bPropertiesRegistered;
     248             : 
     249             :     protected:
     250             :         ODerivedDataType( const OUString& _rName, sal_Int16 _nTypeClass );
     251             : 
     252             :     protected:
     253             :         // OPropertyArrayUsageHelper
     254             :         virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
     255             : 
     256             :         // XPropertySet
     257             :         virtual com::sun::star::uno::Reference<com::sun::star::beans::XPropertySetInfo>  SAL_CALL getPropertySetInfo() throw(com::sun::star::uno::RuntimeException);
     258             :         virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
     259             :     };
     260             : 
     261             :     class OBooleanType;
     262             :     typedef ODerivedDataType< OBooleanType > OBooleanType_Base;
     263           0 :     class OBooleanType : public OBooleanType_Base
     264             :     {
     265             :     public:
     266             :         OBooleanType( const OUString& _rName );
     267             : 
     268             :     protected:
     269             :         DECLARE_DEFAULT_CLONING( OBooleanType )
     270             : 
     271             :         // OXSDDataType overridables
     272             :         virtual sal_uInt16      _validate( const OUString& value ) SAL_OVERRIDE;
     273             :         virtual OUString _explainInvalid( sal_uInt16 nReason ) SAL_OVERRIDE;
     274             :     };
     275             : 
     276             :     class OStringType;
     277             :     typedef ODerivedDataType< OStringType > OStringType_Base;
     278           0 :     class OStringType   :public OStringType_Base
     279             :     {
     280             :     protected:
     281             :         // <properties>
     282             :         ::com::sun::star::uno::Any m_aLength;
     283             :         ::com::sun::star::uno::Any m_aMinLength;
     284             :         ::com::sun::star::uno::Any m_aMaxLength;
     285             :         // </properties>
     286             : 
     287             :     public:
     288             :         OStringType( const OUString& _rName, sal_Int16 _nTypeClass /* = ::com::sun::star::xsd::DataTypeClass::STRING */ );
     289             : 
     290             :     protected:
     291             :         DECLARE_DEFAULT_CLONING( OStringType )
     292             : 
     293             :         // OXSDDataType overridables
     294             :         virtual sal_uInt16      _validate( const OUString& value ) SAL_OVERRIDE;
     295             :         virtual OUString _explainInvalid( sal_uInt16 nReason ) SAL_OVERRIDE;
     296             :         virtual bool            checkPropertySanity( sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rNewValue, OUString& _rErrorMessage ) SAL_OVERRIDE;
     297             :         virtual void            registerProperties() SAL_OVERRIDE;
     298             :     };
     299             : 
     300             :     class ODecimalType;
     301             :     typedef ODerivedDataType< ODecimalType, OValueLimitedType< double > > ODecimalType_Base;
     302           0 :     class ODecimalType : public ODecimalType_Base
     303             :     {
     304             :     protected:
     305             :         ::com::sun::star::uno::Any m_aTotalDigits;
     306             :         ::com::sun::star::uno::Any m_aFractionDigits;
     307             : 
     308             :     public:
     309             :         ODecimalType( const OUString& _rName, sal_Int16 _nTypeClass /* = ::com::sun::star::xsd::DataTypeClass::DECIMAL */ );
     310             : 
     311             :     protected:
     312             :         DECLARE_DEFAULT_CLONING( ODecimalType )
     313             : 
     314             :         // OXSDDataType overridables
     315             :         virtual sal_uInt16      _validate( const OUString& value ) SAL_OVERRIDE;
     316             :         virtual OUString _explainInvalid( sal_uInt16 nReason ) SAL_OVERRIDE;
     317             :         virtual void            registerProperties() SAL_OVERRIDE;
     318             : 
     319             :         // OValueLimitedType overridables
     320             :         virtual OUString typedValueAsHumanReadableString( const ::com::sun::star::uno::Any& _rValue ) const SAL_OVERRIDE;
     321             :         virtual void normalizeValue( const ::com::sun::star::uno::Any& _rValue, double& _rDoubleValue ) const SAL_OVERRIDE;
     322             : 
     323             :     private:
     324             :         using ODecimalType_Base::initializeTypedClone;
     325             :     };
     326             : 
     327             : 
     328             :     //=
     329             : 
     330             : #define DEFAULT_DECLARE_SUBTYPE( classname, valuetype )         \
     331             :     class classname;                                            \
     332             :     typedef ODerivedDataType< classname, OValueLimitedType< valuetype > > classname##_Base;  \
     333             :     class classname : public classname##_Base                   \
     334             :     {                                                           \
     335             :     public:                                                     \
     336             :         classname( const OUString& _rName );             \
     337             :                                                                 \
     338             :     protected:                                                  \
     339             :         DECLARE_DEFAULT_CLONING( classname )                    \
     340             :                                                                 \
     341             :         /* OXSDDataType overridables */                         \
     342             :         virtual sal_uInt16          _validate( const OUString& value ) SAL_OVERRIDE;  \
     343             :         virtual bool                _getValue( const OUString& value, double& fValue ) SAL_OVERRIDE;  \
     344             :                                                                 \
     345             :         /* OValueLimitedType overridables */                    \
     346             :         virtual OUString     typedValueAsHumanReadableString( const ::com::sun::star::uno::Any& _rValue ) const SAL_OVERRIDE;  \
     347             :         virtual void normalizeValue( const ::com::sun::star::uno::Any& _rValue, double& _rDoubleValue ) const SAL_OVERRIDE; \
     348             :                                                                 \
     349             :     private:                                                    \
     350             :         using classname##_Base::initializeTypedClone;          \
     351             :     };
     352             : 
     353             : 
     354             :     //= ODateType
     355             : 
     356           0 :     DEFAULT_DECLARE_SUBTYPE( ODateType, ::com::sun::star::util::Date )
     357             : 
     358             : 
     359             :     //= OTimeType
     360             : 
     361           0 :     DEFAULT_DECLARE_SUBTYPE( OTimeType, ::com::sun::star::util::Time )
     362             : 
     363             : 
     364             :     //= ODateTimeType
     365             : 
     366           0 :     DEFAULT_DECLARE_SUBTYPE( ODateTimeType, ::com::sun::star::util::DateTime )
     367             : 
     368             :     class OShortIntegerType;
     369             :     typedef ODerivedDataType< OShortIntegerType, OValueLimitedType< sal_Int16 > > OShortIntegerType_Base;
     370           0 :     class OShortIntegerType : public OShortIntegerType_Base
     371             :     {
     372             :     public:
     373             :         OShortIntegerType( const OUString& _rName, sal_Int16 _nTypeClass );
     374             : 
     375             :     protected:
     376             :         DECLARE_DEFAULT_CLONING( OShortIntegerType )
     377             : 
     378             :         // OXSDDataType overridables
     379             :         virtual bool            _getValue( const OUString& value, double& fValue ) SAL_OVERRIDE;
     380             : 
     381             :         // OValueLimitedType overridables
     382             :         virtual OUString typedValueAsHumanReadableString( const ::com::sun::star::uno::Any& _rValue ) const SAL_OVERRIDE;
     383             :         virtual void normalizeValue( const ::com::sun::star::uno::Any& _rValue, double& _rDoubleValue ) const SAL_OVERRIDE;
     384             : 
     385             :     private:
     386             :         using OShortIntegerType_Base::initializeTypedClone;
     387             :     };
     388             : 
     389             : 
     390             : } // namespace xforms
     391             : 
     392             : 
     393             : #endif // INCLUDED_FORMS_SOURCE_XFORMS_DATATYPES_HXX
     394             : 
     395             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10