LibreOffice Module xmlhelp (master) 1
db.hxx
Go to the documentation of this file.
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#pragma once
20
21#include <com/sun/star/ucb/XSimpleFileAccess3.hpp>
23#include <osl/diagnose.h>
24#include <rtl/string.hxx>
25#include <memory>
26#include <unordered_map>
27
28namespace helpdatafileproxy {
29
30 class HDFData
31 {
32 friend class Hdf;
33
35 std::unique_ptr<char[]> m_pBuffer;
36
37 void copyToBuffer( const char* pSrcData, int nSize );
38
39 public:
40 HDFData() : m_nSize( 0 ) {}
41
42 int getSize() const
43 { return m_nSize; }
44 const char* getData() const
45 { return m_pBuffer.get(); }
46 };
47
48 typedef std::unordered_map< OString,std::pair<int,int> > StringToValPosMap;
49 typedef std::unordered_map< OString,OString > StringToDataMap;
50
51 class Hdf
52 {
53 OUString m_aFileURL;
54 std::unique_ptr<StringToDataMap> m_pStringToDataMap;
55 std::unique_ptr<StringToValPosMap> m_pStringToValPosMap;
56 css::uno::Reference< css::ucb::XSimpleFileAccess3 >
58
59 css::uno::Sequence< sal_Int8 >
63
64 static bool implReadLenAndData(
65 const char* pData, char const * end, int& riPos, HDFData& rValue );
66
67 public:
68 //HDFHelp must get a fileURL which can then directly be used by simple file access.
69 //SimpleFileAccess requires file URLs as arguments. Passing file path may work but fails
70 //for example when using long file paths on Windows, which start with "\\?\"
71 Hdf( OUString aFileURL,
72 css::uno::Reference< css::ucb::XSimpleFileAccess3 > xSFA )
73 : m_aFileURL( std::move(aFileURL) )
74 , m_xSFA( std::move(xSFA) )
75 , m_nItRead( -1 )
76 , m_iItPos( -1 )
77 {
79 }
80 ~Hdf();
81
82 void createHashMap( bool bOptimizeForPerformance );
83 void releaseHashMap();
84
85 bool getValueForKey( const OString& rKey, HDFData& rValue );
86
87 bool startIteration();
88 bool getNextKeyAndValue( HDFData& rKey, HDFData& rValue );
89 void stopIteration();
90 Hdf(const Hdf&) = delete;
91 void operator=(const Hdf&) = delete;
92 };
93
94}
95
96/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
int getSize() const
Definition: db.hxx:42
const char * getData() const
Definition: db.hxx:44
void copyToBuffer(const char *pSrcData, int nSize)
Definition: db.cxx:51
std::unique_ptr< char[]> m_pBuffer
Definition: db.hxx:35
std::unique_ptr< StringToValPosMap > m_pStringToValPosMap
Definition: db.hxx:55
void operator=(const Hdf &)=delete
std::unique_ptr< StringToDataMap > m_pStringToDataMap
Definition: db.hxx:54
void releaseHashMap()
Definition: db.cxx:141
static bool implReadLenAndData(const char *pData, char const *end, int &riPos, HDFData &rValue)
Definition: db.cxx:62
Hdf(const Hdf &)=delete
Hdf(OUString aFileURL, css::uno::Reference< css::ucb::XSimpleFileAccess3 > xSFA)
Definition: db.hxx:71
bool getNextKeyAndValue(HDFData &rKey, HDFData &rValue)
Definition: db.cxx:243
bool startIteration()
Definition: db.cxx:219
bool getValueForKey(const OString &rKey, HDFData &rValue)
Definition: db.cxx:152
void stopIteration()
Definition: db.cxx:260
void createHashMap(bool bOptimizeForPerformance)
Definition: db.cxx:81
css::uno::Reference< css::ucb::XSimpleFileAccess3 > m_xSFA
Definition: db.hxx:57
css::uno::Sequence< sal_Int8 > m_aItData
Definition: db.hxx:60
OUString m_aFileURL
Definition: db.hxx:53
COMPHELPER_DLLPUBLIC bool isFileUrl(std::u16string_view url)
std::unordered_map< OString, OString > StringToDataMap
Definition: db.hxx:49
std::unordered_map< OString, std::pair< int, int > > StringToValPosMap
Definition: db.hxx:48