Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / dbaccess / source / core / inc / composertools.hxx
blob3370647573003e49811d93ccaa2cc0211bfc3fae
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 #pragma once
22 #include <rtl/ustrbuf.hxx>
23 #include <osl/diagnose.h>
25 namespace dbaccess
28 // TokenComposer
29 struct TokenComposer
31 private:
32 #ifdef DBG_UTIL
33 bool m_bUsed;
34 #endif
36 protected:
37 OUStringBuffer m_aBuffer;
39 public:
40 OUString getComposedAndClear()
42 #ifdef DBG_UTIL
43 m_bUsed = true;
44 #endif
45 return m_aBuffer.makeStringAndClear();
48 void clear()
50 #ifdef DBG_UTIL
51 m_bUsed = false;
52 #endif
53 m_aBuffer.setLength(0);
56 public:
57 TokenComposer()
58 #ifdef DBG_UTIL
59 :m_bUsed( false )
60 #endif
64 virtual ~TokenComposer()
68 TokenComposer(TokenComposer const &) = default;
69 TokenComposer(TokenComposer &&) = default;
70 TokenComposer & operator =(TokenComposer const &) = default;
71 TokenComposer & operator =(TokenComposer &&) = default;
73 void operator() (const OUString& lhs)
75 append(lhs);
78 void append( const 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.isEmpty() )
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 OUString& lhs ) = 0;
96 // FilterCreator
97 struct FilterCreator : public TokenComposer
99 virtual void appendNonEmptyToNonEmpty( const OUString& lhs ) override
101 m_aBuffer.insert( 0, ' ' );
102 m_aBuffer.insert( 0, '(' );
103 m_aBuffer.append( " ) AND ( " );
104 m_aBuffer.append( lhs );
105 m_aBuffer.append( " )" );
109 // FilterCreator
110 struct OrderCreator : public TokenComposer
112 virtual void appendNonEmptyToNonEmpty( const OUString& lhs ) override
114 m_aBuffer.append( ", " );
115 m_aBuffer.append( lhs );
119 } // namespace dbaccess
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */