Cosmetics.
[LibreOffice.git] / include / connectivity / CommonTools.hxx
blobf9cd35155dd2d65bd849f071cd989a19204e92c6
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
60 std::vector< VectorVal > m_vector;
62 protected:
63 virtual ~ORefVector() override {}
64 public:
65 typedef std::vector< VectorVal > Vector;
67 ORefVector() {}
68 ORefVector(size_t _st) : m_vector(_st) {}
69 ORefVector(const ORefVector& rOther)
70 : salhelper::SimpleReferenceObject()
71 , m_vector(rOther.m_vector)
74 ORefVector& operator=(const ORefVector& _rRH)
76 if ( &_rRH != this )
78 m_vector = _rRH.m_vector;
80 return *this;
83 std::vector< VectorVal > & get() { return m_vector; }
84 std::vector< VectorVal > const & get() const { return m_vector; }
88 // class ORowVector includes refcounting and initialize himself
89 // with at least one element. This first element is reserved for
90 // the bookmark
91 template< class VectorVal > class ORowVector : public ORefVector< VectorVal >
93 public:
94 ORowVector() : ORefVector< VectorVal >(1){}
95 ORowVector(size_t _st) : ORefVector< VectorVal >(_st+1)
99 typedef ORefVector< css::uno::Reference< css::beans::XPropertySet> > OSQLColumns;
101 // search from first to last the column with the name _rVal
102 // when no such column exist last is returned
103 OOO_DLLPUBLIC_DBTOOLS
104 OSQLColumns::Vector::const_iterator find( const OSQLColumns::Vector::const_iterator& first,
105 const OSQLColumns::Vector::const_iterator& last,
106 const OUString& _rVal,
107 const ::comphelper::UStringMixEqual& _rCase);
109 // search from first to last the column with the realname _rVal
110 // when no such column exist last is returned
111 OOO_DLLPUBLIC_DBTOOLS
112 OSQLColumns::Vector::const_iterator findRealName( const OSQLColumns::Vector::const_iterator& first,
113 const OSQLColumns::Vector::const_iterator& last,
114 const OUString& _rVal,
115 const ::comphelper::UStringMixEqual& _rCase);
117 // the first two find methods are much faster than the one below
118 // search from first to last the column with the property _rProp equals the value _rVal
119 // when no such column exist last is returned
120 OOO_DLLPUBLIC_DBTOOLS
121 OSQLColumns::Vector::const_iterator find( OSQLColumns::Vector::const_iterator first,
122 const OSQLColumns::Vector::const_iterator& last,
123 const OUString& _rProp,
124 const OUString& _rVal,
125 const ::comphelper::UStringMixEqual& _rCase);
127 /// @throws css::lang::DisposedException
128 OOO_DLLPUBLIC_DBTOOLS void checkDisposed(bool _bThrow);
130 #if HAVE_FEATURE_JAVA
131 /** creates a java virtual machine
132 @param _rxContext
133 The ORB.
134 @return
135 The JavaVM.
137 OOO_DLLPUBLIC_DBTOOLS ::rtl::Reference< jvmaccess::VirtualMachine > getJavaVM(const css::uno::Reference< css::uno::XComponentContext >& _rxContext);
139 /** return <TRUE/> if the java class exists, otherwise <FALSE/>.
140 @param _pJVM
141 The JavaVM.
142 @param _sClassName
143 The class name to look for.
145 OOO_DLLPUBLIC_DBTOOLS bool existsJavaClassByName( const ::rtl::Reference< jvmaccess::VirtualMachine >& _pJVM,const OUString& _sClassName );
146 #endif
149 #define DECLARE_SERVICE_INFO() \
150 virtual OUString SAL_CALL getImplementationName( ) override; \
151 virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName ) override; \
152 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override \
154 #define IMPLEMENT_SERVICE_INFO(classname, implasciiname, serviceasciiname) \
155 OUString SAL_CALL classname::getImplementationName( ) \
157 return OUString(implasciiname); \
159 css::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames( ) \
161 css::uno::Sequence< OUString > aSupported { serviceasciiname }; \
162 return aSupported; \
164 sal_Bool SAL_CALL classname::supportsService( const OUString& rServiceName ) \
166 return cppu::supportsService(this, rServiceName); \
169 #endif // INCLUDED_CONNECTIVITY_COMMONTOOLS_HXX
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */