Tag: cws_src680_rpt23fix01
User: fs      
Date: 2007-07-16 13:43:56+0000
Modified:
   dba/reportdesign/source/ui/dlg/Condition.cxx
   dba/reportdesign/source/ui/dlg/Condition.hxx

Log:
 #i77800# outsourced ExpressionFactory and friends to a dedicated file 
(conditionalexpression.*)

File Changes:

Directory: /dba/reportdesign/source/ui/dlg/
===========================================

File [changed]: Condition.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/reportdesign/source/ui/dlg/Condition.cxx?r1=1.2&r2=1.2.2.1
Delta lines:  +14 -179
----------------------
--- Condition.cxx       2007-07-09 11:56:29+0000        1.2
+++ Condition.cxx       2007-07-16 13:43:53+0000        1.2.2.1
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: Condition.cxx,v $
  *
- *  $Revision: 1.2 $
+ *  $Revision: 1.2.2.1 $
  *
- *  last change: $Author: rt $ $Date: 2007/07/09 11:56:29 $
+ *  last change: $Author: fs $ $Date: 2007/07/16 13:43:53 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -45,6 +45,7 @@
 #include "RptResId.hrc"
 #include "helpids.hrc"
 #include "reportformula.hxx"
+#include "conditionalexpression.hxx"
 
 #ifndef _COM_SUN_STAR_UTIL_URL_HPP_
 #include <com/sun/star/util/URL.hpp>
@@ -205,172 +206,6 @@
 }
 
 // 
