NIST Biometric Evaluation Framework
Software components for biometric technology evaluations
be_memory.h
Go to the documentation of this file.
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
11#ifndef __BE_MEMORY__
12#define __BE_MEMORY__
13
14#include <memory>
15#include <type_traits>
16
17namespace BiometricEvaluation {
25 namespace Memory
26 {
35 template<class T>
36 struct unique_if
37 {
39 using unique_single = std::unique_ptr<T>;
40 };
41
51 template<class T>
52 struct unique_if<T[]>
53 {
55 using unique_array_unknown_bound = std::unique_ptr<T[]>;
56 };
57
66 template<class T, size_t S>
67 struct unique_if<T[S]>
68 {
71 };
72
86 template<typename T, typename... Ts>
88 make_unique(Ts&&... params)
89 {
90 return (std::unique_ptr<T>
91 (new T(std::forward<Ts>(params)...)));
92 }
93
107 template<class T>
108 typename unique_if<T>::unique_array_unknown_bound
109 make_unique(size_t size)
110 {
111 typedef typename std::remove_extent<T>::type U;
112 return (std::unique_ptr<T>(new U[size]()));
113 }
114
127 template<class T, class... Ts>
128 typename unique_if<T>::unique_array_known_bound
129 make_unique(Ts&&...) = delete;
130
138 inline bool
140 {
141 /* Anonymous union */
142 union { uint32_t i; uint8_t c; } u;
143 u.i = 1;
144
145 /*
146 * Explore contents of octet 1 via properties of union.
147 *
148 * i = 0x00000001
149 *
150 * |1 |2 |3 |4
151 * |-------|-------|-------|-------
152 * Little Endian|01 |00 |00 |00
153 * Big Endian|00 |00 |00 |01
154 */
155 return (u.c == 1);
156 }
157 }
158}
159#endif /* __BE_MEMORY__ */
160
bool isLittleEndian()
Determine endianess of current platform.
Definition: be_memory.h:139
unique_if< T >::unique_single make_unique(Ts &&... params)
Framework version of std::make_unique for non-array types.
Definition: be_memory.h:88
This software was developed at the National Institute of Standards and Technology (NIST) by employees...
std::unique_ptr< T[]> unique_array_unknown_bound
Type to use when T is unknown-bound array.
Definition: be_memory.h:55
void unique_array_known_bound
Type to use when T is known-bound array.
Definition: be_memory.h:70
Define a type that is visible when T is not an array.
Definition: be_memory.h:37
std::unique_ptr< T > unique_single
Type to use when T is not an array.
Definition: be_memory.h:39