Bump version to 21.06.18.1
[LibreOffice.git] / include / connectivity / CommonTools.hxx
blob62e25b10d3f88547236622654099d18ca399fbf1
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 INCLUDED_CONNECTIVITY_COMMONTOOLS_HXX
20 #define INCLUDED_CONNECTIVITY_COMMONTOOLS_HXX
22 #include <sal/config.h>
23 #include <config_java.h>
25 #include <map>
27 #include <rtl/ref.hxx>
28 #include <rtl/ustring.hxx>
29 #include <vector>
30 #include <cppuhelper/weakref.hxx>
31 #include <comphelper/stl_types.hxx>
32 #include <com/sun/star/beans/XPropertySet.hpp>
33 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
34 #include <connectivity/dbtoolsdllapi.hxx>
35 #include <cppuhelper/supportsservice.hxx>
36 #include <salhelper/simplereferenceobject.hxx>
38 namespace com::sun::star::uno { class XComponentContext; }
40 #if HAVE_FEATURE_JAVA
41 namespace jvmaccess { class VirtualMachine; }
42 #endif
44 namespace connectivity
46 OOO_DLLPUBLIC_DBTOOLS bool match(const sal_Unicode* pWild, const sal_Unicode* pStr, const sal_Unicode cEscape);
47 inline bool match(const OUString &rWild, const OUString &rStr, const sal_Unicode cEscape)
49 return match(rWild.getStr(), rStr.getStr(), cEscape);
51 // typedefs
52 typedef std::vector< css::uno::WeakReferenceHelper > OWeakRefArray;
53 typedef css::uno::Reference< css::sdbcx::XColumnsSupplier> OSQLTable;
55 typedef std::map<OUString,OSQLTable,comphelper::UStringMixLess> OSQLTables;
57 // class ORefVector allows reference counting on a std::vector
58 template< class VectorVal > class ORefVector : public salhelper::SimpleReferenceObject,
59 public std::vector< VectorVal >
61 protected:
62 virtual ~ORefVector() override {}
63 public:
64 typedef std::vector< VectorVal > Vector;
66 ORefVector() {}
67 ORefVector(size_t _st) : std::vector< VectorVal >(_st) {}
68 ORefVector(const ORefVector& rOther)
69 : salhelper::SimpleReferenceObject()
70 , std::vector< VectorVal >(rOther)
73 ORefVector& operator=(const ORefVector& _rRH)
75 if ( &_rRH != this )
77 std::vector< VectorVal >::operator=(_rRH);
79 return *this;
83 // class ORowVector includes refcounting and initialize himself
84 // with at least one element. This first element is reserved for
85 // the bookmark
86 template< class VectorVal > class ORowVector : public ORefVector< VectorVal >
88 public:
89 ORowVector() : ORefVector< VectorVal >(1){}
90 ORowVector(size_t _st) : ORefVector< VectorVal >(_st+1)
94 typedef ORefVector< css::uno::Reference< css::beans::XPropertySet> > OSQLColumns;
96 // search from first to last the column with the name _rVal
97 // when no such column exist last is returned
98 OOO_DLLPUBLIC_DBTOOLS
99 OSQLColumns::const_iterator find( const OSQLColumns::const_iterator& first,
100 const OSQLColumns::const_iterator& last,
101 const OUString& _rVal,
102 const ::comphelper::UStringMixEqual& _rCase);
104 // search from first to last the column with the realname _rVal
105 // when no such column exist last is returned
106 OOO_DLLPUBLIC_DBTOOLS
107 OSQLColumns::const_iterator findRealName( const OSQLColumns::const_iterator& first,
108 const OSQLColumns::const_iterator& last,
109 const OUString& _rVal,
110 const ::comphelper::UStringMixEqual& _rCase);
112 // the first two find methods are much faster than the one below
113 // search from first to last the column with the property _rProp equals the value _rVal
114 // when no such column exist last is returned
115 OOO_DLLPUBLIC_DBTOOLS
116 OSQLColumns::const_iterator find( OSQLColumns::const_iterator first,
117 const OSQLColumns::const_iterator& last,
118 const OUString& _rProp,
119 const OUString& _rVal,
120 const ::comphelper::UStringMixEqual& _rCase);
122 /// @throws css::lang::DisposedException
123 OOO_DLLPUBLIC_DBTOOLS void checkDisposed(bool _bThrow);
125 #if HAVE_FEATURE_JAVA
126 /** creates a java virtual machine
127 @param _rxContext
128 The ORB.
129 @return
130 The JavaVM.
132 OOO_DLLPUBLIC_DBTOOLS ::rtl::Reference< jvmaccess::VirtualMachine > getJavaVM(const css::uno::Reference< css::uno::XComponentContext >& _rxContext);
134 /** return <TRUE/> if the java class exists, otherwise <FALSE/>.
135 @param _pJVM
136 The JavaVM.
137 @param _sClassName
138 The class name to look for.
140 OOO_DLLPUBLIC_DBTOOLS bool existsJavaClassByName( const ::rtl::Reference< jvmaccess::VirtualMachine >& _pJVM,const OUString& _sClassName );
141 #endif
144 #define DECLARE_SERVICE_INFO() \
145 virtual OUString SAL_CALL getImplementationName( ) override; \
146 virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName ) override; \
147 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override \
149 #define IMPLEMENT_SERVICE_INFO(classname, implasciiname, serviceasciiname) \
150 OUString SAL_CALL classname::getImplementationName( ) \
152 return implasciiname; \
154 css::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames( ) \
156 css::uno::Sequence< OUString > aSupported { serviceasciiname }; \
157 return aSupported; \
159 sal_Bool SAL_CALL classname::supportsService( const OUString& rServiceName ) \
161 return cppu::supportsService(this, rServiceName); \
164 #endif // INCLUDED_CONNECTIVITY_COMMONTOOLS_HXX
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */