Nail to Nail Fingerprint Capture Challenge
API for participant-specific one-to-many template generation and template matching.
be_io_recordstore.h
1/******************************************************************************
2 * This software was developed at the National Institute of Standards and
3 * Technology (NIST) by employees of the Federal Government in the course
4 * of their official duties. Pursuant to title 17 Section 105 of the
5 * United States Code, this software is not subject to copyright protection
6 * and is in the public domain. NIST assumes no responsibility whatsoever for
7 * its use by other parties, and makes no guarantees, expressed or implied,
8 * about its quality, reliability, or any other characteristic.
9 ******************************************************************************/
10#ifndef __BE_IO_RECORDSTORE_H__
11#define __BE_IO_RECORDSTORE_H__
12
13#include <functional>
14#include <memory>
15#include <string>
16#include <vector>
17
18#include <be_framework_enumeration.h>
19#include <be_io.h>
20#include <be_memory_autoarray.h>
21
22/*
23 * This file contains the class declaration for the RecordStore, a virtual
24 * class that represents a collection of named blobs of data.
25 */
26
27namespace BiometricEvaluation {
28
29 namespace IO {
30 class RecordStoreIterator;
31
52 public:
53 struct Record {
58
68 const std::string &key,
69 const Memory::uint8Array &data);
70 std::string key;
72 };
73 using Record = struct Record;
74
76
78 enum class Kind
79 {
83 Archive,
85 File,
87 SQLite,
91 List,
92
95 };
96
101 static const std::string INVALIDKEYCHARS;
102
103 virtual ~RecordStore();
104
110 virtual std::string getDescription() const = 0;
111
117 virtual unsigned int getCount() const = 0;
118
125 virtual std::string getPathname() const = 0;
126
139 virtual void move(
140 const std::string &pathname) = 0;
141
150 virtual void changeDescription(
151 const std::string &description) = 0;
152
169 virtual uint64_t getSpaceUsed() const = 0;
170
179 virtual void sync() const = 0;
180
197 void
198 virtual insert(
199 const std::string &key,
200 const Memory::uint8Array &data);
201
220 virtual void
222 const std::string &key,
223 const void *const data,
224 const uint64_t size) = 0;
225
237 virtual void remove(
238 const std::string &key) = 0;
239
257 virtual Memory::uint8Array
259 const std::string &key) const = 0;
260
276 virtual void replace(
277 const std::string &key,
278 const Memory::uint8Array &data);
279
297 virtual void replace(
298 const std::string &key,
299 const void *const data,
300 const uint64_t size);
301
315 virtual uint64_t length(
316 const std::string &key) const = 0;
317
328 virtual void flush(
329 const std::string &key) const = 0;
330
332 static const int BE_RECSTORE_SEQ_START = 1;
334 static const int BE_RECSTORE_SEQ_NEXT = 2;
335
361 virtual RecordStore::Record
363 int cursor = BE_RECSTORE_SEQ_NEXT) = 0;
364
389 virtual std::string
391 int cursor = BE_RECSTORE_SEQ_NEXT) = 0;
392
409 virtual void setCursorAtKey(
410 const std::string &key) = 0;
411
424 virtual bool
426 const std::string &key)
427 const;
428
430 virtual iterator
432 noexcept;
433
435 virtual iterator
437 noexcept;
438
450 static bool
452 const std::string &pathname);
453
480 static std::shared_ptr<RecordStore> openRecordStore(
481 const std::string &pathname,
482 IO::Mode mode = Mode::ReadOnly);
483
508 static std::shared_ptr<RecordStore> createRecordStore(
509 const std::string &pathname,
510 const std::string &description,
511 const IO::RecordStore::Kind &kind);
512
525 static void removeRecordStore(
526 const std::string &pathname);
527
554 static void mergeRecordStores(
555 const std::string &mergePathname,
556 const std::string &description,
557 const IO::RecordStore::Kind &kind,
558 const std::vector<std::string> &pathnames,
559 const std::function<bool()> &interrupt =
560 []() {return (false);});
561
562 class Impl;
563 protected:
564 private:
565 };
566
580 {
581 public:
582 /*
583 * Satisfy std::iterator_traits<> expectations.
584 */
585
587 using iterator_category = std::forward_iterator_tag;
591 using difference_type = std::ptrdiff_t;
596
607
625 IO::RecordStore *recordStore,
626 bool atEnd);
627
630 const RecordStoreIterator &rhs) = default;
633 RecordStoreIterator &&rvalue) = default;
636
637 /*
638 * Operators.
639 */
640
644
646 pointer
648
652
656 int);
657
670 difference_type rhs);
671
684 difference_type rhs);
685
696 bool
698 const RecordStoreIterator &rhs);
699
714 inline bool
716 const RecordStoreIterator &rhs)
717 {
718 return (!(*this == rhs));
719 }
720
721 /* Default copy assignment operator */
723 operator=(
724 const RecordStoreIterator &rhs) = default;
725
729 RecordStoreIterator &&rhs) = default;
730
731 private:
733 IO::RecordStore *_recordStore{nullptr};
735 bool _atEnd{true};
737 value_type _currentRecord{};
738
740 void
741 setBegin();
742
750 void
751 step(
752 difference_type steps = 1);
753
755 void
756 setEnd();
757 };
758 }
759}
760
761BE_FRAMEWORK_ENUMERATION_DECLARATIONS(
763 BE_IO_RecordStore_Kind_EnumToStringMap);
764
765#endif /* __BE_IO_RECORDSTORE_H__ */
A class to represent a data storage mechanism.
Definition: be_io_recordstore.h:51
static std::shared_ptr< RecordStore > openRecordStore(const std::string &pathname, IO::Mode mode=Mode::ReadOnly)
Open an existing RecordStore and return a managed pointer to the the object representing that store.
virtual void setCursorAtKey(const std::string &key)=0
Set the sequence cursor to an arbitrary position within the RecordStore, starting at key.
virtual std::string getDescription() const =0
Obtain a textual description of the RecordStore.
virtual void changeDescription(const std::string &description)=0
Change the description of the RecordStore.
virtual void insert(const std::string &key, const Memory::uint8Array &data)
Insert a record into the store.
static const std::string INVALIDKEYCHARS
The set of prohibited characters in a key: '/', '\', '*', '&'.
Definition: be_io_recordstore.h:101
virtual void remove(const std::string &key)=0
Remove a record from the store.
static const int BE_RECSTORE_SEQ_START
Tell sequence() to sequence from beginning.
Definition: be_io_recordstore.h:332
static bool isRecordStore(const std::string &pathname)
Determine if a location appears to be a RecordStore.
virtual uint64_t length(const std::string &key) const =0
Return the length of a record.
virtual iterator begin() noexcept
virtual bool containsKey(const std::string &key) const
Determines whether the RecordStore contains an element with the specified key.
virtual std::string sequenceKey(int cursor=BE_RECSTORE_SEQ_NEXT)=0
Sequence through a RecordStore, returning the key.
virtual void flush(const std::string &key) const =0
Commit the record's data to storage.
Kind
Possible types of RecordStore.
Definition: be_io_recordstore.h:79
@ Default
"Default" RecordStore kind
virtual uint64_t getSpaceUsed() const =0
Obtain real storage utilization.
static const int BE_RECSTORE_SEQ_NEXT
Tell sequence to sequence from current position.
Definition: be_io_recordstore.h:334
virtual void replace(const std::string &key, const void *const data, const uint64_t size)
Replace a complete record in a RecordStore.
virtual std::string getPathname() const =0
Return the path name of the RecordStore.
virtual void sync() const =0
Synchronize the entire record store to persistent storage.
virtual void move(const std::string &pathname)=0
Move the RecordStore.
virtual unsigned int getCount() const =0
Obtain the number of items in the RecordStore.
virtual iterator end() noexcept
virtual RecordStore::Record sequence(int cursor=BE_RECSTORE_SEQ_NEXT)=0
Sequence through a RecordStore, returning the key/data pairs.
virtual void replace(const std::string &key, const Memory::uint8Array &data)
Replace a complete record in a RecordStore.
static std::shared_ptr< RecordStore > createRecordStore(const std::string &pathname, const std::string &description, const IO::RecordStore::Kind &kind)
Create a new RecordStore and return a managed pointer to the the object representing that store.
static void mergeRecordStores(const std::string &mergePathname, const std::string &description, const IO::RecordStore::Kind &kind, const std::vector< std::string > &pathnames, const std::function< bool()> &interrupt=[]() {return(false);})
Create a new RecordStore that contains the contents of several other RecordStores.
virtual void insert(const std::string &key, const void *const data, const uint64_t size)=0
Insert a record into the store.
virtual Memory::uint8Array read(const std::string &key) const =0
Read a complete record from a store.
static void removeRecordStore(const std::string &pathname)
Remove a RecordStore by deleting all persistant data associated with the store.
Generic ForwardIterator for all RecordStores.
Definition: be_io_recordstore.h:580
RecordStoreIterator operator+(difference_type rhs)
Advance a variable number of arguments.
RecordStoreIterator(RecordStoreIterator &&rvalue)=default
Default move constructor.
RecordStoreIterator(const RecordStoreIterator &rhs)=default
Default copy constructor.
RecordStoreIterator()=default
Default constructor.
RecordStoreIterator & operator=(RecordStoreIterator &&rhs)=default
Default move assignment operator.
bool operator!=(const RecordStoreIterator &rhs)
Non-equivalence operator.
Definition: be_io_recordstore.h:715
RecordStoreIterator operator+=(difference_type rhs)
Advance a variable number of arguments.
RecordStoreIterator(IO::RecordStore *recordStore, bool atEnd)
Constructor.
std::forward_iterator_tag iterator_category
Type of iterator.
Definition: be_io_recordstore.h:587
bool operator==(const RecordStoreIterator &rhs)
Equivalence operator.
std::ptrdiff_t difference_type
Type used to measure distance between iterators.
Definition: be_io_recordstore.h:591
~RecordStoreIterator()=default
Default destructor.
RecordStore::Record value_type
Type when dereferencing iterators.
Definition: be_io_recordstore.h:589
A C-style array wrapped in the facade of a C++ STL container.
Definition: be_memory_autoarray.h:45
Definition: be_io_recordstore.h:53
Record(const std::string &key, const Memory::uint8Array &data)
Create a Record from the key and data.