LibreOffice Module sot (master) 1
storage.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
20#ifndef INCLUDED_SOT_STORAGE_HXX
21#define INCLUDED_SOT_STORAGE_HXX
22
23#include <sot/object.hxx>
24#include <tools/stream.hxx>
25#include <tools/globname.hxx>
27#include <sot/storinfo.hxx>
28#include <sot/sotdllapi.h>
29
30namespace com::sun::star::embed { class XStorage; }
31namespace com::sun::star::uno { class Any; }
32namespace com::sun::star::uno { template <typename > class Reference; }
33
34enum class SotClipboardFormatId : sal_uInt32;
35
37
38class SOT_DLLPUBLIC SotTempStream final : virtual public SvRefBase, public SvStream
39{
40friend class SotStorage;
41
42 virtual ~SotTempStream() override;
43public:
44 SotTempStream(OUString const & rString, StreamMode = StreamMode::STD_READWRITE);
45
46 void CopyTo(SotTempStream * pDestStm);
47};
48
49class SOT_DLLPUBLIC SotStorageStream final : virtual public SotObject, public SvStream
50{
51friend class SotStorage;
52 BaseStorageStream * pOwnStm; // pointer to the own stream
53
54 virtual std::size_t GetData(void* pData, std::size_t nSize) override;
55 virtual std::size_t PutData(const void* pData, std::size_t nSize) override;
56 virtual sal_uInt64 SeekPos(sal_uInt64 nPos) override;
57 virtual void FlushData() override;
58
59 virtual ~SotStorageStream() override;
60public:
62
63 virtual void ResetError() override;
64
65 virtual void SetSize(sal_uInt64 nNewSize) override;
66 sal_uInt32 GetSize() const;
67 void Commit();
68 bool SetProperty(OUString const & rName, css::uno::Any const & rValue);
69 virtual sal_uInt64 TellEnd() override;
70};
71
72class BaseStorage;
73class SOT_DLLPUBLIC SotStorage final : virtual public SotObject
74{
75friend class SotStorageStream;
76
77 BaseStorage* m_pOwnStg; // target storage
78 SvStream* m_pStorStm; // only for SDSTORAGES
80 OUString m_aName;// name of the storage
81 bool m_bIsRoot; // e.g.: File Storage
83 OString m_aKey; // aKey.Len != 0 -> encryption
84 sal_Int32 m_nVersion;
85
86 virtual ~SotStorage() override;
87 void CreateStorage(bool bUCBStorage, StreamMode);
88public:
89 SotStorage(OUString const & rString, StreamMode eMode = StreamMode::STD_READWRITE);
90 SotStorage(bool bUCBStorage, const OUString & rString,
91 StreamMode = StreamMode::STD_READWRITE);
92 SotStorage(BaseStorage * pStorage);
93 SotStorage(SvStream & rStream);
94 SotStorage(bool bUCBStorage, SvStream & rStream);
95 SotStorage(SvStream * rStream, bool bDelete);
96
97 std::unique_ptr<SvMemoryStream> CreateMemoryStream();
98
99 static bool IsStorageFile(OUString const & rFileName);
100 static bool IsStorageFile(SvStream* pStream);
101
102 const OUString& GetName() const;
103
104 bool Validate();
105
106 const OString& GetKey() const { return m_aKey;}
107
108 void SetVersion(sal_Int32 nVersion)
109 {
111 }
112 sal_Int32 GetVersion() const
113 {
114 return m_nVersion;
115 }
116
118 {
119 return m_nError.IgnoreWarning();
120 }
121 void SetError(ErrCode nErrorCode)
122 {
123 if (m_nError == ERRCODE_NONE)
124 m_nError = nErrorCode;
125 }
126
127 void SignAsRoot(bool bRoot) { m_bIsRoot = bRoot; }
128
129 // own data sector
130 void SetClass(const SvGlobalName & rClass,
131 SotClipboardFormatId bOriginalClipFormat,
132 const OUString & rUserTypeName);
133
134 SvGlobalName GetClassName(); // type of data in the storage
136 OUString GetUserName();
137
138 // list of all elements
139 void FillInfoList(SvStorageInfoList *) const;
140 bool CopyTo(SotStorage * pDestStg);
141 bool Commit();
142
143 // create stream with connection to Storage,
144 // more or less a Parent-Child relationship
145 tools::SvRef<SotStorageStream> OpenSotStream(const OUString & rEleName,
146 StreamMode = StreamMode::STD_READWRITE);
147 SotStorage* OpenSotStorage(const OUString & rEleName,
148 StreamMode = StreamMode::STD_READWRITE,
149 bool transacted = true);
150
151 // query whether Storage or Stream
152 bool IsStream( const OUString & rEleName ) const;
153 bool IsStorage( const OUString & rEleName ) const;
154 bool IsContained( const OUString & rEleName ) const;
155 // remove element
156 bool Remove(const OUString & rEleName);
157 bool CopyTo(const OUString & rEleName, SotStorage* pDest,
158 const OUString & rNewName);
159
160 bool IsOLEStorage() const;
161 static bool IsOLEStorage(const OUString & rFileName);
162 static bool IsOLEStorage(SvStream* pStream);
163
164 static SotStorage* OpenOLEStorage(css::uno::Reference<css::embed::XStorage> const & xStorage,
165 OUString const & rEleName, StreamMode = StreamMode::STD_READWRITE);
166 static SotClipboardFormatId GetFormatID(css::uno::Reference<css::embed::XStorage> const & xStorage);
167 static sal_Int32 GetVersion(css::uno::Reference<css::embed::XStorage> const & xStorage);
168};
169
170#endif // INCLUDED_SOT_STORAGE_HXX
171
172/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ErrCode IgnoreWarning() const
BaseStorageStream * pOwnStm
Definition: storage.hxx:52
friend class SotStorage
Definition: storage.hxx:51
bool m_bDelStm
Definition: storage.hxx:82
bool m_bIsRoot
Definition: storage.hxx:81
sal_Int32 GetVersion() const
Definition: storage.hxx:112
SvStream * m_pStorStm
Definition: storage.hxx:78
bool CopyTo(SotStorage *pDestStg)
Definition: storage.cxx:504
const OString & GetKey() const
Definition: storage.hxx:106
BaseStorage * m_pOwnStg
Definition: storage.hxx:77
OUString m_aName
Definition: storage.hxx:80
void SetVersion(sal_Int32 nVersion)
Definition: storage.hxx:108
ErrCode m_nError
Definition: storage.hxx:79
bool Commit()
Definition: storage.cxx:519
sal_Int32 m_nVersion
Definition: storage.hxx:84
ErrCode GetError() const
Definition: storage.hxx:117
void SignAsRoot(bool bRoot)
Definition: storage.hxx:127
void SetError(ErrCode nErrorCode)
Definition: storage.hxx:121
OString m_aKey
Definition: storage.hxx:83
friend class SotStorageStream
Definition: storage.hxx:75
virtual void ResetError()
virtual sal_uInt64 TellEnd()
virtual sal_uInt64 SeekPos(sal_uInt64 nPos)
virtual void SetSize(sal_uInt64 nSize)
sal_Int32 m_nVersion
sal_Int32 GetVersion() const
virtual std::size_t GetData(void *pData, std::size_t nSize)
ErrCode m_nError
virtual std::size_t PutData(const void *pData, std::size_t nSize)
virtual void FlushData()
virtual OUString GetName() const override
virtual SotClipboardFormatId GetFormat(const TransferableDataHelper &aHelper) override
#define ERRCODE_NONE
sal_Int16 nVersion
SotClipboardFormatId
Definition: formats.hxx:28
Reference
#define SOT_DLLPUBLIC
Definition: sotdllapi.h:28
std::vector< SvStorageInfo > SvStorageInfoList
Definition: storinfo.hxx:56
StreamMode