Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / dbaccess / source / core / inc / composertools.hxx
blob5549a704915297ffa0ae3249c0b572a982f6c5ab
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef DBACCESS_SOURCE_CORE_INC_COMPOSERTOOLS_HXX
21 #define DBACCESS_SOURCE_CORE_INC_COMPOSERTOOLS_HXX
24 #include <rtl/ustrbuf.hxx>
26 #include <functional>
28 namespace dbaccess
31 //====================================================================
32 //= TokenComposer
33 //====================================================================
34 struct TokenComposer : public ::std::unary_function< ::rtl::OUString, void >
36 private:
37 #ifdef DBG_UTIL
38 bool m_bUsed;
39 #endif
41 protected:
42 ::rtl::OUStringBuffer m_aBuffer;
44 public:
45 ::rtl::OUString getComposedAndClear()
47 #ifdef DBG_UTIL
48 m_bUsed = true;
49 #endif
50 return m_aBuffer.makeStringAndClear();
53 void clear()
55 #ifdef DBG_UTIL
56 m_bUsed = false;
57 #endif
58 m_aBuffer.makeStringAndClear();
61 public:
62 TokenComposer()
63 #ifdef DBG_UTIL
64 :m_bUsed( false )
65 #endif
69 virtual ~TokenComposer()
73 void operator() (const ::rtl::OUString& lhs)
75 append(lhs);
78 void append( const ::rtl::OUString& lhs )
80 #ifdef DBG_UTIL
81 OSL_ENSURE( !m_bUsed, "FilterCreator::append: already used up!" );
82 #endif
83 if ( !lhs.isEmpty() )
85 if ( m_aBuffer.getLength() )
86 appendNonEmptyToNonEmpty( lhs );
87 else
88 m_aBuffer.append( lhs );
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 ::rtl::OUString& lhs ) = 0;
96 //====================================================================
97 //= FilterCreator
98 //====================================================================
99 struct FilterCreator : public TokenComposer
101 virtual void appendNonEmptyToNonEmpty( const ::rtl::OUString& lhs )
103 m_aBuffer.insert( 0, (sal_Unicode)' ' );
104 m_aBuffer.insert( 0, (sal_Unicode)'(' );
105 m_aBuffer.appendAscii( " ) AND ( " );
106 m_aBuffer.append( lhs );
107 m_aBuffer.appendAscii( " )" );
111 //====================================================================
112 //= FilterCreator
113 //====================================================================
114 struct OrderCreator : public TokenComposer
116 virtual void appendNonEmptyToNonEmpty( const ::rtl::OUString& lhs )
118 m_aBuffer.appendAscii( ", " );
119 m_aBuffer.append( lhs );
123 } // namespace dbaccess
125 #endif // DBACCESS_SOURCE_CORE_INC_COMPOSERTOOLS_HXX
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */