Debian Codegraph @

src/lib/object_store/FindOperation.cpp

raw
1 /*
2 * Copyright (c) 2012 SURFnet bv
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 /*****************************************************************************
28 FindOperation.cpp
29
30 This class represents the find operation that can be used to collect
31 objects that match the attributes contained in a given template.
32 *****************************************************************************/
33
34 #include "config.h"
35 #include "FindOperation.h"
36
37 FindOperation::FindOperation()
38 {
39 }
40
41 FindOperation *FindOperation::create()
42 {
43 return new FindOperation();
44 }
45
46 void FindOperation::recycle()
47 {
48 delete this;
49 }
50
51 void FindOperation::setHandles(const std::set<CK_OBJECT_HANDLE> &handles)
52 {
53 _handles = handles;
54 }
55
56 CK_ULONG FindOperation::retrieveHandles(CK_OBJECT_HANDLE_PTR phObject, CK_ULONG ulCount)
57 {
58 CK_ULONG ulReturn = 0;
59 std::set<CK_OBJECT_HANDLE>::const_iterator it;
60 for (it=_handles.begin(); it != _handles.end(); ++it) {
61 if (ulReturn >= ulCount) break;
62
63 phObject[ulReturn++] = *it;
64 }
65 return ulReturn;
66 }
67
68 CK_ULONG FindOperation::eraseHandles(CK_ULONG ulIndex, CK_ULONG ulCount)
69 {
70 std::set<CK_OBJECT_HANDLE>::const_iterator it;
71 for (it=_handles.begin(); it != _handles.end() && ulIndex != 0; --ulIndex) {
72 ++it;
73 }
74
75 CK_ULONG ulReturn = 0;
76 for ( ; it != _handles.end() && ulReturn < ulCount; ++ulReturn) {
77 _handles.erase(it++);
78 }
79 return ulReturn;
80 }