1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef DBACCESS_SOURCE_CORE_INC_COMPOSERTOOLS_HXX
29 #define DBACCESS_SOURCE_CORE_INC_COMPOSERTOOLS_HXX
30 
31 /** === begin UNO includes === **/
32 /** === end UNO includes === **/
33 
34 #ifndef _RTL_USTRBUF_HXX_
35 #include <rtl/ustrbuf.hxx>
36 #endif
37 
38 #include <functional>
39 
40 //........................................................................
41 namespace dbaccess
42 {
43 //........................................................................
44 
45 	//====================================================================
46 	//= TokenComposer
47 	//====================================================================
48 	struct TokenComposer : public ::std::unary_function< ::rtl::OUString, void >
49 	{
50     private:
51         #ifdef DBG_UTIL
52         bool                    m_bUsed;
53         #endif
54 
55     protected:
56 		::rtl::OUStringBuffer   m_aBuffer;
57 
58     public:
59         ::rtl::OUString getComposedAndClear()
60         {
61             #ifdef DBG_UTIL
62             m_bUsed = true;
63             #endif
64             return m_aBuffer.makeStringAndClear();
65         }
66 
67         void clear()
68         {
69             #ifdef DBG_UTIL
70             m_bUsed = false;
71             #endif
72             m_aBuffer.makeStringAndClear();
73         }
74 
75     public:
76         TokenComposer()
77         #ifdef DBG_UTIL
78             :m_bUsed( false )
79         #endif
80         {
81         }
82 
83         virtual ~TokenComposer()
84         {
85         }
86 
87 		void operator() (const ::rtl::OUString& lhs)
88 		{
89 			append(lhs);
90 		}
91 
92         void append( const ::rtl::OUString& lhs )
93         {
94             #ifdef DBG_UTIL
95             OSL_ENSURE( !m_bUsed, "FilterCreator::append: already used up!" );
96             #endif
97             if ( lhs.getLength() )
98             {
99                 if ( m_aBuffer.getLength() )
100                     appendNonEmptyToNonEmpty( lhs );
101                 else
102                     m_aBuffer.append( lhs );
103             }
104         }
105 
106         /// append the given part. Only to be called when both the part and our buffer so far are not empty
107 		virtual void appendNonEmptyToNonEmpty( const ::rtl::OUString& lhs ) = 0;
108 	};
109 
110 	//====================================================================
111 	//= FilterCreator
112 	//====================================================================
113     struct FilterCreator : public TokenComposer
114     {
115 		virtual void appendNonEmptyToNonEmpty( const ::rtl::OUString& lhs )
116 		{
117             m_aBuffer.insert( 0, (sal_Unicode)' ' );
118             m_aBuffer.insert( 0, (sal_Unicode)'(' );
119             m_aBuffer.appendAscii( " ) AND ( " );
120             m_aBuffer.append( lhs );
121             m_aBuffer.appendAscii( " )" );
122 		}
123     };
124 
125 	//====================================================================
126 	//= FilterCreator
127 	//====================================================================
128 	struct OrderCreator : public TokenComposer
129 	{
130 		virtual void appendNonEmptyToNonEmpty( const ::rtl::OUString& lhs )
131 		{
132             m_aBuffer.appendAscii( ", " );
133             m_aBuffer.append( lhs );
134 		}
135 	};
136 
137 //........................................................................
138 } // namespace dbaccess
139 //........................................................................
140 
141 #endif // DBACCESS_SOURCE_CORE_INC_COMPOSERTOOLS_HXX
142 
143