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