bump product version to 4.1.6.2
[LibreOffice.git] / include / connectivity / CommonTools.hxx
blobc13b97dc7050a205bb57923a8113ba4722810cfa
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 .
19 #ifndef _CONNECTIVITY_COMMONTOOLS_HXX_
20 #define _CONNECTIVITY_COMMONTOOLS_HXX_
22 #include <rtl/ref.hxx>
23 #include <rtl/ustring.hxx>
24 #include <com/sun/star/lang/DisposedException.hpp>
25 #include <com/sun/star/uno/Any.hxx>
26 #ifndef _VECTOR_
27 #include <vector>
28 #endif
29 #include <cppuhelper/weakref.hxx>
30 #include <comphelper/stl_types.hxx>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
33 #include <osl/interlck.h>
34 #include <com/sun/star/uno/XComponentContext.hpp>
35 #include "connectivity/dbtoolsdllapi.hxx"
37 namespace com { namespace sun { namespace star { namespace util {
38 struct Date;
39 struct DateTime;
40 struct Time;
42 }}}
44 #ifdef SOLAR_JAVA
45 namespace jvmaccess { class VirtualMachine; }
46 #endif
48 namespace connectivity
50 //------------------------------------------------------------------------------
51 OOO_DLLPUBLIC_DBTOOLS sal_Bool match(const sal_Unicode* pWild, const sal_Unicode* pStr, const sal_Unicode cEscape);
52 inline sal_Bool match(const OUString &rWild, const OUString &rStr, const sal_Unicode cEscape)
54 return match(rWild.getStr(), rStr.getStr(), cEscape);
56 //------------------------------------------------------------------------------
57 OOO_DLLPUBLIC_DBTOOLS OUString toDateString(const ::com::sun::star::util::Date& rDate);
58 OOO_DLLPUBLIC_DBTOOLS OUString toTimeString(const ::com::sun::star::util::Time& rTime);
59 OOO_DLLPUBLIC_DBTOOLS OUString toDateTimeString(const ::com::sun::star::util::DateTime& rDateTime);
61 // typedefs
62 typedef std::vector< ::com::sun::star::uno::WeakReferenceHelper > OWeakRefArray;
63 typedef ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier> OSQLTable;
65 DECLARE_STL_MAP(OUString,OSQLTable,comphelper::UStringMixLess, OSQLTables);
67 // -------------------------------------------------------------------------
68 // class ORefVector allows reference counting on a std::vector
69 // -------------------------------------------------------------------------
70 template< class VectorVal > class ORefVector
72 std::vector< VectorVal > m_vector;
73 oslInterlockedCount m_refCount;
75 protected:
76 virtual ~ORefVector(){}
77 public:
78 typedef std::vector< VectorVal > Vector;
80 ORefVector() : m_refCount(0) {}
81 ORefVector(size_t _st) : m_vector(_st) , m_refCount(0) {}
82 ORefVector(const ORefVector& _rRH) : m_vector(_rRH.m_vector),m_refCount(0)
85 ORefVector& operator=(const ORefVector& _rRH)
87 if ( &_rRH != this )
89 m_vector = _rRH.m_vector;
91 return *this;
94 std::vector< VectorVal > & get() { return m_vector; }
95 std::vector< VectorVal > const & get() const { return m_vector; }
97 inline static void * SAL_CALL operator new( size_t nSize ) SAL_THROW(())
98 { return ::rtl_allocateMemory( nSize ); }
99 inline static void SAL_CALL operator delete( void * pMem ) SAL_THROW(())
100 { ::rtl_freeMemory( pMem ); }
101 inline static void * SAL_CALL operator new( size_t, void * pMem ) SAL_THROW(())
102 { return pMem; }
103 inline static void SAL_CALL operator delete( void *, void * ) SAL_THROW(())
106 void acquire()
108 osl_atomic_increment( &m_refCount );
110 void release()
112 if (! osl_atomic_decrement( &m_refCount ))
113 delete this;
117 // -------------------------------------------------------------------------
118 // class ORowVector incudes refcounting and initialze himself
119 // with at least one element. This first element is reserved for
120 // the bookmark
121 // -------------------------------------------------------------------------
122 template< class VectorVal > class ORowVector : public ORefVector< VectorVal >
124 public:
125 ORowVector() : ORefVector< VectorVal >(1){}
126 ORowVector(size_t _st) : ORefVector< VectorVal >(_st+1)
130 typedef ORefVector< ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> > OSQLColumns;
132 // =======================================================================================
133 // search from __first to __last the column with the name _rVal
134 // when no such column exist __last is returned
135 OOO_DLLPUBLIC_DBTOOLS
136 OSQLColumns::Vector::const_iterator find( OSQLColumns::Vector::const_iterator __first,
137 OSQLColumns::Vector::const_iterator __last,
138 const OUString& _rVal,
139 const ::comphelper::UStringMixEqual& _rCase);
140 // =======================================================================================
141 // search from __first to __last the column with the realname _rVal
142 // when no such column exist __last is returned
143 OOO_DLLPUBLIC_DBTOOLS
144 OSQLColumns::Vector::const_iterator findRealName( OSQLColumns::Vector::const_iterator __first,
145 OSQLColumns::Vector::const_iterator __last,
146 const OUString& _rVal,
147 const ::comphelper::UStringMixEqual& _rCase);
149 // =======================================================================================
150 // the first two find methods are much faster than the one below
151 // =======================================================================================
152 // search from __first to __last the column with the property _rProp equals the value _rVal
153 // when no such column exist __last is returned
154 OOO_DLLPUBLIC_DBTOOLS
155 OSQLColumns::Vector::const_iterator find( OSQLColumns::Vector::const_iterator __first,
156 OSQLColumns::Vector::const_iterator __last,
157 const OUString& _rProp,
158 const OUString& _rVal,
159 const ::comphelper::UStringMixEqual& _rCase);
161 OOO_DLLPUBLIC_DBTOOLS void checkDisposed(sal_Bool _bThrow) throw ( ::com::sun::star::lang::DisposedException );
163 #ifdef SOLAR_JAVA
164 /** creates a java virtual machine
165 @param _rxContext
166 The ORB.
167 @return
168 The JavaVM.
170 OOO_DLLPUBLIC_DBTOOLS ::rtl::Reference< jvmaccess::VirtualMachine > getJavaVM(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext);
172 /** return <TRUE/> if the java class exists, otherwise <FALSE/>.
173 @param _pJVM
174 The JavaVM.
175 @param _sClassName
176 The class name to look for.
178 OOO_DLLPUBLIC_DBTOOLS sal_Bool existsJavaClassByName( const ::rtl::Reference< jvmaccess::VirtualMachine >& _pJVM,const OUString& _sClassName );
179 #endif
182 //==================================================================================
184 #define DECLARE_SERVICE_INFO() \
185 virtual OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); \
186 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); \
187 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) \
189 #define IMPLEMENT_SERVICE_INFO(classname, implasciiname, serviceasciiname) \
190 OUString SAL_CALL classname::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException) \
192 return OUString::createFromAscii(implasciiname); \
194 ::com::sun::star::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) \
196 ::com::sun::star::uno::Sequence< OUString > aSupported(1); \
197 aSupported[0] = OUString::createFromAscii(serviceasciiname); \
198 return aSupported; \
200 sal_Bool SAL_CALL classname::supportsService( const OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException) \
202 Sequence< OUString > aSupported(getSupportedServiceNames()); \
203 const OUString* pSupported = aSupported.getConstArray(); \
204 const OUString* pEnd = pSupported + aSupported.getLength(); \
205 for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported) \
208 return pSupported != pEnd; \
211 //==================================================================================
213 #endif // _CONNECTIVITY_COMMONTOOLS_HXX_
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */