UDK 3.2.7 C/C++ API Reference
|
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 00002 /************************************************************************* 00003 * 00004 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 00005 * 00006 * Copyright 2000, 2010 Oracle and/or its affiliates. 00007 * 00008 * OpenOffice.org - a multi-platform office productivity suite 00009 * 00010 * This file is part of OpenOffice.org. 00011 * 00012 * OpenOffice.org is free software: you can redistribute it and/or modify 00013 * it under the terms of the GNU Lesser General Public License version 3 00014 * only, as published by the Free Software Foundation. 00015 * 00016 * OpenOffice.org is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Lesser General Public License version 3 for more details 00020 * (a copy is included in the LICENSE file that accompanied this code). 00021 * 00022 * You should have received a copy of the GNU Lesser General Public License 00023 * version 3 along with OpenOffice.org. If not, see 00024 * <http://www.openoffice.org/license.html> 00025 * for a copy of the LGPLv3 License. 00026 * 00027 ************************************************************************/ 00028 00029 #ifndef _STORE_STORE_HXX_ 00030 #define _STORE_STORE_HXX_ 00031 00032 #include "sal/types.h" 00033 #include "rtl/ustring.hxx" 00034 #include "store/store.h" 00035 00036 namespace store 00037 { 00038 00039 /*======================================================================== 00040 * 00041 * OStoreStream interface. 00042 * 00043 *======================================================================*/ 00044 class OStoreStream 00045 { 00046 public: 00049 inline OStoreStream (void) SAL_THROW(()) 00050 : m_hImpl (0) 00051 {} 00052 00055 inline ~OStoreStream (void) SAL_THROW(()) 00056 { 00057 if (m_hImpl) 00058 (void) store_releaseHandle (m_hImpl); 00059 } 00060 00063 inline OStoreStream (OStoreStream const & rhs) SAL_THROW(()) 00064 : m_hImpl (rhs.m_hImpl) 00065 { 00066 if (m_hImpl) 00067 (void) store_acquireHandle (m_hImpl); 00068 } 00069 00072 inline OStoreStream & operator= (OStoreStream const & rhs) SAL_THROW(()) 00073 { 00074 if (rhs.m_hImpl) 00075 (void) store_acquireHandle (rhs.m_hImpl); 00076 if (m_hImpl) 00077 (void) store_releaseHandle (m_hImpl); 00078 m_hImpl = rhs.m_hImpl; 00079 return *this; 00080 } 00081 00084 inline explicit OStoreStream (storeStreamHandle Handle) SAL_THROW(()) 00085 : m_hImpl (Handle) 00086 { 00087 if (m_hImpl) 00088 (void) store_acquireHandle (m_hImpl); 00089 } 00090 00093 inline operator storeStreamHandle (void) const SAL_THROW(()) 00094 { 00095 return m_hImpl; 00096 } 00097 00101 inline bool isValid (void) const SAL_THROW(()) 00102 { 00103 return (m_hImpl != 0); 00104 } 00105 00109 inline storeError create ( 00110 storeFileHandle hFile, 00111 rtl::OUString const & rPath, 00112 rtl::OUString const & rName, 00113 storeAccessMode eMode) SAL_THROW(()) 00114 { 00115 if (m_hImpl) 00116 { 00117 (void) store_releaseHandle (m_hImpl); 00118 m_hImpl = 0; 00119 } 00120 return store_openStream (hFile, rPath.pData, rName.pData, eMode, &m_hImpl); 00121 } 00122 00126 inline void close (void) SAL_THROW(()) 00127 { 00128 if (m_hImpl) 00129 { 00130 (void) store_closeStream (m_hImpl); 00131 m_hImpl = 0; 00132 } 00133 } 00134 00138 inline storeError readAt ( 00139 sal_uInt32 nOffset, 00140 void * pBuffer, 00141 sal_uInt32 nBytes, 00142 sal_uInt32 & rnDone) SAL_THROW(()) 00143 { 00144 if (!m_hImpl) 00145 return store_E_InvalidHandle; 00146 00147 return store_readStream (m_hImpl, nOffset, pBuffer, nBytes, &rnDone); 00148 } 00149 00153 inline storeError writeAt ( 00154 sal_uInt32 nOffset, 00155 void const * pBuffer, 00156 sal_uInt32 nBytes, 00157 sal_uInt32 & rnDone) SAL_THROW(()) 00158 { 00159 if (!m_hImpl) 00160 return store_E_InvalidHandle; 00161 00162 return store_writeStream (m_hImpl, nOffset, pBuffer, nBytes, &rnDone); 00163 } 00164 00168 inline storeError flush (void) const SAL_THROW(()) 00169 { 00170 if (!m_hImpl) 00171 return store_E_InvalidHandle; 00172 00173 return store_flushStream (m_hImpl); 00174 } 00175 00179 inline storeError getSize (sal_uInt32 & rnSize) const SAL_THROW(()) 00180 { 00181 if (!m_hImpl) 00182 return store_E_InvalidHandle; 00183 00184 return store_getStreamSize (m_hImpl, &rnSize); 00185 } 00186 00190 inline storeError setSize (sal_uInt32 nSize) SAL_THROW(()) 00191 { 00192 if (!m_hImpl) 00193 return store_E_InvalidHandle; 00194 00195 return store_setStreamSize (m_hImpl, nSize); 00196 } 00197 00198 private: 00201 storeStreamHandle m_hImpl; 00202 }; 00203 00204 /*======================================================================== 00205 * 00206 * OStoreDirectory interface. 00207 * 00208 *======================================================================*/ 00209 class OStoreDirectory 00210 { 00211 public: 00214 inline OStoreDirectory (void) SAL_THROW(()) 00215 : m_hImpl (0) 00216 {} 00217 00220 inline ~OStoreDirectory (void) SAL_THROW(()) 00221 { 00222 if (m_hImpl) 00223 (void) store_releaseHandle (m_hImpl); 00224 } 00225 00228 inline OStoreDirectory (OStoreDirectory const & rhs) SAL_THROW(()) 00229 : m_hImpl (rhs.m_hImpl) 00230 { 00231 if (m_hImpl) 00232 (void) store_acquireHandle (m_hImpl); 00233 } 00234 00237 inline OStoreDirectory & operator= (OStoreDirectory const & rhs) SAL_THROW(()) 00238 { 00239 if (rhs.m_hImpl) 00240 (void) store_acquireHandle (rhs.m_hImpl); 00241 if (m_hImpl) 00242 (void) store_releaseHandle (m_hImpl); 00243 m_hImpl = rhs.m_hImpl; 00244 return *this; 00245 } 00246 00249 inline explicit OStoreDirectory (storeDirectoryHandle Handle) SAL_THROW(()) 00250 : m_hImpl (Handle) 00251 { 00252 if (m_hImpl) 00253 (void) store_acquireHandle (m_hImpl); 00254 } 00255 00258 inline operator storeDirectoryHandle(void) const SAL_THROW(()) 00259 { 00260 return m_hImpl; 00261 } 00262 00266 inline bool isValid (void) const SAL_THROW(()) 00267 { 00268 return (m_hImpl != 0); 00269 } 00270 00274 inline storeError create ( 00275 storeFileHandle hFile, 00276 rtl::OUString const & rPath, 00277 rtl::OUString const & rName, 00278 storeAccessMode eMode) SAL_THROW(()) 00279 { 00280 if (m_hImpl) 00281 { 00282 (void) store_releaseHandle (m_hImpl); 00283 m_hImpl = 0; 00284 } 00285 return store_openDirectory (hFile, rPath.pData, rName.pData, eMode, &m_hImpl); 00286 } 00287 00291 inline void close (void) SAL_THROW(()) 00292 { 00293 if (m_hImpl) 00294 { 00295 (void) store_closeDirectory (m_hImpl); 00296 m_hImpl = 0; 00297 } 00298 } 00299 00304 typedef storeFindData iterator; 00305 00309 inline storeError first (iterator& it) SAL_THROW(()) 00310 { 00311 if (!m_hImpl) 00312 return store_E_InvalidHandle; 00313 00314 return store_findFirst (m_hImpl, &it); 00315 } 00316 00320 inline storeError next (iterator& it) SAL_THROW(()) 00321 { 00322 if (!m_hImpl) 00323 return store_E_InvalidHandle; 00324 00325 return store_findNext (m_hImpl, &it); 00326 } 00327 00331 class traveller 00332 { 00333 public: 00338 virtual sal_Bool visit (const iterator& it) = 0; 00339 00340 protected: 00341 ~traveller() {} 00342 }; 00343 00351 inline storeError travel (traveller & rTraveller) const 00352 { 00353 storeError eErrCode = store_E_InvalidHandle; 00354 if (m_hImpl) 00355 { 00356 iterator it; 00357 eErrCode = store_findFirst (m_hImpl, &it); 00358 while ((eErrCode == store_E_None) && rTraveller.visit(it)) 00359 eErrCode = store_findNext (m_hImpl, &it); 00360 } 00361 return eErrCode; 00362 } 00363 00364 private: 00367 storeDirectoryHandle m_hImpl; 00368 }; 00369 00370 /*======================================================================== 00371 * 00372 * OStoreFile interface. 00373 * 00374 *======================================================================*/ 00375 class OStoreFile 00376 { 00377 public: 00380 inline OStoreFile (void) SAL_THROW(()) 00381 : m_hImpl (0) 00382 {} 00383 00386 inline ~OStoreFile (void) SAL_THROW(()) 00387 { 00388 if (m_hImpl) 00389 (void) store_releaseHandle (m_hImpl); 00390 } 00391 00394 inline OStoreFile (OStoreFile const & rhs) SAL_THROW(()) 00395 : m_hImpl (rhs.m_hImpl) 00396 { 00397 if (m_hImpl) 00398 (void) store_acquireHandle (m_hImpl); 00399 } 00400 00403 inline OStoreFile & operator= (OStoreFile const & rhs) SAL_THROW(()) 00404 { 00405 if (rhs.m_hImpl) 00406 (void) store_acquireHandle (rhs.m_hImpl); 00407 if (m_hImpl) 00408 (void) store_releaseHandle (m_hImpl); 00409 m_hImpl = rhs.m_hImpl; 00410 return *this; 00411 } 00412 00415 inline explicit OStoreFile (storeFileHandle Handle) SAL_THROW(()) 00416 : m_hImpl (Handle) 00417 { 00418 if (m_hImpl) 00419 (void) store_acquireHandle (m_hImpl); 00420 } 00421 00424 inline operator storeFileHandle (void) const SAL_THROW(()) 00425 { 00426 return m_hImpl; 00427 } 00428 00432 inline bool isValid (void) const SAL_THROW(()) 00433 { 00434 return (m_hImpl != 0); 00435 } 00436 00440 inline storeError create ( 00441 rtl::OUString const & rFilename, 00442 storeAccessMode eAccessMode, 00443 sal_uInt16 nPageSize = STORE_DEFAULT_PAGESIZE) SAL_THROW(()) 00444 { 00445 if (m_hImpl) 00446 { 00447 (void) store_releaseHandle (m_hImpl); 00448 m_hImpl = 0; 00449 } 00450 return store_openFile (rFilename.pData, eAccessMode, nPageSize, &m_hImpl); 00451 } 00452 00456 inline storeError createInMemory ( 00457 sal_uInt16 nPageSize = STORE_DEFAULT_PAGESIZE) SAL_THROW(()) 00458 { 00459 if (m_hImpl) 00460 { 00461 (void) store_releaseHandle (m_hImpl); 00462 m_hImpl = 0; 00463 } 00464 return store_createMemoryFile (nPageSize, &m_hImpl); 00465 } 00466 00470 inline void close (void) SAL_THROW(()) 00471 { 00472 if (m_hImpl) 00473 { 00474 (void) store_closeFile (m_hImpl); 00475 m_hImpl = 0; 00476 } 00477 } 00478 00482 inline storeError flush (void) const SAL_THROW(()) 00483 { 00484 if (!m_hImpl) 00485 return store_E_InvalidHandle; 00486 00487 return store_flushFile (m_hImpl); 00488 } 00489 00493 inline storeError getRefererCount (sal_uInt32 & rnRefCount) const SAL_THROW(()) 00494 { 00495 if (!m_hImpl) 00496 return store_E_InvalidHandle; 00497 00498 return store_getFileRefererCount (m_hImpl, &rnRefCount); 00499 } 00500 00504 inline storeError getSize (sal_uInt32 & rnSize) const SAL_THROW(()) 00505 { 00506 if (!m_hImpl) 00507 return store_E_InvalidHandle; 00508 00509 return store_getFileSize (m_hImpl, &rnSize); 00510 } 00511 00515 inline storeError attrib ( 00516 rtl::OUString const & rPath, 00517 rtl::OUString const & rName, 00518 sal_uInt32 nMask1, 00519 sal_uInt32 nMask2, 00520 sal_uInt32 & rnAttrib) SAL_THROW(()) 00521 { 00522 if (!m_hImpl) 00523 return store_E_InvalidHandle; 00524 00525 return store_attrib (m_hImpl, rPath.pData, rName.pData, nMask1, nMask2, &rnAttrib); 00526 } 00527 00531 inline storeError attrib ( 00532 rtl::OUString const & rPath, 00533 rtl::OUString const & rName, 00534 sal_uInt32 nMask1, 00535 sal_uInt32 nMask2) SAL_THROW(()) 00536 { 00537 if (!m_hImpl) 00538 return store_E_InvalidHandle; 00539 00540 return store_attrib (m_hImpl, rPath.pData, rName.pData, nMask1, nMask2, NULL); 00541 } 00542 00546 inline storeError link ( 00547 rtl::OUString const & rSrcPath, rtl::OUString const & rSrcName, 00548 rtl::OUString const & rDstPath, rtl::OUString const & rDstName) SAL_THROW(()) 00549 { 00550 if (!m_hImpl) 00551 return store_E_InvalidHandle; 00552 00553 return store_link ( 00554 m_hImpl, rSrcPath.pData, rSrcName.pData, rDstPath.pData, rDstName.pData); 00555 } 00556 00560 inline storeError symlink ( 00561 rtl::OUString const & rSrcPath, rtl::OUString const & rSrcName, 00562 rtl::OUString const & rDstPath, rtl::OUString const & rDstName) SAL_THROW(()) 00563 { 00564 if (!m_hImpl) 00565 return store_E_InvalidHandle; 00566 00567 return store_symlink (m_hImpl, rSrcPath.pData, rSrcName.pData, rDstPath.pData, rDstName.pData); 00568 } 00569 00573 inline storeError rename ( 00574 rtl::OUString const & rSrcPath, rtl::OUString const & rSrcName, 00575 rtl::OUString const & rDstPath, rtl::OUString const & rDstName) SAL_THROW(()) 00576 { 00577 if (!m_hImpl) 00578 return store_E_InvalidHandle; 00579 00580 return store_rename (m_hImpl, rSrcPath.pData, rSrcName.pData, rDstPath.pData, rDstName.pData); 00581 } 00582 00586 inline storeError remove ( 00587 rtl::OUString const & rPath, rtl::OUString const & rName) SAL_THROW(()) 00588 { 00589 if (!m_hImpl) 00590 return store_E_InvalidHandle; 00591 00592 return store_remove (m_hImpl, rPath.pData, rName.pData); 00593 } 00594 00595 private: 00598 storeFileHandle m_hImpl; 00599 }; 00600 00601 /*======================================================================== 00602 * 00603 * The End. 00604 * 00605 *======================================================================*/ 00606 00607 } // namespace store 00608 00609 #endif /* !_STORE_STORE_HXX_ */ 00610 00611 00612 00613 00614 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */