bump product version to 5.0.4.1
[LibreOffice.git] / xmlhelp / source / cxxhelp / provider / db.hxx
blobbdfaa38d84dde79864a756b9b9802f2495183fcc
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_XMLHELP_SOURCE_CXXHELP_PROVIDER_DB_HXX
20 #define INCLUDED_XMLHELP_SOURCE_CXXHELP_PROVIDER_DB_HXX
22 #include <com/sun/star/ucb/XSimpleFileAccess3.hpp>
24 #include <osl/diagnose.h>
25 #include <rtl/string.hxx>
26 #include <unordered_map>
28 namespace helpdatafileproxy {
30 namespace hdf_internal
32 class Noncopyable
34 Noncopyable(const Noncopyable&) SAL_DELETED_FUNCTION;
35 void operator=(const Noncopyable&) SAL_DELETED_FUNCTION;
36 protected:
37 Noncopyable() {}
38 ~Noncopyable() {}
42 class HDFData
44 friend class Hdf;
46 int m_nSize;
47 char* m_pBuffer;
49 void copyToBuffer( const char* pSrcData, int nSize );
51 public:
52 HDFData()
53 : m_nSize( 0 )
54 , m_pBuffer( NULL )
56 ~HDFData()
57 { delete [] m_pBuffer; }
59 int getSize() const
60 { return m_nSize; }
61 const char* getData() const
62 { return m_pBuffer; }
65 typedef std::unordered_map< OString,std::pair<int,int>,OStringHash > StringToValPosMap;
66 typedef std::unordered_map< OString,OString,OStringHash > StringToDataMap;
68 class Hdf : hdf_internal::Noncopyable
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;
76 com::sun::star::uno::Sequence< sal_Int8 >
77 m_aItData;
78 const char* m_pItData;
79 int m_nItRead;
80 int m_iItPos;
82 static bool implReadLenAndData( const char* pData, int& riPos, HDFData& rValue );
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 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 , m_iItPos( -1 )
98 OSL_ASSERT(rFileURL.startsWith("file:"));
100 ~Hdf()
101 { releaseHashMap(); }
103 void createHashMap( bool bOptimizeForPerformance = false );
104 void releaseHashMap();
106 bool getValueForKey( const OString& rKey, HDFData& rValue );
108 bool startIteration();
109 bool getNextKeyAndValue( HDFData& rKey, HDFData& rValue );
110 void stopIteration();
114 #endif
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */