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  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * Copyright 2000, 2010 Oracle and/or its affiliates.
7  *
8  * OpenOffice.org - a multi-platform office productivity suite
9  *
10  * This file is part of OpenOffice.org.
11  *
12  * OpenOffice.org is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 3
14  * only, as published by the Free Software Foundation.
15  *
16  * OpenOffice.org is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License version 3 for more details
20  * (a copy is included in the LICENSE file that accompanied this code).
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * version 3 along with OpenOffice.org. If not, see
24  * <http://www.openoffice.org/license.html>
25  * for a copy of the LGPLv3 License.
26  *
27  ************************************************************************/
28 
29 #ifndef _STORE_STORE_HXX_
30 #define _STORE_STORE_HXX_
31 
32 #include "sal/types.h"
33 #include "rtl/ustring.hxx"
34 #include "store/store.h"
35 
36 namespace store
37 {
38 
39 /*========================================================================
40  *
41  * OStoreStream interface.
42  *
43  *======================================================================*/
45 {
46 public:
49  inline OStoreStream (void) SAL_THROW(())
50  : m_hImpl (0)
51  {}
52 
55  inline ~OStoreStream (void) SAL_THROW(())
56  {
57  if (m_hImpl)
58  (void) store_releaseHandle (m_hImpl);
59  }
60 
63  inline OStoreStream (OStoreStream const & rhs) SAL_THROW(())
64  : m_hImpl (rhs.m_hImpl)
65  {
66  if (m_hImpl)
67  (void) store_acquireHandle (m_hImpl);
68  }
69 
72  inline OStoreStream & operator= (OStoreStream const & rhs) SAL_THROW(())
73  {
74  if (rhs.m_hImpl)
75  (void) store_acquireHandle (rhs.m_hImpl);
76  if (m_hImpl)
77  (void) store_releaseHandle (m_hImpl);
78  m_hImpl = rhs.m_hImpl;
79  return *this;
80  }
81 
84  inline explicit OStoreStream (storeStreamHandle Handle) SAL_THROW(())
85  : m_hImpl (Handle)
86  {
87  if (m_hImpl)
88  (void) store_acquireHandle (m_hImpl);
89  }
90 
93  inline operator storeStreamHandle (void) const SAL_THROW(())
94  {
95  return m_hImpl;
96  }
97 
101  inline bool isValid (void) const SAL_THROW(())
102  {
103  return (m_hImpl != 0);
104  }
105 
110  storeFileHandle hFile,
111  rtl::OUString const & rPath,
112  rtl::OUString const & rName,
113  storeAccessMode eMode) SAL_THROW(())
114  {
115  if (m_hImpl)
116  {
117  (void) store_releaseHandle (m_hImpl);
118  m_hImpl = 0;
119  }
120  return store_openStream (hFile, rPath.pData, rName.pData, eMode, &m_hImpl);
121  }
122 
126  inline void close (void) SAL_THROW(())
127  {
128  if (m_hImpl)
129  {
130  (void) store_closeStream (m_hImpl);
131  m_hImpl = 0;
132  }
133  }
134 
139  sal_uInt32 nOffset,
140  void * pBuffer,
141  sal_uInt32 nBytes,
142  sal_uInt32 & rnDone) SAL_THROW(())
143  {
144  if (!m_hImpl)
145  return store_E_InvalidHandle;
146 
147  return store_readStream (m_hImpl, nOffset, pBuffer, nBytes, &rnDone);
148  }
149 
154  sal_uInt32 nOffset,
155  void const * pBuffer,
156  sal_uInt32 nBytes,
157  sal_uInt32 & rnDone) SAL_THROW(())
158  {
159  if (!m_hImpl)
160  return store_E_InvalidHandle;
161 
162  return store_writeStream (m_hImpl, nOffset, pBuffer, nBytes, &rnDone);
163  }
164 
168  inline storeError flush (void) const SAL_THROW(())
169  {
170  if (!m_hImpl)
171  return store_E_InvalidHandle;
172 
173  return store_flushStream (m_hImpl);
174  }
175 
179  inline storeError getSize (sal_uInt32 & rnSize) const SAL_THROW(())
180  {
181  if (!m_hImpl)
182  return store_E_InvalidHandle;
183 
184  return store_getStreamSize (m_hImpl, &rnSize);
185  }
186 
190  inline storeError setSize (sal_uInt32 nSize) SAL_THROW(())
191  {
192  if (!m_hImpl)
193  return store_E_InvalidHandle;
194 
195  return store_setStreamSize (m_hImpl, nSize);
196  }
197 
198 private:
201  storeStreamHandle m_hImpl;
202 };
203 
204 /*========================================================================
205  *
206  * OStoreDirectory interface.
207  *
208  *======================================================================*/
210 {
211 public:
214  inline OStoreDirectory (void) SAL_THROW(())
215  : m_hImpl (0)
216  {}
217 
220  inline ~OStoreDirectory (void) SAL_THROW(())
221  {
222  if (m_hImpl)
223  (void) store_releaseHandle (m_hImpl);
224  }
225 
228  inline OStoreDirectory (OStoreDirectory const & rhs) SAL_THROW(())
229  : m_hImpl (rhs.m_hImpl)
230  {
231  if (m_hImpl)
232  (void) store_acquireHandle (m_hImpl);
233  }
234 
238  {
239  if (rhs.m_hImpl)
240  (void) store_acquireHandle (rhs.m_hImpl);
241  if (m_hImpl)
242  (void) store_releaseHandle (m_hImpl);
243  m_hImpl = rhs.m_hImpl;
244  return *this;
245  }
246 
249  inline explicit OStoreDirectory (storeDirectoryHandle Handle) SAL_THROW(())
250  : m_hImpl (Handle)
251  {
252  if (m_hImpl)
253  (void) store_acquireHandle (m_hImpl);
254  }
255 
258  inline operator storeDirectoryHandle(void) const SAL_THROW(())
259  {
260  return m_hImpl;
261  }
262 
266  inline bool isValid (void) const SAL_THROW(())
267  {
268  return (m_hImpl != 0);
269  }
270 
275  storeFileHandle hFile,
276  rtl::OUString const & rPath,
277  rtl::OUString const & rName,
278  storeAccessMode eMode) SAL_THROW(())
279  {
280  if (m_hImpl)
281  {
282  (void) store_releaseHandle (m_hImpl);
283  m_hImpl = 0;
284  }
285  return store_openDirectory (hFile, rPath.pData, rName.pData, eMode, &m_hImpl);
286  }
287 
291  inline void close (void) SAL_THROW(())
292  {
293  if (m_hImpl)
294  {
295  (void) store_closeDirectory (m_hImpl);
296  m_hImpl = 0;
297  }
298  }
299 
305 
310  {
311  if (!m_hImpl)
312  return store_E_InvalidHandle;
313 
314  return store_findFirst (m_hImpl, &it);
315  }
316 
321  {
322  if (!m_hImpl)
323  return store_E_InvalidHandle;
324 
325  return store_findNext (m_hImpl, &it);
326  }
327 
331  class traveller
332  {
333  public:
338  virtual sal_Bool visit (const iterator& it) = 0;
339 
340  protected:
342  };
343 
351  inline storeError travel (traveller & rTraveller) const
352  {
354  if (m_hImpl)
355  {
356  iterator it;
357  eErrCode = store_findFirst (m_hImpl, &it);
358  while ((eErrCode == store_E_None) && rTraveller.visit(it))
359  eErrCode = store_findNext (m_hImpl, &it);
360  }
361  return eErrCode;
362  }
363 
364 private:
367  storeDirectoryHandle m_hImpl;
368 };
369 
370 /*========================================================================
371  *
372  * OStoreFile interface.
373  *
374  *======================================================================*/
376 {
377 public:
380  inline OStoreFile (void) SAL_THROW(())
381  : m_hImpl (0)
382  {}
383 
386  inline ~OStoreFile (void) SAL_THROW(())
387  {
388  if (m_hImpl)
389  (void) store_releaseHandle (m_hImpl);
390  }
391 
394  inline OStoreFile (OStoreFile const & rhs) SAL_THROW(())
395  : m_hImpl (rhs.m_hImpl)
396  {
397  if (m_hImpl)
398  (void) store_acquireHandle (m_hImpl);
399  }
400 
403  inline OStoreFile & operator= (OStoreFile const & rhs) SAL_THROW(())
404  {
405  if (rhs.m_hImpl)
406  (void) store_acquireHandle (rhs.m_hImpl);
407  if (m_hImpl)
408  (void) store_releaseHandle (m_hImpl);
409  m_hImpl = rhs.m_hImpl;
410  return *this;
411  }
412 
415  inline explicit OStoreFile (storeFileHandle Handle) SAL_THROW(())
416  : m_hImpl (Handle)
417  {
418  if (m_hImpl)
419  (void) store_acquireHandle (m_hImpl);
420  }
421 
424  inline operator storeFileHandle (void) const SAL_THROW(())
425  {
426  return m_hImpl;
427  }
428 
432  inline bool isValid (void) const SAL_THROW(())
433  {
434  return (m_hImpl != 0);
435  }
436 
441  rtl::OUString const & rFilename,
442  storeAccessMode eAccessMode,
443  sal_uInt16 nPageSize = STORE_DEFAULT_PAGESIZE) SAL_THROW(())
444  {
445  if (m_hImpl)
446  {
447  (void) store_releaseHandle (m_hImpl);
448  m_hImpl = 0;
449  }
450  return store_openFile (rFilename.pData, eAccessMode, nPageSize, &m_hImpl);
451  }
452 
457  sal_uInt16 nPageSize = STORE_DEFAULT_PAGESIZE) SAL_THROW(())
458  {
459  if (m_hImpl)
460  {
461  (void) store_releaseHandle (m_hImpl);
462  m_hImpl = 0;
463  }
464  return store_createMemoryFile (nPageSize, &m_hImpl);
465  }
466 
470  inline void close (void) SAL_THROW(())
471  {
472  if (m_hImpl)
473  {
474  (void) store_closeFile (m_hImpl);
475  m_hImpl = 0;
476  }
477  }
478 
482  inline storeError flush (void) const SAL_THROW(())
483  {
484  if (!m_hImpl)
485  return store_E_InvalidHandle;
486 
487  return store_flushFile (m_hImpl);
488  }
489 
493  inline storeError getRefererCount (sal_uInt32 & rnRefCount) const SAL_THROW(())
494  {
495  if (!m_hImpl)
496  return store_E_InvalidHandle;
497 
498  return store_getFileRefererCount (m_hImpl, &rnRefCount);
499  }
500 
504  inline storeError getSize (sal_uInt32 & rnSize) const SAL_THROW(())
505  {
506  if (!m_hImpl)
507  return store_E_InvalidHandle;
508 
509  return store_getFileSize (m_hImpl, &rnSize);
510  }
511 
516  rtl::OUString const & rPath,
517  rtl::OUString const & rName,
518  sal_uInt32 nMask1,
519  sal_uInt32 nMask2,
520  sal_uInt32 & rnAttrib) SAL_THROW(())
521  {
522  if (!m_hImpl)
523  return store_E_InvalidHandle;
524 
525  return store_attrib (m_hImpl, rPath.pData, rName.pData, nMask1, nMask2, &rnAttrib);
526  }
527 
532  rtl::OUString const & rPath,
533  rtl::OUString const & rName,
534  sal_uInt32 nMask1,
535  sal_uInt32 nMask2) SAL_THROW(())
536  {
537  if (!m_hImpl)
538  return store_E_InvalidHandle;
539 
540  return store_attrib (m_hImpl, rPath.pData, rName.pData, nMask1, nMask2, NULL);
541  }
542 
546  inline storeError link (
547  rtl::OUString const & rSrcPath, rtl::OUString const & rSrcName,
548  rtl::OUString const & rDstPath, rtl::OUString const & rDstName) SAL_THROW(())
549  {
550  if (!m_hImpl)
551  return store_E_InvalidHandle;
552 
553  return store_link (
554  m_hImpl, rSrcPath.pData, rSrcName.pData, rDstPath.pData, rDstName.pData);
555  }
556 
561  rtl::OUString const & rSrcPath, rtl::OUString const & rSrcName,
562  rtl::OUString const & rDstPath, rtl::OUString const & rDstName) SAL_THROW(())
563  {
564  if (!m_hImpl)
565  return store_E_InvalidHandle;
566 
567  return store_symlink (m_hImpl, rSrcPath.pData, rSrcName.pData, rDstPath.pData, rDstName.pData);
568  }
569 
574  rtl::OUString const & rSrcPath, rtl::OUString const & rSrcName,
575  rtl::OUString const & rDstPath, rtl::OUString const & rDstName) SAL_THROW(())
576  {
577  if (!m_hImpl)
578  return store_E_InvalidHandle;
579 
580  return store_rename (m_hImpl, rSrcPath.pData, rSrcName.pData, rDstPath.pData, rDstName.pData);
581  }
582 
586  inline storeError remove (
587  rtl::OUString const & rPath, rtl::OUString const & rName) SAL_THROW(())
588  {
589  if (!m_hImpl)
590  return store_E_InvalidHandle;
591 
592  return store_remove (m_hImpl, rPath.pData, rName.pData);
593  }
594 
595 private:
598  storeFileHandle m_hImpl;
599 };
600 
601 /*========================================================================
602  *
603  * The End.
604  *
605  *======================================================================*/
606 
607 } // namespace store
608 
609 #endif /* !_STORE_STORE_HXX_ */
610 
611 
612 
613 
614 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */