Enrollment 28.2.0
Loading...
Searching...
No Matches
PrintTemplate.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include "enrollment/Export.h"
17#include <algorithm>
18#include <vector>
19
20namespace inno
21{
25 */
26 class PrintTemplate : public Serializable
27 {
28 public:
38 */
39 static std::vector<std::shared_ptr<ICSTemplate>> ToICSTemplates(
40 const std::vector<std::shared_ptr<PrintTemplate>>& templates)
41 {
42 std::vector<std::shared_ptr<ICSTemplate>> icsTemplates(templates.size());
43 std::transform(templates.begin(),
44 templates.end(),
45 icsTemplates.begin(),
46 [](const auto& pt) { return pt != nullptr ? pt->GetICSRepresentation() : nullptr; });
47 return icsTemplates;
48 }
58 */
59 static std::vector<std::shared_ptr<EmbeddingTemplate>> ToEmbeddingTemplates(
60 const std::vector<std::shared_ptr<PrintTemplate>>& templates)
61 {
62 std::vector<std::shared_ptr<EmbeddingTemplate>> embeddings(templates.size());
63 std::transform(templates.begin(),
64 templates.end(),
65 embeddings.begin(),
66 [](const auto& pt) { return pt != nullptr ? pt->GetEmbeddingRepresentation() : nullptr; });
67 return embeddings;
68 }
72 */
73 [[nodiscard]] std::shared_ptr<ICSTemplate> GetICSRepresentation() const
74 {
75 return t;
76 }
77
85 */
86 [[nodiscard]] std::shared_ptr<EmbeddingTemplate> GetEmbeddingRepresentation() const
87 {
88 return e;
89 }
90
98 */
99 [[nodiscard]] bool HasIcsRepresentation() const
100 {
101 return t != nullptr;
102 }
103
111 */
112 [[nodiscard]] bool HasEmbeddingRepresentation() const
113 {
114 return e != nullptr;
115 }
116
120 */
121 void WriteTo(Writer& writer) const final
122 {
123 writer.Write("ics", t);
124 writer.Write("e", e);
125 }
126
135 */
136 explicit PrintTemplate(std::shared_ptr<ICSTemplate> icsTemplate)
137 : t(std::move(icsTemplate))
138 {
139 if (t == nullptr)
140 {
141 throw NullArgumentException("ICSTemplate cannot be null");
142 }
143 }
144
157 */
158 PrintTemplate(std::shared_ptr<ICSTemplate> icsTemplate, std::shared_ptr<EmbeddingTemplate> embedding)
159 : t(std::move(icsTemplate))
160 , e(std::move(embedding))
161 {
162 if (t == nullptr)
163 {
164 throw NullArgumentException("ICSTemplate cannot be null");
165 }
166 if (e == nullptr)
167 {
168 throw NullArgumentException("Embedding cannot be null");
169 }
170
171 if (!ArePositionsSame(t, e))
172 {
173 throw EnrollmentInvalidArgumentException("ICSTemplate and embedding have different position");
174 }
175 }
176
185 */
186 explicit PrintTemplate(std::shared_ptr<EmbeddingTemplate> embedding)
187 : t(nullptr)
188 , e(std::move(embedding))
189 {
190 if (e == nullptr)
191 {
192 throw NullArgumentException("Embedding cannot be null");
193 }
194 }
195
196 [[nodiscard]] bool operator==(const PrintTemplate& other) const noexcept
197 {
198 auto icsEqual = (t == nullptr && other.t == nullptr) ||
199 (t != nullptr && other.t != nullptr && t->icsTemplateData == other.t->icsTemplateData);
200 auto embEqual = (e == nullptr && other.e == nullptr) ||
201 (e != nullptr && other.e != nullptr &&
202 e->embeddingTemplateData == other.e->embeddingTemplateData);
203 return icsEqual && embEqual;
204 }
205
206 [[nodiscard]] std::size_t Hash() const noexcept
207 {
208 std::size_t h = t != nullptr ? detail::HashBytes(t->icsTemplateData) : 0U;
209 h = detail::HashCombine(h, e != nullptr ? detail::HashBytes(e->embeddingTemplateData) : 0U);
210 return h;
211 }
212
213 PrintTemplate() = delete;
214 virtual ~PrintTemplate() = default;
215 PrintTemplate(const PrintTemplate& ap) = default;
216 PrintTemplate(PrintTemplate&& ap) = default;
217 PrintTemplate& operator=(const PrintTemplate& ap) = default;
218 PrintTemplate& operator=(PrintTemplate&& ap) = default;
219
220 private:
221 std::shared_ptr<ICSTemplate> t;
222 std::shared_ptr<EmbeddingTemplate> e;
223
224 static bool ArePositionsSame(const std::shared_ptr<ICSTemplate>& i, const std::shared_ptr<EmbeddingTemplate>& e)
225 {
226 if (!i->IsICSTemplateBiometricPositionKnown() || !e->IsEmbeddingTemplateBiometricPositionKnown())
227 {
228 // one of position is unknown. When both have unknown position then they are same, otherwise they are
229 // different.
230 return i->IsICSTemplateBiometricPositionKnown() == e->IsEmbeddingTemplateBiometricPositionKnown();
231 }
232 // Both have known position.
233 if (i->GetICSTemplateBiometricPosition() == e->GetEmbeddingTemplateBiometricPosition())
234 {
235 // both have same known position
236 return true;
237 }
238
239 return false;
240 }
241 };
242} // namespace inno
Base exception for all enrollment-sdk invalid argument exceptions.
Definition EnrollmentException.h:96
Null argument is not allowed.
Definition EnrollmentException.h:156
Holds various biometric representation types for print.
Definition PrintTemplate.h:26
void WriteTo(Writer &writer) const final
It serializes applicant print via provided Writer.
Definition PrintTemplate.h:120
PrintTemplate(std::shared_ptr< ICSTemplate > icsTemplate, std::shared_ptr< EmbeddingTemplate > embedding)
Constructs an PrintTemplate object with the provided ICSTemplate and embedding.
Definition PrintTemplate.h:157
bool HasEmbeddingRepresentation() const
Checks if the object has an embedding representation.
Definition PrintTemplate.h:111
bool HasIcsRepresentation() const
Checks if the object has an ICS representation.
Definition PrintTemplate.h:98
PrintTemplate(std::shared_ptr< ICSTemplate > icsTemplate)
Constructs an PrintTemplate object with the provided ICSTemplate.
Definition PrintTemplate.h:135
static std::vector< std::shared_ptr< EmbeddingTemplate > > ToEmbeddingTemplates(const std::vector< std::shared_ptr< PrintTemplate > > &templates)
Converts a PrintTemplate objects into an EmbeddingTemplate objects.
Definition PrintTemplate.h:58
static std::vector< std::shared_ptr< ICSTemplate > > ToICSTemplates(const std::vector< std::shared_ptr< PrintTemplate > > &templates)
Converts a PrintTemplate objects into a ICSTemplate objects.
Definition PrintTemplate.h:38
std::shared_ptr< ICSTemplate > GetICSRepresentation() const
Provides ICS (Innovatrics proprietary extracted template) representation of print.
Definition PrintTemplate.h:72
std::shared_ptr< EmbeddingTemplate > GetEmbeddingRepresentation() const
Retrieves the embedding representation associated with the object.
Definition PrintTemplate.h:85
PrintTemplate(std::shared_ptr< EmbeddingTemplate > embedding)
Constructs an PrintTemplate object with the provided embedding.
Definition PrintTemplate.h:185
Provides interface for serialization of all classes.
Definition Writer.h:164