Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #ifndef INCLUDED_XMLHELP_SOURCE_CXXHELP_PROVIDER_DB_HXX
20 : #define INCLUDED_XMLHELP_SOURCE_CXXHELP_PROVIDER_DB_HXX
21 :
22 : #include <com/sun/star/ucb/XSimpleFileAccess3.hpp>
23 :
24 : #include <osl/diagnose.h>
25 : #include <rtl/string.hxx>
26 : #include <unordered_map>
27 :
28 : namespace helpdatafileproxy {
29 :
30 : namespace hdf_internal
31 : {
32 : class Noncopyable
33 : {
34 : Noncopyable(const Noncopyable&) SAL_DELETED_FUNCTION;
35 : void operator=(const Noncopyable&) SAL_DELETED_FUNCTION;
36 : protected:
37 0 : Noncopyable() {}
38 0 : ~Noncopyable() {}
39 : };
40 : }
41 :
42 : class HDFData
43 : {
44 : friend class Hdf;
45 :
46 : int m_nSize;
47 : char* m_pBuffer;
48 :
49 : void copyToBuffer( const char* pSrcData, int nSize );
50 :
51 : public:
52 2900 : HDFData()
53 : : m_nSize( 0 )
54 2900 : , m_pBuffer( NULL )
55 2900 : {}
56 2900 : ~HDFData()
57 2900 : { delete [] m_pBuffer; }
58 :
59 0 : int getSize() const
60 0 : { return m_nSize; }
61 0 : const char* getData() const
62 0 : { return m_pBuffer; }
63 : };
64 :
65 : typedef std::unordered_map< OString,std::pair<int,int>,OStringHash > StringToValPosMap;
66 : typedef std::unordered_map< OString,OString,OStringHash > StringToDataMap;
67 :
68 : class Hdf : hdf_internal::Noncopyable
69 : {
70 : OUString m_aFileURL;
71 : StringToDataMap* m_pStringToDataMap;
72 : StringToValPosMap* m_pStringToValPosMap;
73 : com::sun::star::uno::Reference< com::sun::star::ucb::XSimpleFileAccess3 >
74 : m_xSFA;
75 :
76 : com::sun::star::uno::Sequence< sal_Int8 >
77 : m_aItData;
78 : const char* m_pItData;
79 : int m_nItRead;
80 : int m_iItPos;
81 :
82 : static bool implReadLenAndData( const char* pData, int& riPos, HDFData& rValue );
83 :
84 : public:
85 : //HDFHelp must get a fileURL which can then directly be used by simple file access.
86 : //SimpleFileAccess requires file URLs as arguments. Passing file path may work but fails
87 : //for example when using long file paths on Windows, which start with "\\?\"
88 0 : Hdf( const OUString& rFileURL,
89 : com::sun::star::uno::Reference< com::sun::star::ucb::XSimpleFileAccess3 > xSFA )
90 : : m_aFileURL( rFileURL )
91 : , m_pStringToDataMap( NULL )
92 : , m_pStringToValPosMap( NULL )
93 : , m_xSFA( xSFA )
94 : , m_pItData( NULL )
95 : , m_nItRead( -1 )
96 0 : , m_iItPos( -1 )
97 : {
98 : OSL_ASSERT(rFileURL.startsWith("file:"));
99 0 : }
100 0 : ~Hdf()
101 0 : { releaseHashMap(); }
102 :
103 : void createHashMap( bool bOptimizeForPerformance = false );
104 : void releaseHashMap();
105 :
106 : bool getValueForKey( const OString& rKey, HDFData& rValue );
107 :
108 : bool startIteration();
109 : bool getNextKeyAndValue( HDFData& rKey, HDFData& rValue );
110 : void stopIteration();
111 : };
112 : }
113 :
114 : #endif
115 :
116 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|