LibreOffice Module sc (master) 1
dataprovider.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
10#pragma once
11
12#include <memory>
13#include <string_view>
14#include <salhelper/thread.hxx>
15#include <rtl/ustring.hxx>
16#include <rtl/ref.hxx>
17#include <osl/mutex.hxx>
18#include <document.hxx>
19
20#include <rtl/strbuf.hxx>
21
22#include <atomic>
23#include <vector>
24//#include <map>
25
26#include <orcus/csv_parser.hpp>
27
28class SvStream;
29class ScDBData;
30
31namespace sc {
32
33class DataTransformation;
34class ExternalDataSource;
35
37{
39 OUString maURL;
40
41 std::atomic<bool> mbTerminate;
42
43 orcus::csv::parser_config maConfig;
44
45 std::vector<std::shared_ptr<sc::DataTransformation>> maDataTransformations;
46
47 std::function<void()> maImportFinishedHdl;
48
49
50public:
51 CSVFetchThread(ScDocument& rDoc, OUString , std::function<void()> aImportFinishedHdl,
52 std::vector<std::shared_ptr<sc::DataTransformation>>&& mrDataTransformations);
53 virtual ~CSVFetchThread() override;
54
55 void RequestTerminate();
57 void Terminate();
58 void EndThread();
59
60 virtual void execute() override;
61};
62
68{
69protected:
75
76public:
78
79 virtual ~DataProvider();
80
81 virtual void Import() = 0;
82
83 virtual const OUString& GetURL() const = 0;
84
85 static std::unique_ptr<SvStream> FetchStreamFromURL(const OUString&, OStringBuffer& rBuffer);
86
87 void setDeterministic();
88};
89
91{
95
96 void Refresh();
97
98public:
100 virtual ~CSVDataProvider() override;
101
102 virtual void Import() override;
103
104 const OUString& GetURL() const override;
105 void ImportFinished();
106};
107
119{
120 OUString maDBName;
122
123public:
124 ScDBDataManager(OUString aDBName, ScDocument* pDoc);
126
127 void SetDatabase(const OUString& rDBName);
128
130
131 void WriteToDoc(ScDocument& rDoc);
132};
133
135{
136private:
137
138 static bool isInternalDataProvider(std::u16string_view rProvider);
139
140public:
141
142 static std::shared_ptr<DataProvider> getDataProvider(ScDocument* pDoc, sc::ExternalDataSource& rDataSource);
143
144 static std::vector<OUString> getDataProviders();
145};
146
147}
148
149/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const OUString & GetURL() const override
rtl::Reference< CSVFetchThread > mxCSVFetchThread
virtual ~CSVDataProvider() override
virtual void Import() override
ScDocument * mpDocument
ScDocumentUniquePtr mpDoc
CSVDataProvider(ScDocument *pDoc, sc::ExternalDataSource &rDataSource)
CSVFetchThread(ScDocument &rDoc, OUString, std::function< void()> aImportFinishedHdl, std::vector< std::shared_ptr< sc::DataTransformation > > &&mrDataTransformations)
std::vector< std::shared_ptr< sc::DataTransformation > > maDataTransformations
ScDocument & mrDocument
std::function< void()> maImportFinishedHdl
std::atomic< bool > mbTerminate
orcus::csv::parser_config maConfig
virtual ~CSVFetchThread() override
virtual void execute() override
static std::vector< OUString > getDataProviders()
static std::shared_ptr< DataProvider > getDataProvider(ScDocument *pDoc, sc::ExternalDataSource &rDataSource)
static bool isInternalDataProvider(std::u16string_view rProvider)
Abstract class for all data provider.
virtual ~DataProvider()
static std::unique_ptr< SvStream > FetchStreamFromURL(const OUString &, OStringBuffer &rBuffer)
bool mbDeterministic
If true make the threaded import deterministic for the tests.
virtual void Import()=0
DataProvider(sc::ExternalDataSource &rDataSource)
sc::ExternalDataSource & mrDataSource
virtual const OUString & GetURL() const =0
This class handles the copying of the data from the imported temporary document to the actual documen...
void WriteToDoc(ScDocument &rDoc)
ScDBData * getDBData()
void SetDatabase(const OUString &rDBName)
ScDBDataManager(OUString aDBName, ScDocument *pDoc)
std::unique_ptr< ScDocument, o3tl::default_delete< ScDocument > > ScDocumentUniquePtr
Definition: document.hxx:2720
CAUTION! The following defines must be in the same namespace as the respective type.
Definition: broadcast.cxx:15