Update ooo320-m1
[ooovba.git] / dbaccess / source / core / inc / composertools.hxx
blob609ae3e1447988c3a46231dd78daaf8946f2e8b8
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: composertools.hxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef DBACCESS_SOURCE_CORE_INC_COMPOSERTOOLS_HXX
32 #define DBACCESS_SOURCE_CORE_INC_COMPOSERTOOLS_HXX
34 /** === begin UNO includes === **/
35 /** === end UNO includes === **/
37 #ifndef _RTL_USTRBUF_HXX_
38 #include <rtl/ustrbuf.hxx>
39 #endif
41 #include <functional>
43 //........................................................................
44 namespace dbaccess
46 //........................................................................
48 //====================================================================
49 //= TokenComposer
50 //====================================================================
51 struct TokenComposer : public ::std::unary_function< ::rtl::OUString, void >
53 private:
54 #ifdef DBG_UTIL
55 bool m_bUsed;
56 #endif
58 protected:
59 ::rtl::OUStringBuffer m_aBuffer;
61 public:
62 ::rtl::OUString getComposedAndClear()
64 #ifdef DBG_UTIL
65 m_bUsed = true;
66 #endif
67 return m_aBuffer.makeStringAndClear();
70 void clear()
72 #ifdef DBG_UTIL
73 m_bUsed = false;
74 #endif
75 m_aBuffer.makeStringAndClear();
78 public:
79 TokenComposer()
80 #ifdef DBG_UTIL
81 :m_bUsed( false )
82 #endif
86 virtual ~TokenComposer()
90 void operator() (const ::rtl::OUString& lhs)
92 append(lhs);
95 void append( const ::rtl::OUString& lhs )
97 #ifdef DBG_UTIL
98 OSL_ENSURE( !m_bUsed, "FilterCreator::append: already used up!" );
99 #endif
100 if ( lhs.getLength() )
102 if ( m_aBuffer.getLength() )
103 appendNonEmptyToNonEmpty( lhs );
104 else
105 m_aBuffer.append( lhs );
109 /// append the given part. Only to be called when both the part and our buffer so far are not empty
110 virtual void appendNonEmptyToNonEmpty( const ::rtl::OUString& lhs ) = 0;
113 //====================================================================
114 //= FilterCreator
115 //====================================================================
116 struct FilterCreator : public TokenComposer
118 virtual void appendNonEmptyToNonEmpty( const ::rtl::OUString& lhs )
120 m_aBuffer.insert( 0, (sal_Unicode)' ' );
121 m_aBuffer.insert( 0, (sal_Unicode)'(' );
122 m_aBuffer.appendAscii( " ) AND ( " );
123 m_aBuffer.append( lhs );
124 m_aBuffer.appendAscii( " )" );
128 //====================================================================
129 //= FilterCreator
130 //====================================================================
131 struct OrderCreator : public TokenComposer
133 virtual void appendNonEmptyToNonEmpty( const ::rtl::OUString& lhs )
135 m_aBuffer.appendAscii( ", " );
136 m_aBuffer.append( lhs );
140 //........................................................................
141 } // namespace dbaccess
142 //........................................................................
144 #endif // DBACCESS_SOURCE_CORE_INC_COMPOSERTOOLS_HXX