=============================================================================
-// = IExpressionFactory
-// 
=============================================================================
-class SAL_NO_VTABLE IExpressionFactory
-{
-public:
-    virtual ::rtl::OUString     assembleExpression( const ::rtl::OUString& 
_rFieldDataSource, const ::rtl::OUString& _rLHS, const ::rtl::OUString& _rRHS ) 
const = 0;
-    virtual bool                matchExpression( const ::rtl::OUString& 
_rExpression, const ::rtl::OUString& _rFieldDataSource, ::rtl::OUString& 
_out_rLHS, ::rtl::OUString& _out_rRHS ) const = 0;
-
-    virtual ~IExpressionFactory() { }
-};
-
-// 
=============================================================================
-// = ExpressionFactory
-// 
=============================================================================
-class ExpressionFactory : public IExpressionFactory
-{
-private:
-    const ::rtl::OUString       m_sPattern;
-
-public:
-    ExpressionFactory( const sal_Char* _pAsciiPattern );
-
-    // IExpressionFactory
-    virtual ::rtl::OUString     assembleExpression( const ::rtl::OUString& 
_rFieldDataSource, const ::rtl::OUString& _rLHS, const ::rtl::OUString& _rRHS ) 
const;
-    virtual bool                matchExpression( const ::rtl::OUString& 
_rExpression, const ::rtl::OUString& _rFieldDataSource, ::rtl::OUString& 
_out_rLHS, ::rtl::OUString& _out_rRHS ) const;
-};
-
-// 
-----------------------------------------------------------------------------
-ExpressionFactory::ExpressionFactory( const sal_Char* _pAsciiPattern )
-    :m_sPattern( ::rtl::OUString::createFromAscii( _pAsciiPattern ) )
-{
-}
-
-// 
-----------------------------------------------------------------------------
-::rtl::OUString ExpressionFactory::assembleExpression( const ::rtl::OUString& 
_rFieldDataSource, const ::rtl::OUString& _rLHS, const ::rtl::OUString& _rRHS ) 
const
-{
-    ::rtl::OUString sExpression( m_sPattern );
-
-    sal_Int32 nPatternIndex = sExpression.indexOf( '$' );
-    while ( nPatternIndex > -1 )
-    {
-        const ::rtl::OUString* pReplace = NULL;
-        switch ( sExpression.getStr()[ nPatternIndex + 1 ] )
-        {
-        case '$': pReplace = &_rFieldDataSource; break;
-        case '1': pReplace = &_rLHS; break;
-        case '2': pReplace = &_rRHS; break;
-        default: break;
-        }
-
-        if ( pReplace == NULL )
-        {
-            OSL_ENSURE( false, "ExpressionFactory::assembleExpression: illegal 
pattern!" );
-            break;
-        }
-
-        sExpression = sExpression.replaceAt( nPatternIndex, 2, *pReplace );
-        nPatternIndex = sExpression.indexOf( '$', nPatternIndex + 
pReplace->getLength() + 1 );
-    }
-    return sExpression;
-}
-
-// 
-----------------------------------------------------------------------------
-bool ExpressionFactory::matchExpression( const ::rtl::OUString& _rExpression, 
const ::rtl::OUString& _rFieldDataSource, ::rtl::OUString& _out_rLHS, 
::rtl::OUString& _out_rRHS ) const
-{
-    (void)_rExpression;
-    (void)_rFieldDataSource;
-    (void)_out_rLHS;
-    (void)_out_rRHS;
-
-    // if we had regular expression, the matching would be pretty easy ...
-    // just replace $1 and $2 in the pattern with (.*), and then get them with 
\1 resp. \2.
-    // Unfortunately, we don't have such a regexp engine ...
-
-    // Okay, let's start with replacing all $$ in our pattern with the actual 
field data source
-    ::rtl::OUString sMatchExpression( m_sPattern );
-    const ::rtl::OUString sFieldDataPattern( RTL_CONSTASCII_USTRINGPARAM( "$$" 
) );
-    sal_Int32 nIndex( sMatchExpression.indexOf( sFieldDataPattern ) );
-    while ( nIndex != -1 )
-    {
-        sMatchExpression = sMatchExpression.replaceAt( nIndex, 
sFieldDataPattern.getLength(), _rFieldDataSource );
-        nIndex = sMatchExpression.indexOf( sFieldDataPattern, nIndex + 
_rFieldDataSource.getLength() );
-    }
-
-    const ::rtl::OUString sLHSPattern( RTL_CONSTASCII_USTRINGPARAM( "$1" ) );
-    const ::rtl::OUString sRHSPattern( RTL_CONSTASCII_USTRINGPARAM( "$2" ) );
-    sal_Int32 nLHSIndex( sMatchExpression.indexOf( sLHSPattern ) );
-    sal_Int32 nRHSIndex( sMatchExpression.indexOf( sRHSPattern ) );
-
-    // now we should have at most one occurance of $1 and $2, resp.
-    OSL_ENSURE( sMatchExpression.indexOf( sLHSPattern, nLHSIndex + 1 ) == -1,
-        "ExpressionFactory::matchExpression: unsupported pattern (more than 
one LHS occurance)!" );
-    OSL_ENSURE( sMatchExpression.indexOf( sRHSPattern, nRHSIndex + 1 ) == -1,
-        "ExpressionFactory::matchExpression: unsupported pattern (more than 
one RHS occurance)!" );
-    // Also, an LHS must be present, and precede the RHS (if present)
-    OSL_ENSURE( ( nLHSIndex != -1 ) && ( ( nLHSIndex < nRHSIndex ) || ( 
nRHSIndex == -1 ) ),
-        "ExpressionFactory::matchExpression: no LHS, or an RHS preceeding the 
LHS - this is not supported!" );
-
-    // up to the occurance of the LHS (which must exist, see above), the two 
expressions
-    // must be identical
-    if ( _rExpression.getLength() < nLHSIndex )
-        return false;
-    const ::rtl::OUString sExprPart1( _rExpression.copy( 0, nLHSIndex ) );
-    const ::rtl::OUString sMatchExprPart1( sMatchExpression.copy( 0, nLHSIndex 
) );
-    if ( sExprPart1 != sMatchExprPart1 )
-        // the left-most expression parts do not match
-        return false;
-
-    // after the occurance of the RHS (or the LHS, if there is no RHS), the 
two expressions
-    // must be identical, too
-    bool bHaveRHS( nRHSIndex != -1 );
-    sal_Int32 nRightMostIndex( bHaveRHS ? nRHSIndex : nLHSIndex );
-    const ::rtl::OUString sMatchExprPart3( sMatchExpression.copy( 
nRightMostIndex + 2 ) );
-    if ( _rExpression.getLength() < sMatchExprPart3.getLength() )
-        // the expression is not even long enough to hold the right-most part 
of the match expression
-        return false;
-    const ::rtl::OUString sExprPart3( _rExpression.copy( 
_rExpression.getLength() - sMatchExprPart3.getLength() ) );
-    if ( sExprPart3 != sMatchExprPart3 )
-        // the right-most expression parts do not match
-        return false;
-
-    // if we don't have an RHS, we're done
-    if ( !bHaveRHS )
-    {
-        _out_rLHS = _rExpression.copy( sExprPart1.getLength(), 
_rExpression.getLength() - sExprPart1.getLength() - sExprPart3.getLength() );
-        return true;
-    }
-
-    // strip the match expression by its right-most and left-most part, and by 
the placeholders $1 and $2
-    sal_Int32 nMatchExprPart2Start( nLHSIndex + sLHSPattern.getLength() );
-    ::rtl::OUString sMatchExprPart2 = sMatchExpression.copy(
-        nMatchExprPart2Start,
-        sMatchExpression.getLength() - nMatchExprPart2Start - 
sMatchExprPart3.getLength() - 2
-    );
-    // strip the expression by its left-most and right-most part
-    const ::rtl::OUString sExpression( _rExpression.copy(
-        sExprPart1.getLength(),
-        _rExpression.getLength() - sExprPart1.getLength() - 
sExprPart3.getLength()
-    ) );
-
-    sal_Int32 nPart2Index = sExpression.indexOf( sMatchExprPart2 );
-    if ( nPart2Index == -1 )
-        // the "middle" part of the match expression does not exist in the 
expression at all
-        return false;
-
-    OSL_ENSURE( sExpression.indexOf( sMatchExprPart2, nPart2Index + 1 ) == -1,
-        "ExpressionFactory::matchExpression: ambiguous matching!" );
-        // if this fires, then we're lost: The middle part exists two times in 
the expression,
-        // so we cannot reliably determine what's the LHS and what's the RHS.
-        // Well, the whole mechanism is flawed, anyway:
-        // Encoding the field content in the conditional expression will break 
as soon
-        // as somebody
-        // - assigns a Data Field to a control
-        // - creates a conditional format expression for the control
-        // - assigns another Data Field to the control
-        // - opens the Conditional Format Dialog, again
-        // Here, at the latest, you can see that we need another mechanism, 
anyway, which does not
-        // rely on those strange expression building/matching
-
-    _out_rLHS = sExpression.copy( 0, nPart2Index );
-    _out_rRHS = sExpression.copy( nPart2Index + sMatchExprPart2.getLength() );
-
-    return true;
-}
-
-// 
=============================================================================
 // = Condition
 // 
=============================================================================
 // 
-----------------------------------------------------------------------------
@@ -455,14 +290,14 @@
 
     impl_layoutAll();
 
-    m_aFieldExprFactories[ eBetween ]        = PExpressionFactory( new 
ExpressionFactory( "AND( ( $$ ) >= ( $1 ); ( $$ ) <= ( $2 ) )" ) );
-    m_aFieldExprFactories[ eNotBetween ]     = PExpressionFactory( new 
ExpressionFactory( "NOT( AND( ( $$ ) >= ( $1 ); ( $$ ) <= ( $2 ) ) )" ) );
-    m_aFieldExprFactories[ eEqualTo ]        = PExpressionFactory( new 
ExpressionFactory( "( $$ ) = ( $1 )" ) );
-    m_aFieldExprFactories[ eNotEqualTo ]     = PExpressionFactory( new 
ExpressionFactory( "( $$ ) <> ( $1 )" ) );
-    m_aFieldExprFactories[ eGreaterThan ]    = PExpressionFactory( new 
ExpressionFactory( "( $$ ) > ( $1 )" ) );
-    m_aFieldExprFactories[ eLessThan ]       = PExpressionFactory( new 
ExpressionFactory( "( $$ ) < ( $1 )" ) );
-    m_aFieldExprFactories[ eGreaterOrEqual ] = PExpressionFactory( new 
ExpressionFactory( "( $$ ) >= ( $1 )" ) );
-    m_aFieldExprFactories[ eLessOrEqual ]    = PExpressionFactory( new 
ExpressionFactory( "( $$ ) <= ( $1 )" ) );
+    m_aConditionalExpressions[ eBetween ]        = PConditionalExpression( new 
ConditionalExpression( "AND( ( $$ ) >= ( $1 ); ( $$ ) <= ( $2 ) )" ) );
+    m_aConditionalExpressions[ eNotBetween ]     = PConditionalExpression( new 
ConditionalExpression( "NOT( AND( ( $$ ) >= ( $1 ); ( $$ ) <= ( $2 ) ) )" ) );
+    m_aConditionalExpressions[ eEqualTo ]        = PConditionalExpression( new 
ConditionalExpression( "( $$ ) = ( $1 )" ) );
+    m_aConditionalExpressions[ eNotEqualTo ]     = PConditionalExpression( new 
ConditionalExpression( "( $$ ) <> ( $1 )" ) );
+    m_aConditionalExpressions[ eGreaterThan ]    = PConditionalExpression( new 
ConditionalExpression( "( $$ ) > ( $1 )" ) );
+    m_aConditionalExpressions[ eLessThan ]       = PConditionalExpression( new 
ConditionalExpression( "( $$ ) < ( $1 )" ) );
+    m_aConditionalExpressions[ eGreaterOrEqual ] = PConditionalExpression( new 
ConditionalExpression( "( $$ ) >= ( $1 )" ) );
+    m_aConditionalExpressions[ eLessOrEqual ]    = PConditionalExpression( new 
ConditionalExpression( "( $$ ) <= ( $1 )" ) );
 }
 
 // 
-----------------------------------------------------------------------------
@@ -763,8 +598,8 @@
         const ::rtl::OUString sUnprefixedFieldContent( 
aFieldContentFormula.getBracketedFieldOrExpression() );
 
         // check whether one of the Field Value Expression Factories 
recognizes the expression
-        for (   ExpressionFactories::const_iterator fac = 
m_aFieldExprFactories.begin();
-                fac != m_aFieldExprFactories.end();
+        for (   ConditionalExpressions::const_iterator fac = 
m_aConditionalExpressions.begin();
+                fac != m_aConditionalExpressions.end();
                 ++fac
             )
         {
@@ -855,7 +690,7 @@
         ReportFormula aFieldContentFormula( m_rAction.getDataField() );
         ::rtl::OUString sUnprefixedFieldContent( 
aFieldContentFormula.getBracketedFieldOrExpression() );
 
-        PExpressionFactory pFactory( m_aFieldExprFactories[ eOperation ] );
+        PConditionalExpression pFactory( m_aConditionalExpressions[ eOperation 
] );
         sUndecoratedFormula = pFactory->assembleExpression( 
sUnprefixedFieldContent, sLHS, sRHS );
     }
 

File [changed]: Condition.hxx
Url: 
http://dba.openoffice.org/source/browse/dba/reportdesign/source/ui/dlg/Condition.hxx?r1=1.2&r2=1.2.2.1
Delta lines:  +6 -6
-------------------
--- Condition.hxx       2007-07-09 11:56:29+0000        1.2
+++ Condition.hxx       2007-07-16 13:43:53+0000        1.2.2.1
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: Condition.hxx,v $
  *
- *  $Revision: 1.2 $
+ *  $Revision: 1.2.2.1 $
  *
- *  last change: $Author: rt $ $Date: 2007/07/09 11:56:29 $
+ *  last change: $Author: fs $ $Date: 2007/07/16 13:43:53 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -102,9 +102,9 @@
         eLessOrEqual    = 7
     };
 
-    class IExpressionFactory;
-    typedef ::boost::shared_ptr< IExpressionFactory >               
PExpressionFactory;
-    typedef ::std::map< ComparisonOperation, PExpressionFactory >   
ExpressionFactories;
+    class ConditionalExpression;
+    typedef ::boost::shared_ptr< ConditionalExpression >                
PConditionalExpression;
+    typedef ::std::map< ComparisonOperation, PConditionalExpression >   
ConditionalExpressions;
     //========================================================================
     //= Condition
     //========================================================================
@@ -135,7 +135,7 @@
         long                            m_nLastKnownWindowWidth;
         bool                            m_bInDestruction;
 
-        ExpressionFactories             m_aFieldExprFactories;
+        ConditionalExpressions          m_aConditionalExpressions;
 
         DECL_LINK( OnFormatAction,      ToolBox* );
         DECL_LINK( DropdownClick,       ToolBox* );




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to