NIST Biometric Evaluation Framework
Software components for biometric technology evaluations
be_memory_autoarrayutility.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_AUTOARRAYUTILITY_H__
12#define __BE_MEMORY_AUTOARRAYUTILITY_H__
13
14#include <cstdarg>
15#include <cstdio>
16#include <string>
17#include <type_traits>
18
19#include <be_error_exception.h>
20#include <be_memory_autoarray.h>
21
22namespace BiometricEvaluation
23{
24 namespace Memory
25 {
27 namespace AutoArrayUtility
28 {
39 template <typename T, typename = typename
40 std::enable_if<std::is_same<T, uint8_t>::value ||
41 std::is_same<T, char>::value>::type>
42 inline char *
44 const AutoArray<T> &rahc)
45 {
46 return ((char *)&(*rahc));
47 }
48
64 template <typename T, typename = typename
65 std::enable_if<std::is_same<T, uint8_t>::value ||
66 std::is_same<T, char>::value>::type>
67 inline std::string
69 const AutoArray<T> &aa,
70 typename AutoArray<T>::size_type count)
71 {
72 if (count > aa.size())
73 throw Error::MemoryError();
74
75 return (std::string(cstr(aa), count));
76 }
77
87 template <typename T, typename = typename
88 std::enable_if<std::is_same<T, uint8_t>::value ||
89 std::is_same<T, char>::value>::type>
90 inline void
92 AutoArray<T> &aa,
93 const std::string &str)
94 {
95 aa.resize(str.size() + 1);
96 ::snprintf(cstr(aa), aa.size(), "%s",
97 str.c_str());
98 }
99
111 template <typename T, typename = typename
112 std::enable_if<std::is_same<T, uint8_t>::value ||
113 std::is_same<T, char>::value>::type>
114 inline void
116 AutoArray<T> &aa,
117 const char *str,
118 ...)
119 {
120 aa.resize(strlen(str) + 1);
121
122 va_list args;
123 va_start(args, str);
124 ::vsnprintf(cstr(aa), aa.size(), str, args);
125 va_end(args);
126 }
127 }
128 }
129}
130
141template <typename T, typename = typename
142 std::enable_if<std::is_same<T, uint8_t>::value ||
143 std::is_same<T, char>::value>::type>
144inline std::string
147{
148 return (std::string(
150 aa.size() - 1));
151}
152
153#endif /* __BE_MEMORY_AUTOARRAYUTILITY_H__ */
std::string to_string(const BiometricEvaluation::Memory::AutoArray< T > &aa)
Convert a uint8_t or char AutoArray to a string.
An error occurred when allocating an object.
A C-style array wrapped in the facade of a C++ STL container.
size_type size() const
Obtain the number of accessible elements.
size_t size_type
Type of subscripts, counts, etc.
void resize(size_type new_size, bool free=false)
Change the number of accessible elements.
std::string getString(const AutoArray< T > &aa, typename AutoArray< T >::size_type count)
Convert a uint8_t or char AutoArray to a string.
char * cstr(const AutoArray< T > &rahc)
Cast an AutoArray of uint8_t or char to a char*.
void setString(AutoArray< T > &aa, const std::string &str)
Copy a string into an AutoAray of uint8_t or char.
This software was developed at the National Institute of Standards and Technology (NIST) by employees...