1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _STORE_STORE_HXX_ 25 #define _STORE_STORE_HXX_ 26 27 #include "sal/types.h" 28 #include "rtl/ustring.hxx" 29 #include "store/store.h" 30 31 namespace store 32 { 33 34 /*======================================================================== 35 * 36 * OStoreStream interface. 37 * 38 *======================================================================*/ 39 class OStoreStream 40 { 41 public: 42 /** Construction. 43 */ 44 inline OStoreStream (void) SAL_THROW(()) 45 : m_hImpl (0) 46 {} 47 48 /** Destruction. 49 */ 50 inline ~OStoreStream (void) SAL_THROW(()) 51 { 52 if (m_hImpl) 53 (void) store_releaseHandle (m_hImpl); 54 } 55 56 /** Copy construction. 57 */ 58 inline OStoreStream (OStoreStream const & rhs) SAL_THROW(()) 59 : m_hImpl (rhs.m_hImpl) 60 { 61 if (m_hImpl) 62 (void) store_acquireHandle (m_hImpl); 63 } 64 65 /** Assignment. 66 */ operator =(OStoreStream const & rhs)67 inline OStoreStream & operator= (OStoreStream const & rhs) SAL_THROW(()) 68 { 69 if (rhs.m_hImpl) 70 (void) store_acquireHandle (rhs.m_hImpl); 71 if (m_hImpl) 72 (void) store_releaseHandle (m_hImpl); 73 m_hImpl = rhs.m_hImpl; 74 return *this; 75 } 76 77 /** Construction from Stream Handle. 78 */ 79 inline explicit OStoreStream (storeStreamHandle Handle) SAL_THROW(()) 80 : m_hImpl (Handle) 81 { 82 if (m_hImpl) 83 (void) store_acquireHandle (m_hImpl); 84 } 85 86 /** Conversion into Stream Handle. 87 */ operator storeStreamHandle(void) const88 inline operator storeStreamHandle (void) const SAL_THROW(()) 89 { 90 return m_hImpl; 91 } 92 93 /** Check for a valid Stream Handle. 94 @return sal_True if valid, sal_False otherwise. 95 */ isValid(void) const96 inline bool isValid (void) const SAL_THROW(()) 97 { 98 return (m_hImpl != 0); 99 } 100 101 /** Open the stream. 102 @see store_openStream() 103 */ create(storeFileHandle hFile,rtl::OUString const & rPath,rtl::OUString const & rName,storeAccessMode eMode)104 inline storeError create ( 105 storeFileHandle hFile, 106 rtl::OUString const & rPath, 107 rtl::OUString const & rName, 108 storeAccessMode eMode) SAL_THROW(()) 109 { 110 if (m_hImpl) 111 { 112 (void) store_releaseHandle (m_hImpl); 113 m_hImpl = 0; 114 } 115 return store_openStream (hFile, rPath.pData, rName.pData, eMode, &m_hImpl); 116 } 117 118 /** Close the stream. 119 @see store_closeStream() 120 */ close(void)121 inline void close (void) SAL_THROW(()) 122 { 123 if (m_hImpl) 124 { 125 (void) store_closeStream (m_hImpl); 126 m_hImpl = 0; 127 } 128 } 129 130 /** Read from the stream. 131 @see store_readStream() 132 */ readAt(sal_uInt32 nOffset,void * pBuffer,sal_uInt32 nBytes,sal_uInt32 & rnDone)133 inline storeError readAt ( 134 sal_uInt32 nOffset, 135 void * pBuffer, 136 sal_uInt32 nBytes, 137 sal_uInt32 & rnDone) SAL_THROW(()) 138 { 139 if (!m_hImpl) 140 return store_E_InvalidHandle; 141 142 return store_readStream (m_hImpl, nOffset, pBuffer, nBytes, &rnDone); 143 } 144 145 /** Write to the stream. 146 @see store_writeStream() 147 */ writeAt(sal_uInt32 nOffset,void const * pBuffer,sal_uInt32 nBytes,sal_uInt32 & rnDone)148 inline storeError writeAt ( 149 sal_uInt32 nOffset, 150 void const * pBuffer, 151 sal_uInt32 nBytes, 152 sal_uInt32 & rnDone) SAL_THROW(()) 153 { 154 if (!m_hImpl) 155 return store_E_InvalidHandle; 156 157 return store_writeStream (m_hImpl, nOffset, pBuffer, nBytes, &rnDone); 158 } 159 160 /** Flush the stream. 161 @see store_flushStream() 162 */ flush(void) const163 inline storeError flush (void) const SAL_THROW(()) 164 { 165 if (!m_hImpl) 166 return store_E_InvalidHandle; 167 168 return store_flushStream (m_hImpl); 169 } 170 171 /** Get the stream size. 172 @see store_getStreamSize() 173 */ getSize(sal_uInt32 & rnSize) const174 inline storeError getSize (sal_uInt32 & rnSize) const SAL_THROW(()) 175 { 176 if (!m_hImpl) 177 return store_E_InvalidHandle; 178 179 return store_getStreamSize (m_hImpl, &rnSize); 180 } 181 182 /** Set the stream size. 183 @see store_setStreamSize() 184 */ setSize(sal_uInt32 nSize)185 inline storeError setSize (sal_uInt32 nSize) SAL_THROW(()) 186 { 187 if (!m_hImpl) 188 return store_E_InvalidHandle; 189 190 return store_setStreamSize (m_hImpl, nSize); 191 } 192 193 private: 194 /** Representation. 195 */ 196 storeStreamHandle m_hImpl; 197 }; 198 199 /*======================================================================== 200 * 201 * OStoreDirectory interface. 202 * 203 *======================================================================*/ 204 class OStoreDirectory 205 { 206 public: 207 /** Construction. 208 */ 209 inline OStoreDirectory (void) SAL_THROW(()) 210 : m_hImpl (0) 211 {} 212 213 /** Destruction. 214 */ 215 inline ~OStoreDirectory (void) SAL_THROW(()) 216 { 217 if (m_hImpl) 218 (void) store_releaseHandle (m_hImpl); 219 } 220 221 /** Copy construction. 222 */ 223 inline OStoreDirectory (OStoreDirectory const & rhs) SAL_THROW(()) 224 : m_hImpl (rhs.m_hImpl) 225 { 226 if (m_hImpl) 227 (void) store_acquireHandle (m_hImpl); 228 } 229 230 /** Assignment. 231 */ operator =(OStoreDirectory const & rhs)232 inline OStoreDirectory & operator= (OStoreDirectory const & rhs) SAL_THROW(()) 233 { 234 if (rhs.m_hImpl) 235 (void) store_acquireHandle (rhs.m_hImpl); 236 if (m_hImpl) 237 (void) store_releaseHandle (m_hImpl); 238 m_hImpl = rhs.m_hImpl; 239 return *this; 240 } 241 242 /** Construction from Directory Handle. 243 */ 244 inline explicit OStoreDirectory (storeDirectoryHandle Handle) SAL_THROW(()) 245 : m_hImpl (Handle) 246 { 247 if (m_hImpl) 248 (void) store_acquireHandle (m_hImpl); 249 } 250 251 /** Conversion into Directory Handle. 252 */ operator storeDirectoryHandle(void) const253 inline operator storeDirectoryHandle(void) const SAL_THROW(()) 254 { 255 return m_hImpl; 256 } 257 258 /** Check for a valid Directory Handle. 259 @return sal_True if valid, sal_False otherwise. 260 */ isValid(void) const261 inline bool isValid (void) const SAL_THROW(()) 262 { 263 return (m_hImpl != 0); 264 } 265 266 /** Open the directory. 267 @see store_openDirectory() 268 */ create(storeFileHandle hFile,rtl::OUString const & rPath,rtl::OUString const & rName,storeAccessMode eMode)269 inline storeError create ( 270 storeFileHandle hFile, 271 rtl::OUString const & rPath, 272 rtl::OUString const & rName, 273 storeAccessMode eMode) SAL_THROW(()) 274 { 275 if (m_hImpl) 276 { 277 (void) store_releaseHandle (m_hImpl); 278 m_hImpl = 0; 279 } 280 return store_openDirectory (hFile, rPath.pData, rName.pData, eMode, &m_hImpl); 281 } 282 283 /** Close the directory. 284 @see store_closeDirectory() 285 */ close(void)286 inline void close (void) SAL_THROW(()) 287 { 288 if (m_hImpl) 289 { 290 (void) store_closeDirectory (m_hImpl); 291 m_hImpl = 0; 292 } 293 } 294 295 /** Directory iterator type. 296 @see first() 297 @see next() 298 */ 299 typedef storeFindData iterator; 300 301 /** Find first directory entry. 302 @see store_findFirst() 303 */ first(iterator & it)304 inline storeError first (iterator& it) SAL_THROW(()) 305 { 306 if (!m_hImpl) 307 return store_E_InvalidHandle; 308 309 return store_findFirst (m_hImpl, &it); 310 } 311 312 /** Find next directory entry. 313 @see store_findNext() 314 */ next(iterator & it)315 inline storeError next (iterator& it) SAL_THROW(()) 316 { 317 if (!m_hImpl) 318 return store_E_InvalidHandle; 319 320 return store_findNext (m_hImpl, &it); 321 } 322 323 /** Directory traversal helper. 324 @see travel() 325 */ 326 class traveller 327 { 328 public: 329 /** Directory traversal callback. 330 @param it [in] current directory entry. 331 @return sal_True to continue iteration, sal_False to stop. 332 */ 333 virtual sal_Bool visit (const iterator& it) = 0; 334 }; 335 336 /** Directory traversal. 337 @see store_findFirst() 338 @see store_findNext() 339 340 @param rTraveller [in] the traversal callback. 341 @return store_E_NoMoreFiles upon end of iteration. 342 */ travel(traveller & rTraveller) const343 inline storeError travel (traveller & rTraveller) const 344 { 345 storeError eErrCode = store_E_InvalidHandle; 346 if (m_hImpl) 347 { 348 iterator it; 349 eErrCode = store_findFirst (m_hImpl, &it); 350 while ((eErrCode == store_E_None) && rTraveller.visit(it)) 351 eErrCode = store_findNext (m_hImpl, &it); 352 } 353 return eErrCode; 354 } 355 356 private: 357 /** Representation. 358 */ 359 storeDirectoryHandle m_hImpl; 360 }; 361 362 /*======================================================================== 363 * 364 * OStoreFile interface. 365 * 366 *======================================================================*/ 367 class OStoreFile 368 { 369 public: 370 /** Construction. 371 */ 372 inline OStoreFile (void) SAL_THROW(()) 373 : m_hImpl (0) 374 {} 375 376 /** Destruction. 377 */ 378 inline ~OStoreFile (void) SAL_THROW(()) 379 { 380 if (m_hImpl) 381 (void) store_releaseHandle (m_hImpl); 382 } 383 384 /** Copy construction. 385 */ 386 inline OStoreFile (OStoreFile const & rhs) SAL_THROW(()) 387 : m_hImpl (rhs.m_hImpl) 388 { 389 if (m_hImpl) 390 (void) store_acquireHandle (m_hImpl); 391 } 392 393 /** Assignment. 394 */ operator =(OStoreFile const & rhs)395 inline OStoreFile & operator= (OStoreFile const & rhs) SAL_THROW(()) 396 { 397 if (rhs.m_hImpl) 398 (void) store_acquireHandle (rhs.m_hImpl); 399 if (m_hImpl) 400 (void) store_releaseHandle (m_hImpl); 401 m_hImpl = rhs.m_hImpl; 402 return *this; 403 } 404 405 /** Construction from File Handle. 406 */ 407 inline explicit OStoreFile (storeFileHandle Handle) SAL_THROW(()) 408 : m_hImpl (Handle) 409 { 410 if (m_hImpl) 411 (void) store_acquireHandle (m_hImpl); 412 } 413 414 /** Conversion into File Handle. 415 */ operator storeFileHandle(void) const416 inline operator storeFileHandle (void) const SAL_THROW(()) 417 { 418 return m_hImpl; 419 } 420 421 /** Check for a valid File Handle. 422 @return sal_True if valid, sal_False otherwise. 423 */ isValid(void) const424 inline bool isValid (void) const SAL_THROW(()) 425 { 426 return (m_hImpl != 0); 427 } 428 429 /** Open the file. 430 @see store_openFile() 431 */ create(rtl::OUString const & rFilename,storeAccessMode eAccessMode,sal_uInt16 nPageSize=STORE_DEFAULT_PAGESIZE)432 inline storeError create ( 433 rtl::OUString const & rFilename, 434 storeAccessMode eAccessMode, 435 sal_uInt16 nPageSize = STORE_DEFAULT_PAGESIZE) SAL_THROW(()) 436 { 437 if (m_hImpl) 438 { 439 (void) store_releaseHandle (m_hImpl); 440 m_hImpl = 0; 441 } 442 return store_openFile (rFilename.pData, eAccessMode, nPageSize, &m_hImpl); 443 } 444 445 /** Open the temporary file in memory. 446 @see store_createMemoryFile() 447 */ createInMemory(sal_uInt16 nPageSize=STORE_DEFAULT_PAGESIZE)448 inline storeError createInMemory ( 449 sal_uInt16 nPageSize = STORE_DEFAULT_PAGESIZE) SAL_THROW(()) 450 { 451 if (m_hImpl) 452 { 453 (void) store_releaseHandle (m_hImpl); 454 m_hImpl = 0; 455 } 456 return store_createMemoryFile (nPageSize, &m_hImpl); 457 } 458 459 /** Close the file. 460 @see store_closeFile() 461 */ close(void)462 inline void close (void) SAL_THROW(()) 463 { 464 if (m_hImpl) 465 { 466 (void) store_closeFile (m_hImpl); 467 m_hImpl = 0; 468 } 469 } 470 471 /** Flush the file. 472 @see store_flushFile() 473 */ flush(void) const474 inline storeError flush (void) const SAL_THROW(()) 475 { 476 if (!m_hImpl) 477 return store_E_InvalidHandle; 478 479 return store_flushFile (m_hImpl); 480 } 481 482 /** Get the number of referers to the file. 483 @see store_getFileRefererCount() 484 */ getRefererCount(sal_uInt32 & rnRefCount) const485 inline storeError getRefererCount (sal_uInt32 & rnRefCount) const SAL_THROW(()) 486 { 487 if (!m_hImpl) 488 return store_E_InvalidHandle; 489 490 return store_getFileRefererCount (m_hImpl, &rnRefCount); 491 } 492 493 /** Get the file size. 494 @see store_getFileSize() 495 */ getSize(sal_uInt32 & rnSize) const496 inline storeError getSize (sal_uInt32 & rnSize) const SAL_THROW(()) 497 { 498 if (!m_hImpl) 499 return store_E_InvalidHandle; 500 501 return store_getFileSize (m_hImpl, &rnSize); 502 } 503 504 /** Set attributes of a file entry. 505 @see store_attrib() 506 */ attrib(rtl::OUString const & rPath,rtl::OUString const & rName,sal_uInt32 nMask1,sal_uInt32 nMask2,sal_uInt32 & rnAttrib)507 inline storeError attrib ( 508 rtl::OUString const & rPath, 509 rtl::OUString const & rName, 510 sal_uInt32 nMask1, 511 sal_uInt32 nMask2, 512 sal_uInt32 & rnAttrib) SAL_THROW(()) 513 { 514 if (!m_hImpl) 515 return store_E_InvalidHandle; 516 517 return store_attrib (m_hImpl, rPath.pData, rName.pData, nMask1, nMask2, &rnAttrib); 518 } 519 520 /** Set attributes of a file entry. 521 @see store_attrib() 522 */ attrib(rtl::OUString const & rPath,rtl::OUString const & rName,sal_uInt32 nMask1,sal_uInt32 nMask2)523 inline storeError attrib ( 524 rtl::OUString const & rPath, 525 rtl::OUString const & rName, 526 sal_uInt32 nMask1, 527 sal_uInt32 nMask2) SAL_THROW(()) 528 { 529 if (!m_hImpl) 530 return store_E_InvalidHandle; 531 532 return store_attrib (m_hImpl, rPath.pData, rName.pData, nMask1, nMask2, NULL); 533 } 534 535 /** Insert a file entry as 'hard link' to another file entry. 536 @see store_link() 537 */ link(rtl::OUString const & rSrcPath,rtl::OUString const & rSrcName,rtl::OUString const & rDstPath,rtl::OUString const & rDstName)538 inline storeError link ( 539 rtl::OUString const & rSrcPath, rtl::OUString const & rSrcName, 540 rtl::OUString const & rDstPath, rtl::OUString const & rDstName) SAL_THROW(()) 541 { 542 if (!m_hImpl) 543 return store_E_InvalidHandle; 544 545 return store_link ( 546 m_hImpl, rSrcPath.pData, rSrcName.pData, rDstPath.pData, rDstName.pData); 547 } 548 549 /** Insert a file entry as 'symbolic link' to another file entry. 550 @see store_symlink() 551 */ symlink(rtl::OUString const & rSrcPath,rtl::OUString const & rSrcName,rtl::OUString const & rDstPath,rtl::OUString const & rDstName)552 inline storeError symlink ( 553 rtl::OUString const & rSrcPath, rtl::OUString const & rSrcName, 554 rtl::OUString const & rDstPath, rtl::OUString const & rDstName) SAL_THROW(()) 555 { 556 if (!m_hImpl) 557 return store_E_InvalidHandle; 558 559 return store_symlink (m_hImpl, rSrcPath.pData, rSrcName.pData, rDstPath.pData, rDstName.pData); 560 } 561 562 /** Rename a file entry. 563 @see store_rename() 564 */ rename(rtl::OUString const & rSrcPath,rtl::OUString const & rSrcName,rtl::OUString const & rDstPath,rtl::OUString const & rDstName)565 inline storeError rename ( 566 rtl::OUString const & rSrcPath, rtl::OUString const & rSrcName, 567 rtl::OUString const & rDstPath, rtl::OUString const & rDstName) SAL_THROW(()) 568 { 569 if (!m_hImpl) 570 return store_E_InvalidHandle; 571 572 return store_rename (m_hImpl, rSrcPath.pData, rSrcName.pData, rDstPath.pData, rDstName.pData); 573 } 574 575 /** Remove a file entry. 576 @see store_remove() 577 */ remove(rtl::OUString const & rPath,rtl::OUString const & rName)578 inline storeError remove ( 579 rtl::OUString const & rPath, rtl::OUString const & rName) SAL_THROW(()) 580 { 581 if (!m_hImpl) 582 return store_E_InvalidHandle; 583 584 return store_remove (m_hImpl, rPath.pData, rName.pData); 585 } 586 587 private: 588 /** Representation. 589 */ 590 storeFileHandle m_hImpl; 591 }; 592 593 /*======================================================================== 594 * 595 * The End. 596 * 597 *======================================================================*/ 598 599 } // namespace store 600 601 #endif /* !_STORE_STORE_HXX_ */ 602 603 604 605 606