1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: flbytes.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
34 #include <tools/debug.hxx>
35 #include <tools/stream.hxx>
37 //============================================================================
38 class SvFillLockBytes
: public SvLockBytes
40 SvLockBytesRef xLockBytes
;
47 SvFillLockBytes( SvLockBytes
* pLockBytes
);
48 virtual ErrCode
ReadAt(
49 ULONG nPos
, void* pBuffer
, ULONG nCount
, ULONG
* pRead
) const;
50 virtual ErrCode
WriteAt(
51 ULONG nPos
, const void* pBuffer
, ULONG nCount
, ULONG
* pWritten
);
52 virtual ErrCode
Flush() const;
53 virtual ErrCode
SetSize( ULONG nSize
);
54 virtual ErrCode
LockRegion( ULONG nPos
, ULONG nCount
, LockType
);
55 virtual ErrCode
UnlockRegion( ULONG nPos
, ULONG nCount
, LockType
);
56 virtual ErrCode
Stat( SvLockBytesStat
*, SvLockBytesStatFlag
) const;
57 ErrCode
FillAppend( const void* pBuffer
, ULONG nCount
, ULONG
*pWritten
);
58 ULONG
Tell() const { return nFilledSize
; }
59 void Seek( ULONG nPos
) { nFilledSize
= nPos
; }
64 SV_DECL_IMPL_REF( SvFillLockBytes
)
66 //============================================================================
67 class SvSyncLockBytes
: public SvOpenLockBytes
69 SvAsyncLockBytesRef m_xAsyncLockBytes
;
74 /// Create a synchronous wrapper around existing asynchronous lock bytes.
76 /// @param pTheAsyncLockBytes Must not be null.
77 inline SvSyncLockBytes(SvAsyncLockBytes
* pTheAsyncLockBytes
);
79 /// Create a synchronous wrapper around an existing stream.
81 /// @descr This is like first creating asynchronous lock bytes around the
82 /// stream and than creating a synchronous wrapper around the asynchronous
85 /// @param pStream Must not be null.
87 /// @param bOwner True if these lock bytes own the stream (delete it on
89 SvSyncLockBytes(SvStream
* pStream
, BOOL bOwner
):
90 m_xAsyncLockBytes(new SvAsyncLockBytes(pStream
, bOwner
)) {}
92 virtual const SvStream
* GetStream() const
93 { return m_xAsyncLockBytes
->GetStream(); }
95 virtual void SetSynchronMode(BOOL bSync
= TRUE
)
96 { m_xAsyncLockBytes
->SetSynchronMode(bSync
); }
98 virtual BOOL
IsSynchronMode() const
99 { return m_xAsyncLockBytes
->IsSynchronMode(); }
101 virtual ErrCode
ReadAt(ULONG nPos
, void * pBuffer
, ULONG nCount
,
102 ULONG
* pRead
) const;
104 virtual ErrCode
WriteAt(ULONG nPos
, const void * pBuffer
, ULONG nCount
,
107 virtual ErrCode
Flush() const { return m_xAsyncLockBytes
->Flush(); }
109 virtual ErrCode
SetSize(ULONG nSize
)
110 { return m_xAsyncLockBytes
->SetSize(nSize
); }
112 virtual ErrCode
LockRegion(ULONG nPos
, ULONG nCount
, LockType eType
)
113 { return m_xAsyncLockBytes
->LockRegion(nPos
, nCount
, eType
); }
115 virtual ErrCode
UnlockRegion(ULONG nPos
, ULONG nCount
, LockType eType
)
116 { return m_xAsyncLockBytes
->UnlockRegion(nPos
, nCount
, eType
); }
118 virtual ErrCode
Stat(SvLockBytesStat
* pStat
, SvLockBytesStatFlag eFlag
)
120 { return m_xAsyncLockBytes
->Stat(pStat
, eFlag
); }
122 virtual ErrCode
FillAppend(const void * pBuffer
, ULONG nCount
,
124 { return m_xAsyncLockBytes
->FillAppend(pBuffer
, nCount
, pWritten
); }
126 virtual ULONG
Tell() const { return m_xAsyncLockBytes
->Tell(); }
128 virtual ULONG
Seek(ULONG nPos
)
129 { return m_xAsyncLockBytes
->Seek(nPos
); }
131 virtual void Terminate() { m_xAsyncLockBytes
->Terminate(); }
134 inline SvSyncLockBytes::SvSyncLockBytes(SvAsyncLockBytes
*
136 m_xAsyncLockBytes(pTheAsyncLockBytes
)
138 DBG_ASSERT(m_xAsyncLockBytes
.Is(),
139 "SvSyncLockBytes::SvSyncLockBytes(): Null");
142 SV_DECL_IMPL_REF(SvSyncLockBytes
);
144 //============================================================================
145 struct SvCompositeLockBytes_Impl
;
146 class SvCompositeLockBytes
: public SvLockBytes
148 SvCompositeLockBytes_Impl
* pImpl
;
152 SvCompositeLockBytes( );
153 ~SvCompositeLockBytes();
155 void Append( SvLockBytes
* pLockBytes
, ULONG nPos
, ULONG nOffset
);
156 ULONG
RelativeOffset( ULONG nPos
) const;
157 void SetIsPending( BOOL bSet
);
158 SvLockBytes
* GetLastLockBytes() const;
160 virtual ErrCode
ReadAt(
161 ULONG nPos
, void* pBuffer
, ULONG nCount
, ULONG
* pRead
) const;
162 virtual ErrCode
WriteAt(
163 ULONG nPos
, const void* pBuffer
, ULONG nCount
, ULONG
* pWritten
);
164 virtual ErrCode
Flush() const;
165 virtual ErrCode
SetSize( ULONG nSize
);
166 virtual ErrCode
LockRegion( ULONG nPos
, ULONG nCount
, LockType
);
167 virtual ErrCode
UnlockRegion( ULONG nPos
, ULONG nCount
, LockType
);
168 virtual ErrCode
Stat( SvLockBytesStat
*, SvLockBytesStatFlag
) const;
171 SV_DECL_IMPL_REF( SvCompositeLockBytes
)