]>
git.saurik.com Git - apple/security.git/blob - Security/libsecurity_cdsa_utilities/lib/db++.h
2 * Copyright (c) 2003-2004,2006,2011,2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
26 // dbm++ - generic C++ layer interface to [n]dbm
31 #include <security_utilities/utilities.h>
32 #include <security_cdsa_utilities/cssmdata.h>
33 #include <security_utilities/unix++.h>
39 namespace UnixPlusPlus
{
42 class UnixDb
: public FileDesc
{
45 UnixDb(const char *path
, int flags
= O_RDWR
, int mode
= 0666, DBTYPE type
= DB_HASH
);
46 UnixDb(const std::string
&path
, int flags
= O_RDWR
, int mode
= 0666, DBTYPE type
= DB_HASH
);
50 void open(const char *path
, int flags
= O_RDWR
, int mode
= 0666, DBTYPE type
= DB_HASH
);
51 void open(const std::string
&path
, int flags
= O_RDWR
, int mode
= 0666, DBTYPE type
= DB_HASH
);
54 bool get(const CssmData
&key
, CssmData
&value
, int flags
= 0) const;
55 bool get(const CssmData
&key
, CssmOwnedData
&value
, int flags
= 0) const;
56 bool put(const CssmData
&key
, const CssmData
&value
, int flags
= 0);
57 void erase(const CssmData
&key
, int flags
= 0);
58 void flush(int flags
= 0);
60 bool next(CssmData
&key
, CssmData
&value
, int flags
= R_NEXT
) const;
61 bool first(CssmData
&key
, CssmData
&value
) const
62 { return next(key
, value
, R_FIRST
); }
64 operator bool () const
68 struct Data
: public PodWrapper
<Data
, DBT
> {
70 Data(const T
&src
) { DBT::data
= src
.data(); DBT::size
= src
.length(); }
73 Data(void *data
, size_t length
) { DBT::data
= data
; DBT::size
= length
; }
74 Data(const DBT
&dat
) { DBT::data
= dat
.data
; DBT::size
= dat
.size
; }
76 void *data() const { return DBT::data
; }
77 size_t length() const { return size
; }
78 operator bool () const { return DBT::data
!= NULL
; }
79 operator CssmData () const { return CssmData(data(), length()); }
87 } // end namespace UnixPlusPlus
88 } // end namespace Security