Branch data 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< ::rtl::OUString, void >
35 : : {
36 : : private:
37 : : #ifdef DBG_UTIL
38 : : bool m_bUsed;
39 : : #endif
40 : :
41 : : protected:
42 : : ::rtl::OUStringBuffer m_aBuffer;
43 : :
44 : : public:
45 : 114 : ::rtl::OUString getComposedAndClear()
46 : : {
47 : : #ifdef DBG_UTIL
48 : : m_bUsed = true;
49 : : #endif
50 : 114 : return m_aBuffer.makeStringAndClear();
51 : : }
52 : :
53 : 112 : void clear()
54 : : {
55 : : #ifdef DBG_UTIL
56 : : m_bUsed = false;
57 : : #endif
58 : 112 : m_aBuffer.makeStringAndClear();
59 : 112 : }
60 : :
61 : : public:
62 : 58 : TokenComposer()
63 : : #ifdef DBG_UTIL
64 : : :m_bUsed( false )
65 : : #endif
66 : 58 : {
67 : 58 : }
68 : :
69 : 58 : virtual ~TokenComposer()
70 : 58 : {
71 [ - + ]: 58 : }
72 : :
73 : 0 : void operator() (const ::rtl::OUString& lhs)
74 : : {
75 : 0 : append(lhs);
76 : 0 : }
77 : :
78 : 228 : void append( const ::rtl::OUString& lhs )
79 : : {
80 : : #ifdef DBG_UTIL
81 : : OSL_ENSURE( !m_bUsed, "FilterCreator::append: already used up!" );
82 : : #endif
83 [ + + ]: 228 : if ( !lhs.isEmpty() )
84 : : {
85 [ - + ]: 98 : if ( m_aBuffer.getLength() )
86 : 0 : appendNonEmptyToNonEmpty( lhs );
87 : : else
88 : 98 : m_aBuffer.append( lhs );
89 : : }
90 : 228 : }
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 ::rtl::OUString& lhs ) = 0;
94 : : };
95 : :
96 : : //====================================================================
97 : : //= FilterCreator
98 : : //====================================================================
99 [ - + ]: 114 : struct FilterCreator : public TokenComposer
100 : : {
101 : 0 : virtual void appendNonEmptyToNonEmpty( const ::rtl::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 [ - + ]: 58 : struct OrderCreator : public TokenComposer
115 : : {
116 : 0 : virtual void appendNonEmptyToNonEmpty( const ::rtl::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: */
|