My Project
UDK 3.2.7 C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
store.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 _STORE_STORE_HXX_
21 #define _STORE_STORE_HXX_
22 
23 #include "sal/types.h"
24 #include "rtl/ustring.hxx"
25 #include "store/store.h"
26 
27 namespace store
28 {
29 
30 /*========================================================================
31  *
32  * OStoreStream interface.
33  *
34  *======================================================================*/
36 {
37 public:
40  inline OStoreStream (void) SAL_THROW(())
41  : m_hImpl (0)
42  {}
43 
46  inline ~OStoreStream (void) SAL_THROW(())
47  {
48  if (m_hImpl)
49  (void) store_releaseHandle (m_hImpl);
50  }
51 
54  inline OStoreStream (OStoreStream const & rhs) SAL_THROW(())
55  : m_hImpl (rhs.m_hImpl)
56  {
57  if (m_hImpl)
58  (void) store_acquireHandle (m_hImpl);
59  }
60 
63  inline OStoreStream & operator= (OStoreStream const & rhs) SAL_THROW(())
64  {
65  if (rhs.m_hImpl)
66  (void) store_acquireHandle (rhs.m_hImpl);
67  if (m_hImpl)
68  (void) store_releaseHandle (m_hImpl);
69  m_hImpl = rhs.m_hImpl;
70  return *this;
71  }
72 
75  inline explicit OStoreStream (storeStreamHandle Handle) SAL_THROW(())
76  : m_hImpl (Handle)
77  {
78  if (m_hImpl)
79  (void) store_acquireHandle (m_hImpl);
80  }
81 
84  inline operator storeStreamHandle (void) const SAL_THROW(())
85  {
86  return m_hImpl;
87  }
88 
92  inline bool isValid (void) const SAL_THROW(())
93  {
94  return (m_hImpl != 0);
95  }
96 
101  storeFileHandle hFile,
102  rtl::OUString const & rPath,
103  rtl::OUString const & rName,
104  storeAccessMode eMode) SAL_THROW(())
105  {
106  if (m_hImpl)
107  {
108  (void) store_releaseHandle (m_hImpl);
109  m_hImpl = 0;
110  }
111  return store_openStream (hFile, rPath.pData, rName.pData, eMode, &m_hImpl);
112  }
113 
117  inline void close (void) SAL_THROW(())
118  {
119  if (m_hImpl)
120  {
121  (void) store_closeStream (m_hImpl);
122  m_hImpl = 0;
123  }
124  }
125 
130  sal_uInt32 nOffset,
131  void * pBuffer,
132  sal_uInt32 nBytes,
133  sal_uInt32 & rnDone) SAL_THROW(())
134  {
135  if (!m_hImpl)
136  return store_E_InvalidHandle;
137 
138  return store_readStream (m_hImpl, nOffset, pBuffer, nBytes, &rnDone);
139  }
140 
145  sal_uInt32 nOffset,
146  void const * pBuffer,
147  sal_uInt32 nBytes,
148  sal_uInt32 & rnDone) SAL_THROW(())
149  {
150  if (!m_hImpl)
151  return store_E_InvalidHandle;
152 
153  return store_writeStream (m_hImpl, nOffset, pBuffer, nBytes, &rnDone);
154  }
155 
159  inline storeError flush (void) const SAL_THROW(())
160  {
161  if (!m_hImpl)
162  return store_E_InvalidHandle;
163 
164  return store_flushStream (m_hImpl);
165  }
166 
170  inline storeError getSize (sal_uInt32 & rnSize) const SAL_THROW(())
171  {
172  if (!m_hImpl)
173  return store_E_InvalidHandle;
174 
175  return store_getStreamSize (m_hImpl, &rnSize);
176  }
177 
181  inline storeError setSize (sal_uInt32 nSize) SAL_THROW(())
182  {
183  if (!m_hImpl)
184  return store_E_InvalidHandle;
185 
186  return store_setStreamSize (m_hImpl, nSize);
187  }
188 
189 private:
192  storeStreamHandle m_hImpl;
193 };
194 
195 /*========================================================================
196  *
197  * OStoreDirectory interface.
198  *
199  *======================================================================*/
201 {
202 public:
205  inline OStoreDirectory (void) SAL_THROW(())
206  : m_hImpl (0)
207  {}
208 
211  inline ~OStoreDirectory (void) SAL_THROW(())
212  {
213  if (m_hImpl)
214  (void) store_releaseHandle (m_hImpl);
215  }
216 
219  inline OStoreDirectory (OStoreDirectory const & rhs) SAL_THROW(())
220  : m_hImpl (rhs.m_hImpl)
221  {
222  if (m_hImpl)
223  (void) store_acquireHandle (m_hImpl);
224  }
225 
229  {
230  if (rhs.m_hImpl)
231  (void) store_acquireHandle (rhs.m_hImpl);
232  if (m_hImpl)
233  (void) store_releaseHandle (m_hImpl);
234  m_hImpl = rhs.m_hImpl;
235  return *this;
236  }
237 
240  inline explicit OStoreDirectory (storeDirectoryHandle Handle) SAL_THROW(())
241  : m_hImpl (Handle)
242  {
243  if (m_hImpl)
244  (void) store_acquireHandle (m_hImpl);
245  }
246 
249  inline operator storeDirectoryHandle(void) const SAL_THROW(())
250  {
251  return m_hImpl;
252  }
253 
257  inline bool isValid (void) const SAL_THROW(())
258  {
259  return (m_hImpl != 0);
260  }
261 
266  storeFileHandle hFile,
267  rtl::OUString const & rPath,
268  rtl::OUString const & rName,
269  storeAccessMode eMode) SAL_THROW(())
270  {
271  if (m_hImpl)
272  {
273  (void) store_releaseHandle (m_hImpl);
274  m_hImpl = 0;
275  }
276  return store_openDirectory (hFile, rPath.pData, rName.pData, eMode, &m_hImpl);
277  }
278 
282  inline void close (void) SAL_THROW(())
283  {
284  if (m_hImpl)
285  {
286  (void) store_closeDirectory (m_hImpl);
287  m_hImpl = 0;
288  }
289  }
290 
296 
301  {
302  if (!m_hImpl)
303  return store_E_InvalidHandle;
304 
305  return store_findFirst (m_hImpl, &it);
306  }
307 
312  {
313  if (!m_hImpl)
314  return store_E_InvalidHandle;
315 
316  return store_findNext (m_hImpl, &it);
317  }
318 
322  class traveller
323  {
324  public:
329  virtual sal_Bool visit (const iterator& it) = 0;
330 
331  protected:
333  };
334 
342  inline storeError travel (traveller & rTraveller) const
343  {
345  if (m_hImpl)
346  {
347  iterator it;
348  eErrCode = store_findFirst (m_hImpl, &it);
349  while ((eErrCode == store_E_None) && rTraveller.visit(it))
350  eErrCode = store_findNext (m_hImpl, &it);
351  }
352  return eErrCode;
353  }
354 
355 private:
358  storeDirectoryHandle m_hImpl;
359 };
360 
361 /*========================================================================
362  *
363  * OStoreFile interface.
364  *
365  *======================================================================*/
367 {
368 public:
371  inline OStoreFile (void) SAL_THROW(())
372  : m_hImpl (0)
373  {}
374 
377  inline ~OStoreFile (void) SAL_THROW(())
378  {
379  if (m_hImpl)
380  (void) store_releaseHandle (m_hImpl);
381  }
382 
385  inline OStoreFile (OStoreFile const & rhs) SAL_THROW(())
386  : m_hImpl (rhs.m_hImpl)
387  {
388  if (m_hImpl)
389  (void) store_acquireHandle (m_hImpl);
390  }
391 
394  inline OStoreFile & operator= (OStoreFile const & rhs) SAL_THROW(())
395  {
396  if (rhs.m_hImpl)
397  (void) store_acquireHandle (rhs.m_hImpl);
398  if (m_hImpl)
399  (void) store_releaseHandle (m_hImpl);
400  m_hImpl = rhs.m_hImpl;
401  return *this;
402  }
403 
406  inline explicit OStoreFile (storeFileHandle Handle) SAL_THROW(())
407  : m_hImpl (Handle)
408  {
409  if (m_hImpl)
410  (void) store_acquireHandle (m_hImpl);
411  }
412 
415  inline operator storeFileHandle (void) const SAL_THROW(())
416  {
417  return m_hImpl;
418  }
419 
423  inline bool isValid (void) const SAL_THROW(())
424  {
425  return (m_hImpl != 0);
426  }
427 
432  rtl::OUString const & rFilename,
433  storeAccessMode eAccessMode,
434  sal_uInt16 nPageSize = STORE_DEFAULT_PAGESIZE) SAL_THROW(())
435  {
436  if (m_hImpl)
437  {
438  (void) store_releaseHandle (m_hImpl);
439  m_hImpl = 0;
440  }
441  return store_openFile (rFilename.pData, eAccessMode, nPageSize, &m_hImpl);
442  }
443 
448  sal_uInt16 nPageSize = STORE_DEFAULT_PAGESIZE) SAL_THROW(())
449  {
450  if (m_hImpl)
451  {
452  (void) store_releaseHandle (m_hImpl);
453  m_hImpl = 0;
454  }
455  return store_createMemoryFile (nPageSize, &m_hImpl);
456  }
457 
461  inline void close (void) SAL_THROW(())
462  {
463  if (m_hImpl)
464  {
465  (void) store_closeFile (m_hImpl);
466  m_hImpl = 0;
467  }
468  }
469 
473  inline storeError flush (void) const SAL_THROW(())
474  {
475  if (!m_hImpl)
476  return store_E_InvalidHandle;
477 
478  return store_flushFile (m_hImpl);
479  }
480 
484  inline storeError getRefererCount (sal_uInt32 & rnRefCount) const SAL_THROW(())
485  {
486  if (!m_hImpl)
487  return store_E_InvalidHandle;
488 
489  return store_getFileRefererCount (m_hImpl, &rnRefCount);
490  }
491 
495  inline storeError getSize (sal_uInt32 & rnSize) const SAL_THROW(())
496  {
497  if (!m_hImpl)
498  return store_E_InvalidHandle;
499 
500  return store_getFileSize (m_hImpl, &rnSize);
501  }
502 
507  rtl::OUString const & rPath,
508  rtl::OUString const & rName,
509  sal_uInt32 nMask1,
510  sal_uInt32 nMask2,
511  sal_uInt32 & rnAttrib) SAL_THROW(())
512  {
513  if (!m_hImpl)
514  return store_E_InvalidHandle;
515 
516  return store_attrib (m_hImpl, rPath.pData, rName.pData, nMask1, nMask2, &rnAttrib);
517  }
518 
523  rtl::OUString const & rPath,
524  rtl::OUString const & rName,
525  sal_uInt32 nMask1,
526  sal_uInt32 nMask2) SAL_THROW(())
527  {
528  if (!m_hImpl)
529  return store_E_InvalidHandle;
530 
531  return store_attrib (m_hImpl, rPath.pData, rName.pData, nMask1, nMask2, NULL);
532  }
533 
537  inline storeError link (
538  rtl::OUString const & rSrcPath, rtl::OUString const & rSrcName,
539  rtl::OUString const & rDstPath, rtl::OUString const & rDstName) SAL_THROW(())
540  {
541  if (!m_hImpl)
542  return store_E_InvalidHandle;
543 
544  return store_link (
545  m_hImpl, rSrcPath.pData, rSrcName.pData, rDstPath.pData, rDstName.pData);
546  }
547 
552  rtl::OUString const & rSrcPath, rtl::OUString const & rSrcName,
553  rtl::OUString const & rDstPath, rtl::OUString const & rDstName) SAL_THROW(())
554  {
555  if (!m_hImpl)
556  return store_E_InvalidHandle;
557 
558  return store_symlink (m_hImpl, rSrcPath.pData, rSrcName.pData, rDstPath.pData, rDstName.pData);
559  }
560 
565  rtl::OUString const & rSrcPath, rtl::OUString const & rSrcName,
566  rtl::OUString const & rDstPath, rtl::OUString const & rDstName) SAL_THROW(())
567  {
568  if (!m_hImpl)
569  return store_E_InvalidHandle;
570 
571  return store_rename (m_hImpl, rSrcPath.pData, rSrcName.pData, rDstPath.pData, rDstName.pData);
572  }
573 
577  inline storeError remove (
578  rtl::OUString const & rPath, rtl::OUString const & rName) SAL_THROW(())
579  {
580  if (!m_hImpl)
581  return store_E_InvalidHandle;
582 
583  return store_remove (m_hImpl, rPath.pData, rName.pData);
584  }
585 
586 private:
589  storeFileHandle m_hImpl;
590 };
591 
592 /*========================================================================
593  *
594  * The End.
595  *
596  *======================================================================*/
597 
598 } // namespace store
599 
600 #endif /* !_STORE_STORE_HXX_ */
601 
602 
603 
604 
605 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */