|
UDK 3.2.7 C/C++ API Reference
|
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 00002 /* 00003 * This file is part of the LibreOffice project. 00004 * 00005 * This Source Code Form is subject to the terms of the Mozilla Public 00006 * License, v. 2.0. If a copy of the MPL was not distributed with this 00007 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 00008 * 00009 * This file incorporates work covered by the following license notice: 00010 * 00011 * Licensed to the Apache Software Foundation (ASF) under one or more 00012 * contributor license agreements. See the NOTICE file distributed 00013 * with this work for additional information regarding copyright 00014 * ownership. The ASF licenses this file to you under the Apache 00015 * License, Version 2.0 (the "License"); you may not use this file 00016 * except in compliance with the License. You may obtain a copy of 00017 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 00018 */ 00019 00020 #ifndef _STORE_STORE_HXX_ 00021 #define _STORE_STORE_HXX_ 00022 00023 #include "sal/types.h" 00024 #include "rtl/ustring.hxx" 00025 #include "store/store.h" 00026 00027 namespace store 00028 { 00029 00030 /*======================================================================== 00031 * 00032 * OStoreStream interface. 00033 * 00034 *======================================================================*/ 00035 class OStoreStream 00036 { 00037 public: 00040 inline OStoreStream (void) SAL_THROW(()) 00041 : m_hImpl (0) 00042 {} 00043 00046 inline ~OStoreStream (void) SAL_THROW(()) 00047 { 00048 if (m_hImpl) 00049 (void) store_releaseHandle (m_hImpl); 00050 } 00051 00054 inline OStoreStream (OStoreStream const & rhs) SAL_THROW(()) 00055 : m_hImpl (rhs.m_hImpl) 00056 { 00057 if (m_hImpl) 00058 (void) store_acquireHandle (m_hImpl); 00059 } 00060 00063 inline OStoreStream & operator= (OStoreStream const & rhs) SAL_THROW(()) 00064 { 00065 if (rhs.m_hImpl) 00066 (void) store_acquireHandle (rhs.m_hImpl); 00067 if (m_hImpl) 00068 (void) store_releaseHandle (m_hImpl); 00069 m_hImpl = rhs.m_hImpl; 00070 return *this; 00071 } 00072 00075 inline explicit OStoreStream (storeStreamHandle Handle) SAL_THROW(()) 00076 : m_hImpl (Handle) 00077 { 00078 if (m_hImpl) 00079 (void) store_acquireHandle (m_hImpl); 00080 } 00081 00084 inline operator storeStreamHandle (void) const SAL_THROW(()) 00085 { 00086 return m_hImpl; 00087 } 00088 00092 inline bool isValid (void) const SAL_THROW(()) 00093 { 00094 return (m_hImpl != 0); 00095 } 00096 00100 inline storeError create ( 00101 storeFileHandle hFile, 00102 rtl::OUString const & rPath, 00103 rtl::OUString const & rName, 00104 storeAccessMode eMode) SAL_THROW(()) 00105 { 00106 if (m_hImpl) 00107 { 00108 (void) store_releaseHandle (m_hImpl); 00109 m_hImpl = 0; 00110 } 00111 return store_openStream (hFile, rPath.pData, rName.pData, eMode, &m_hImpl); 00112 } 00113 00117 inline void close (void) SAL_THROW(()) 00118 { 00119 if (m_hImpl) 00120 { 00121 (void) store_closeStream (m_hImpl); 00122 m_hImpl = 0; 00123 } 00124 } 00125 00129 inline storeError readAt ( 00130 sal_uInt32 nOffset, 00131 void * pBuffer, 00132 sal_uInt32 nBytes, 00133 sal_uInt32 & rnDone) SAL_THROW(()) 00134 { 00135 if (!m_hImpl) 00136 return store_E_InvalidHandle; 00137 00138 return store_readStream (m_hImpl, nOffset, pBuffer, nBytes, &rnDone); 00139 } 00140 00144 inline storeError writeAt ( 00145 sal_uInt32 nOffset, 00146 void const * pBuffer, 00147 sal_uInt32 nBytes, 00148 sal_uInt32 & rnDone) SAL_THROW(()) 00149 { 00150 if (!m_hImpl) 00151 return store_E_InvalidHandle; 00152 00153 return store_writeStream (m_hImpl, nOffset, pBuffer, nBytes, &rnDone); 00154 } 00155 00159 inline storeError flush (void) const SAL_THROW(()) 00160 { 00161 if (!m_hImpl) 00162 return store_E_InvalidHandle; 00163 00164 return store_flushStream (m_hImpl); 00165 } 00166 00170 inline storeError getSize (sal_uInt32 & rnSize) const SAL_THROW(()) 00171 { 00172 if (!m_hImpl) 00173 return store_E_InvalidHandle; 00174 00175 return store_getStreamSize (m_hImpl, &rnSize); 00176 } 00177 00181 inline storeError setSize (sal_uInt32 nSize) SAL_THROW(()) 00182 { 00183 if (!m_hImpl) 00184 return store_E_InvalidHandle; 00185 00186 return store_setStreamSize (m_hImpl, nSize); 00187 } 00188 00189 private: 00192 storeStreamHandle m_hImpl; 00193 }; 00194 00195 /*======================================================================== 00196 * 00197 * OStoreDirectory interface. 00198 * 00199 *======================================================================*/ 00200 class OStoreDirectory 00201 { 00202 public: 00205 inline OStoreDirectory (void) SAL_THROW(()) 00206 : m_hImpl (0) 00207 {} 00208 00211 inline ~OStoreDirectory (void) SAL_THROW(()) 00212 { 00213 if (m_hImpl) 00214 (void) store_releaseHandle (m_hImpl); 00215 } 00216 00219 inline OStoreDirectory (OStoreDirectory const & rhs) SAL_THROW(()) 00220 : m_hImpl (rhs.m_hImpl) 00221 { 00222 if (m_hImpl) 00223 (void) store_acquireHandle (m_hImpl); 00224 } 00225 00228 inline OStoreDirectory & operator= (OStoreDirectory const & rhs) SAL_THROW(()) 00229 { 00230 if (rhs.m_hImpl) 00231 (void) store_acquireHandle (rhs.m_hImpl); 00232 if (m_hImpl) 00233 (void) store_releaseHandle (m_hImpl); 00234 m_hImpl = rhs.m_hImpl; 00235 return *this; 00236 } 00237 00240 inline explicit OStoreDirectory (storeDirectoryHandle Handle) SAL_THROW(()) 00241 : m_hImpl (Handle) 00242 { 00243 if (m_hImpl) 00244 (void) store_acquireHandle (m_hImpl); 00245 } 00246 00249 inline operator storeDirectoryHandle(void) const SAL_THROW(()) 00250 { 00251 return m_hImpl; 00252 } 00253 00257 inline bool isValid (void) const SAL_THROW(()) 00258 { 00259 return (m_hImpl != 0); 00260 } 00261 00265 inline storeError create ( 00266 storeFileHandle hFile, 00267 rtl::OUString const & rPath, 00268 rtl::OUString const & rName, 00269 storeAccessMode eMode) SAL_THROW(()) 00270 { 00271 if (m_hImpl) 00272 { 00273 (void) store_releaseHandle (m_hImpl); 00274 m_hImpl = 0; 00275 } 00276 return store_openDirectory (hFile, rPath.pData, rName.pData, eMode, &m_hImpl); 00277 } 00278 00282 inline void close (void) SAL_THROW(()) 00283 { 00284 if (m_hImpl) 00285 { 00286 (void) store_closeDirectory (m_hImpl); 00287 m_hImpl = 0; 00288 } 00289 } 00290 00295 typedef storeFindData iterator; 00296 00300 inline storeError first (iterator& it) SAL_THROW(()) 00301 { 00302 if (!m_hImpl) 00303 return store_E_InvalidHandle; 00304 00305 return store_findFirst (m_hImpl, &it); 00306 } 00307 00311 inline storeError next (iterator& it) SAL_THROW(()) 00312 { 00313 if (!m_hImpl) 00314 return store_E_InvalidHandle; 00315 00316 return store_findNext (m_hImpl, &it); 00317 } 00318 00322 class traveller 00323 { 00324 public: 00329 virtual sal_Bool visit (const iterator& it) = 0; 00330 00331 protected: 00332 ~traveller() {} 00333 }; 00334 00342 inline storeError travel (traveller & rTraveller) const 00343 { 00344 storeError eErrCode = store_E_InvalidHandle; 00345 if (m_hImpl) 00346 { 00347 iterator it; 00348 eErrCode = store_findFirst (m_hImpl, &it); 00349 while ((eErrCode == store_E_None) && rTraveller.visit(it)) 00350 eErrCode = store_findNext (m_hImpl, &it); 00351 } 00352 return eErrCode; 00353 } 00354 00355 private: 00358 storeDirectoryHandle m_hImpl; 00359 }; 00360 00361 /*======================================================================== 00362 * 00363 * OStoreFile interface. 00364 * 00365 *======================================================================*/ 00366 class OStoreFile 00367 { 00368 public: 00371 inline OStoreFile (void) SAL_THROW(()) 00372 : m_hImpl (0) 00373 {} 00374 00377 inline ~OStoreFile (void) SAL_THROW(()) 00378 { 00379 if (m_hImpl) 00380 (void) store_releaseHandle (m_hImpl); 00381 } 00382 00385 inline OStoreFile (OStoreFile const & rhs) SAL_THROW(()) 00386 : m_hImpl (rhs.m_hImpl) 00387 { 00388 if (m_hImpl) 00389 (void) store_acquireHandle (m_hImpl); 00390 } 00391 00394 inline OStoreFile & operator= (OStoreFile const & rhs) SAL_THROW(()) 00395 { 00396 if (rhs.m_hImpl) 00397 (void) store_acquireHandle (rhs.m_hImpl); 00398 if (m_hImpl) 00399 (void) store_releaseHandle (m_hImpl); 00400 m_hImpl = rhs.m_hImpl; 00401 return *this; 00402 } 00403 00406 inline explicit OStoreFile (storeFileHandle Handle) SAL_THROW(()) 00407 : m_hImpl (Handle) 00408 { 00409 if (m_hImpl) 00410 (void) store_acquireHandle (m_hImpl); 00411 } 00412 00415 inline operator storeFileHandle (void) const SAL_THROW(()) 00416 { 00417 return m_hImpl; 00418 } 00419 00423 inline bool isValid (void) const SAL_THROW(()) 00424 { 00425 return (m_hImpl != 0); 00426 } 00427 00431 inline storeError create ( 00432 rtl::OUString const & rFilename, 00433 storeAccessMode eAccessMode, 00434 sal_uInt16 nPageSize = STORE_DEFAULT_PAGESIZE) SAL_THROW(()) 00435 { 00436 if (m_hImpl) 00437 { 00438 (void) store_releaseHandle (m_hImpl); 00439 m_hImpl = 0; 00440 } 00441 return store_openFile (rFilename.pData, eAccessMode, nPageSize, &m_hImpl); 00442 } 00443 00447 inline storeError createInMemory ( 00448 sal_uInt16 nPageSize = STORE_DEFAULT_PAGESIZE) SAL_THROW(()) 00449 { 00450 if (m_hImpl) 00451 { 00452 (void) store_releaseHandle (m_hImpl); 00453 m_hImpl = 0; 00454 } 00455 return store_createMemoryFile (nPageSize, &m_hImpl); 00456 } 00457 00461 inline void close (void) SAL_THROW(()) 00462 { 00463 if (m_hImpl) 00464 { 00465 (void) store_closeFile (m_hImpl); 00466 m_hImpl = 0; 00467 } 00468 } 00469 00473 inline storeError flush (void) const SAL_THROW(()) 00474 { 00475 if (!m_hImpl) 00476 return store_E_InvalidHandle; 00477 00478 return store_flushFile (m_hImpl); 00479 } 00480 00484 inline storeError getRefererCount (sal_uInt32 & rnRefCount) const SAL_THROW(()) 00485 { 00486 if (!m_hImpl) 00487 return store_E_InvalidHandle; 00488 00489 return store_getFileRefererCount (m_hImpl, &rnRefCount); 00490 } 00491 00495 inline storeError getSize (sal_uInt32 & rnSize) const SAL_THROW(()) 00496 { 00497 if (!m_hImpl) 00498 return store_E_InvalidHandle; 00499 00500 return store_getFileSize (m_hImpl, &rnSize); 00501 } 00502 00506 inline storeError attrib ( 00507 rtl::OUString const & rPath, 00508 rtl::OUString const & rName, 00509 sal_uInt32 nMask1, 00510 sal_uInt32 nMask2, 00511 sal_uInt32 & rnAttrib) SAL_THROW(()) 00512 { 00513 if (!m_hImpl) 00514 return store_E_InvalidHandle; 00515 00516 return store_attrib (m_hImpl, rPath.pData, rName.pData, nMask1, nMask2, &rnAttrib); 00517 } 00518 00522 inline storeError attrib ( 00523 rtl::OUString const & rPath, 00524 rtl::OUString const & rName, 00525 sal_uInt32 nMask1, 00526 sal_uInt32 nMask2) SAL_THROW(()) 00527 { 00528 if (!m_hImpl) 00529 return store_E_InvalidHandle; 00530 00531 return store_attrib (m_hImpl, rPath.pData, rName.pData, nMask1, nMask2, NULL); 00532 } 00533 00537 inline storeError link ( 00538 rtl::OUString const & rSrcPath, rtl::OUString const & rSrcName, 00539 rtl::OUString const & rDstPath, rtl::OUString const & rDstName) SAL_THROW(()) 00540 { 00541 if (!m_hImpl) 00542 return store_E_InvalidHandle; 00543 00544 return store_link ( 00545 m_hImpl, rSrcPath.pData, rSrcName.pData, rDstPath.pData, rDstName.pData); 00546 } 00547 00551 inline storeError symlink ( 00552 rtl::OUString const & rSrcPath, rtl::OUString const & rSrcName, 00553 rtl::OUString const & rDstPath, rtl::OUString const & rDstName) SAL_THROW(()) 00554 { 00555 if (!m_hImpl) 00556 return store_E_InvalidHandle; 00557 00558 return store_symlink (m_hImpl, rSrcPath.pData, rSrcName.pData, rDstPath.pData, rDstName.pData); 00559 } 00560 00564 inline storeError rename ( 00565 rtl::OUString const & rSrcPath, rtl::OUString const & rSrcName, 00566 rtl::OUString const & rDstPath, rtl::OUString const & rDstName) SAL_THROW(()) 00567 { 00568 if (!m_hImpl) 00569 return store_E_InvalidHandle; 00570 00571 return store_rename (m_hImpl, rSrcPath.pData, rSrcName.pData, rDstPath.pData, rDstName.pData); 00572 } 00573 00577 inline storeError remove ( 00578 rtl::OUString const & rPath, rtl::OUString const & rName) SAL_THROW(()) 00579 { 00580 if (!m_hImpl) 00581 return store_E_InvalidHandle; 00582 00583 return store_remove (m_hImpl, rPath.pData, rName.pData); 00584 } 00585 00586 private: 00589 storeFileHandle m_hImpl; 00590 }; 00591 00592 /*======================================================================== 00593 * 00594 * The End. 00595 * 00596 *======================================================================*/ 00597 00598 } // namespace store 00599 00600 #endif /* !_STORE_STORE_HXX_ */ 00601 00602 00603 00604 00605 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
1.7.3