LibreOffice Module dbaccess (master) 1
composertools.hxx
Go to the documentation of this file.
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#pragma once
21
22#include <rtl/ustrbuf.hxx>
23#include <osl/diagnose.h>
24
25namespace dbaccess
26{
27
28 // TokenComposer
30 {
31 private:
32 #ifdef DBG_UTIL
33 bool m_bUsed;
34 #endif
35
36 protected:
37 OUStringBuffer m_aBuffer;
38
39 public:
41 {
42 #ifdef DBG_UTIL
43 m_bUsed = true;
44 #endif
45 return m_aBuffer.makeStringAndClear();
46 }
47
48 void clear()
49 {
50 #ifdef DBG_UTIL
51 m_bUsed = false;
52 #endif
53 m_aBuffer.setLength(0);
54 }
55
56 public:
58 #ifdef DBG_UTIL
59 :m_bUsed( false )
60 #endif
61 {
62 }
63
65 {
66 }
67
68 TokenComposer(TokenComposer const &) = default;
72
73 void operator() (const OUString& lhs)
74 {
75 append(lhs);
76 }
77
78 void append( const OUString& lhs )
79 {
80 #ifdef DBG_UTIL
81 OSL_ENSURE( !m_bUsed, "FilterCreator::append: already used up!" );
82 #endif
83 if ( !lhs.isEmpty() )
84 {
85 if ( !m_aBuffer.isEmpty() )
87 else
88 m_aBuffer.append( lhs );
89 }
90 }
91
93 virtual void appendNonEmptyToNonEmpty( const OUString& lhs ) = 0;
94 };
95
96 // FilterCreator
98 {
99 virtual void appendNonEmptyToNonEmpty( const OUString& lhs ) override
100 {
101 m_aBuffer.insert( 0, ' ' );
102 m_aBuffer.insert( 0, '(' );
103 m_aBuffer.append( " ) AND ( " );
104 m_aBuffer.append( lhs );
105 m_aBuffer.append( " )" );
106 }
107 };
108
109 // FilterCreator
111 {
112 virtual void appendNonEmptyToNonEmpty( const OUString& lhs ) override
113 {
114 m_aBuffer.append( ", " );
115 m_aBuffer.append( lhs );
116 }
117 };
118
119} // namespace dbaccess
120
121/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void appendNonEmptyToNonEmpty(const OUString &lhs) override
append the given part. Only to be called when both the part and our buffer so far are not empty
virtual void appendNonEmptyToNonEmpty(const OUString &lhs) override
append the given part. Only to be called when both the part and our buffer so far are not empty
TokenComposer & operator=(TokenComposer const &)=default
OUStringBuffer m_aBuffer
void operator()(const OUString &lhs)
void append(const OUString &lhs)
TokenComposer(TokenComposer &&)=default
TokenComposer(TokenComposer const &)=default
virtual void appendNonEmptyToNonEmpty(const OUString &lhs)=0
append the given part. Only to be called when both the part and our buffer so far are not empty