LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/dbaccess/source/core/inc - composertools.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 18 34 52.9 %
Date: 2013-07-09 Functions: 11 23 47.8 %
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 DBACCESS_SOURCE_CORE_INC_COMPOSERTOOLS_HXX
      21             : #define DBACCESS_SOURCE_CORE_INC_COMPOSERTOOLS_HXX
      22             : 
      23             : 
      24             : #include <rtl/ustrbuf.hxx>
      25             : 
      26             : #include <functional>
      27             : 
      28             : namespace dbaccess
      29             : {
      30             : 
      31             :     //====================================================================
      32             :     //= TokenComposer
      33             :     //====================================================================
      34           0 :     struct TokenComposer : public ::std::unary_function< OUString, void >
      35             :     {
      36             :     private:
      37             :         #ifdef DBG_UTIL
      38             :         bool                    m_bUsed;
      39             :         #endif
      40             : 
      41             :     protected:
      42             :         OUStringBuffer   m_aBuffer;
      43             : 
      44             :     public:
      45          57 :         OUString getComposedAndClear()
      46             :         {
      47             :             #ifdef DBG_UTIL
      48             :             m_bUsed = true;
      49             :             #endif
      50          57 :             return m_aBuffer.makeStringAndClear();
      51             :         }
      52             : 
      53          56 :         void clear()
      54             :         {
      55             :             #ifdef DBG_UTIL
      56             :             m_bUsed = false;
      57             :             #endif
      58          56 :             m_aBuffer.makeStringAndClear();
      59          56 :         }
      60             : 
      61             :     public:
      62          29 :         TokenComposer()
      63             :         #ifdef DBG_UTIL
      64             :             :m_bUsed( false )
      65             :         #endif
      66          29 :         {
      67          29 :         }
      68             : 
      69          29 :         virtual ~TokenComposer()
      70          29 :         {
      71          29 :         }
      72             : 
      73           0 :         void operator() (const OUString& lhs)
      74             :         {
      75           0 :             append(lhs);
      76           0 :         }
      77             : 
      78         114 :         void append( const OUString& lhs )
      79             :         {
      80             :             #ifdef DBG_UTIL
      81             :             OSL_ENSURE( !m_bUsed, "FilterCreator::append: already used up!" );
      82             :             #endif
      83         114 :             if ( !lhs.isEmpty() )
      84             :             {
      85          49 :                 if ( !m_aBuffer.isEmpty() )
      86           0 :                     appendNonEmptyToNonEmpty( lhs );
      87             :                 else
      88          49 :                     m_aBuffer.append( lhs );
      89             :             }
      90         114 :         }
      91             : 
      92             :         /// append the given part. Only to be called when both the part and our buffer so far are not empty
      93             :         virtual void appendNonEmptyToNonEmpty( const OUString& lhs ) = 0;
      94             :     };
      95             : 
      96             :     //====================================================================
      97             :     //= FilterCreator
      98             :     //====================================================================
      99          57 :     struct FilterCreator : public TokenComposer
     100             :     {
     101           0 :         virtual void appendNonEmptyToNonEmpty( const OUString& lhs )
     102             :         {
     103           0 :             m_aBuffer.insert( 0, (sal_Unicode)' ' );
     104           0 :             m_aBuffer.insert( 0, (sal_Unicode)'(' );
     105           0 :             m_aBuffer.appendAscii( " ) AND ( " );
     106           0 :             m_aBuffer.append( lhs );
     107           0 :             m_aBuffer.appendAscii( " )" );
     108           0 :         }
     109             :     };
     110             : 
     111             :     //====================================================================
     112             :     //= FilterCreator
     113             :     //====================================================================
     114          29 :     struct OrderCreator : public TokenComposer
     115             :     {
     116           0 :         virtual void appendNonEmptyToNonEmpty( const OUString& lhs )
     117             :         {
     118           0 :             m_aBuffer.appendAscii( ", " );
     119           0 :             m_aBuffer.append( lhs );
     120           0 :         }
     121             :     };
     122             : 
     123             : } // namespace dbaccess
     124             : 
     125             : #endif // DBACCESS_SOURCE_CORE_INC_COMPOSERTOOLS_HXX
     126             : 
     127             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10