]>
git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_utilities/db++.h
2 * Copyright (c) 2003 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
20 // dbm++ - generic C++ layer interface to [n]dbm
25 #include <Security/utilities.h>
26 #include <Security/cssmdata.h>
27 #include <Security/unix++.h>
33 namespace UnixPlusPlus
{
36 class UnixDb
: public FileDesc
{
39 UnixDb(const char *path
, int flags
= O_RDWR
, int mode
= 0666, DBTYPE type
= DB_HASH
);
40 UnixDb(const std::string
&path
, int flags
= O_RDWR
, int mode
= 0666, DBTYPE type
= DB_HASH
);
44 void open(const char *path
, int flags
= O_RDWR
, int mode
= 0666, DBTYPE type
= DB_HASH
);
45 void open(const std::string
&path
, int flags
= O_RDWR
, int mode
= 0666, DBTYPE type
= DB_HASH
);
48 bool get(const CssmData
&key
, CssmData
&value
, int flags
= 0) const;
49 bool get(const CssmData
&key
, CssmOwnedData
&value
, int flags
= 0) const;
50 bool put(const CssmData
&key
, const CssmData
&value
, int flags
= 0);
51 void erase(const CssmData
&key
, int flags
= 0);
52 void flush(int flags
= 0);
54 bool next(CssmData
&key
, CssmData
&value
, int flags
= R_NEXT
) const;
55 bool first(CssmData
&key
, CssmData
&value
) const
56 { return next(key
, value
, R_FIRST
); }
58 operator bool () const
62 struct Data
: public PodWrapper
<Data
, DBT
> {
64 Data(const T
&src
) { DBT::data
= src
.data(); DBT::size
= src
.length(); }
67 Data(void *data
, size_t length
) { DBT::data
= data
; DBT::size
= length
; }
68 Data(const DBT
&dat
) { DBT::data
= dat
.data
; DBT::size
= dat
.size
; }
70 void *data() const { return DBT::data
; }
71 size_t length() const { return size
; }
72 operator bool () const { return DBT::data
!= NULL
; }
73 operator CssmData () const { return CssmData(data(), length()); }
81 } // end namespace UnixPlusPlus
82 } // end namespace Security