xref: /AOO41X/main/dbaccess/source/core/inc/composertools.hxx (revision 2e2212a7c22e96cf6f6fab0dd042c34a45a64bd6)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef DBACCESS_SOURCE_CORE_INC_COMPOSERTOOLS_HXX
25 #define DBACCESS_SOURCE_CORE_INC_COMPOSERTOOLS_HXX
26 
27 /** === begin UNO includes === **/
28 /** === end UNO includes === **/
29 
30 #ifndef _RTL_USTRBUF_HXX_
31 #include <rtl/ustrbuf.hxx>
32 #endif
33 
34 #include <functional>
35 
36 //........................................................................
37 namespace dbaccess
38 {
39 //........................................................................
40 
41     //====================================================================
42     //= TokenComposer
43     //====================================================================
44     struct TokenComposer : public ::std::unary_function< ::rtl::OUString, void >
45     {
46     private:
47         #ifdef DBG_UTIL
48         bool                    m_bUsed;
49         #endif
50 
51     protected:
52         ::rtl::OUStringBuffer   m_aBuffer;
53 
54     public:
getComposedAndCleardbaccess::TokenComposer55         ::rtl::OUString getComposedAndClear()
56         {
57             #ifdef DBG_UTIL
58             m_bUsed = true;
59             #endif
60             return m_aBuffer.makeStringAndClear();
61         }
62 
cleardbaccess::TokenComposer63         void clear()
64         {
65             #ifdef DBG_UTIL
66             m_bUsed = false;
67             #endif
68             m_aBuffer.makeStringAndClear();
69         }
70 
71     public:
TokenComposerdbaccess::TokenComposer72         TokenComposer()
73         #ifdef DBG_UTIL
74             :m_bUsed( false )
75         #endif
76         {
77         }
78 
~TokenComposerdbaccess::TokenComposer79         virtual ~TokenComposer()
80         {
81         }
82 
operator ()dbaccess::TokenComposer83         void operator() (const ::rtl::OUString& lhs)
84         {
85             append(lhs);
86         }
87 
appenddbaccess::TokenComposer88         void append( const ::rtl::OUString& lhs )
89         {
90             #ifdef DBG_UTIL
91             OSL_ENSURE( !m_bUsed, "FilterCreator::append: already used up!" );
92             #endif
93             if ( lhs.getLength() )
94             {
95                 if ( m_aBuffer.getLength() )
96                     appendNonEmptyToNonEmpty( lhs );
97                 else
98                     m_aBuffer.append( lhs );
99             }
100         }
101 
102         /// append the given part. Only to be called when both the part and our buffer so far are not empty
103         virtual void appendNonEmptyToNonEmpty( const ::rtl::OUString& lhs ) = 0;
104     };
105 
106     //====================================================================
107     //= FilterCreator
108     //====================================================================
109     struct FilterCreator : public TokenComposer
110     {
appendNonEmptyToNonEmptydbaccess::FilterCreator111         virtual void appendNonEmptyToNonEmpty( const ::rtl::OUString& lhs )
112         {
113             m_aBuffer.insert( 0, (sal_Unicode)' ' );
114             m_aBuffer.insert( 0, (sal_Unicode)'(' );
115             m_aBuffer.appendAscii( " ) AND ( " );
116             m_aBuffer.append( lhs );
117             m_aBuffer.appendAscii( " )" );
118         }
119     };
120 
121     //====================================================================
122     //= FilterCreator
123     //====================================================================
124     struct OrderCreator : public TokenComposer
125     {
appendNonEmptyToNonEmptydbaccess::OrderCreator126         virtual void appendNonEmptyToNonEmpty( const ::rtl::OUString& lhs )
127         {
128             m_aBuffer.appendAscii( ", " );
129             m_aBuffer.append( lhs );
130         }
131     };
132 
133 //........................................................................
134 } // namespace dbaccess
135 //........................................................................
136 
137 #endif // DBACCESS_SOURCE_CORE_INC_COMPOSERTOOLS_HXX
138 
139