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 HELPDATAFILEPROXY_DB_HXX_
20 : #define HELPDATAFILEPROXY_DB_HXX_
21 :
22 : #include <com/sun/star/ucb/XSimpleFileAccess3.hpp>
23 :
24 : #include <config_global.h>
25 : #if !HAVE_CXX11
26 : #define BOOST_NO_0X_HDR_TYPEINDEX
27 : #endif
28 : #include <boost/unordered_map.hpp>
29 : #include <rtl/string.hxx>
30 :
31 : namespace helpdatafileproxy {
32 :
33 : namespace hdf_internal
34 : {
35 : class Noncopyable
36 : {
37 : // not implemented
38 : Noncopyable(const Noncopyable&);
39 : void operator=(const Noncopyable&);
40 : protected:
41 0 : Noncopyable() {}
42 0 : ~Noncopyable() {}
43 : };
44 : }
45 :
46 : class HDFData
47 : {
48 : friend class Hdf;
49 :
50 : int m_nSize;
51 : char* m_pBuffer;
52 :
53 : void copyToBuffer( const char* pSrcData, int nSize );
54 :
55 : public:
56 0 : HDFData( void )
57 : : m_nSize( 0 )
58 0 : , m_pBuffer( NULL )
59 0 : {}
60 0 : ~HDFData()
61 0 : { delete [] m_pBuffer; }
62 :
63 0 : int getSize() const
64 0 : { return m_nSize; }
65 0 : const char* getData() const
66 0 : { return m_pBuffer; }
67 : };
68 :
69 : struct eq
70 : {
71 0 : bool operator()( const OString& rKey1, const OString& rKey2 ) const
72 0 : { return (rKey1 == rKey2); }
73 : };
74 :
75 : struct ha
76 : {
77 0 : size_t operator()( const OString& rName ) const
78 0 : { return rName.hashCode(); }
79 : };
80 :
81 : typedef boost::unordered_map< OString,std::pair<int,int>,ha,eq > StringToValPosMap;
82 : typedef boost::unordered_map< OString,OString,ha,eq > StringToDataMap;
83 :
84 : class Hdf : hdf_internal::Noncopyable
85 : {
86 : OUString m_aFileURL;
87 : StringToDataMap* m_pStringToDataMap;
88 : StringToValPosMap* m_pStringToValPosMap;
89 : com::sun::star::uno::Reference< com::sun::star::ucb::XSimpleFileAccess3 >
90 : m_xSFA;
91 :
92 : com::sun::star::uno::Sequence< sal_Int8 >
93 : m_aItData;
94 : const char* m_pItData;
95 : int m_nItRead;
96 : int m_iItPos;
97 :
98 : bool implReadLenAndData( const char* pData, int& riPos, HDFData& rValue );
99 :
100 : public:
101 : //HDFHelp must get a fileURL which can then directly be used by simple file access.
102 : //SimpleFileAccess requires file URLs as arguments. Passing file path may work but fails
103 : //for example when using long file paths on Windows, which start with "\\?\"
104 0 : Hdf( const OUString& rFileURL,
105 : com::sun::star::uno::Reference< com::sun::star::ucb::XSimpleFileAccess3 > xSFA )
106 : : m_aFileURL( rFileURL )
107 : , m_pStringToDataMap( NULL )
108 : , m_pStringToValPosMap( NULL )
109 : , m_xSFA( xSFA )
110 : , m_pItData( NULL )
111 : , m_nItRead( -1 )
112 0 : , m_iItPos( -1 )
113 : {
114 : OSL_ASSERT(rFileURL.startsWith("file:"));
115 0 : }
116 0 : ~Hdf()
117 0 : { releaseHashMap(); }
118 :
119 : void createHashMap( bool bOptimizeForPerformance = false );
120 : void releaseHashMap( void );
121 :
122 : bool getValueForKey( const OString& rKey, HDFData& rValue );
123 :
124 : bool startIteration( void );
125 : bool getNextKeyAndValue( HDFData& rKey, HDFData& rValue );
126 : void stopIteration( void );
127 : };
128 : }
129 :
130 : #endif
131 :
132 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|