Data types and type management¶
pni::type_id_t
¶
-
enum class pni::type_id_t¶
type codes for PNI data types
Typed enumeration with type IDs.
Values:
-
enumerator None¶
no data type
-
enumerator Int8¶
signed 8Bit integer
-
enumerator UInt8¶
unsigned 8Bit integer
-
enumerator Int16¶
signed 16Bit integer
-
enumerator UInt16¶
unsigned 16Bit integer
-
enumerator Int32¶
signed 32Bit integer
-
enumerator UInt32¶
unsigned 32Bit integer
-
enumerator Int64¶
signed 64Bit integer
-
enumerator UInt64¶
unsigned 64Bit integer
-
enumerator Float32¶
32Bit IEEE floating point
-
enumerator Float64¶
64Bit IEEE floating point
-
enumerator Float128¶
128Bit IEEE floating point
-
enumerator Complex32¶
32Bit IEEE floating point complex
-
enumerator Complex64¶
64Bit IEEE floating point complex
-
enumerator Complex128¶
128Bit IEEE floating point complex
-
enumerator String¶
String type.
-
enumerator Binary¶
binary data
-
enumerator Bool¶
integer boolean data
-
enumerator EBool¶
enum boolean data
-
enumerator None¶
Operators¶
Predicates¶
-
PNINEXUS_EXPORT bool pni::is_numeric(type_id_t tid)¶
check numeric type
Returns true if the type associated with tid belongs to the numeric types.
- Parameters:
tid – type ID of the type to check
- Returns:
true if tid refers to a numeric type, false otherwise
-
PNINEXUS_EXPORT bool pni::is_integer(type_id_t tid)¶
check integer type
Returns true if the type associated with tid belongs to the integer types.
- Parameters:
tid – type ID of the type to check
- Returns:
true if tid refers to an integer type, false otherwise
-
PNINEXUS_EXPORT bool pni::is_complex(type_id_t tid)¶
check complex type
Returns true if the type associated with tid belongs to the complex types.
- Parameters:
tid – type ID of the type to check
- Returns:
true if tid refers to a complex type, false otherwise
-
PNINEXUS_EXPORT bool pni::is_float(type_id_t tid)¶
check float type
Returns true if the type associated with the tid belongs to the float types.
- Parameters:
tid – id of the type to check
- Returns:
true if tid refers to a float type, false otherwise
-
PNINEXUS_EXPORT bool pni::is_checked_convertible(type_id_t source_tid, type_id_t target_tid)¶
check if two types are checked convertible
Returns true if two types, determined by their type ID, are checked convertible.
- Parameters:
source_tid – ID of the source type
target_tid – ID of the target type
- Returns:
true if types are checked convertible, false otherwise
-
PNINEXUS_EXPORT bool pni::is_unchecked_convertible(type_id_t source_tid, type_id_t target_tid)¶
check if two types are unchecked convertible
Returns true if two types, determined by their type ID, are unchecked convertible.
- Parameters:
source_tid – ID of the source type
target_tid – ID of the target type
- Returns:
true if types are unchecked convertible, false otherwise
-
PNINEXUS_EXPORT bool pni::is_convertible(type_id_t source_tid, type_id_t target_tid)¶
check if two types are unchecked convertible
Returns true if two types, determined by their type ID, are convertible.
- Parameters:
source_tid – ID of the source type
target_tid – ID of the target type
- Returns:
true if types are , false otherwise
Utility functions¶
-
PNINEXUS_EXPORT type_id_t pni::type_id_from_str(const string &s)¶
get a type ID from a string
Returns the type ID for a particular string representation of a type. If the string passed is not a valid type representation an exception will be thrown.
- Throws:
key_error – if the string does not describe a type
- Parameters:
s – string representation of the type
- Returns:
corresponding type ID
-
PNINEXUS_EXPORT string pni::str_from_type_id(type_id_t id)¶
get the string rep. for a type
Returns the string representation for a type determined by its type id. If the type determined by the ID does not have a string representation an exception will be thrown.
- Throws:
key_error – if the type has no string representation
- Parameters:
id – type ID of the type
- Returns:
string representation of the type
-
template<typename GeneralT>
type_id_t pni::type_id(const GeneralT&)¶ get type id of an object
This function returns the type ID of an instance of an object. In the case of scalar data the type if a variable is returned. If the argument passed is a container the type id of the element type is returned.
- Template Parameters:
GeneralT – type if the object
- Returns:
type ID
pni::type_class_t
¶
-
enum class pni::type_class_t¶
type class definitions
classes of data types provided by the PNI utility library
Values:
-
enumerator None¶
unspecified type
-
enumerator Integer¶
integer type
-
enumerator Float¶
floating point type
-
enumerator Binary¶
binary data type
-
enumerator Bool¶
boolean data type
-
enumerator Complex¶
complex data type
-
enumerator String¶
class for string types
-
enumerator None¶
pni::bool_t
¶
-
class bool_t¶
boolean type
There is a particular problem when using the standard bool type in connection with std::vector. The std::vector template is overloaded for bool in a sense that each boolean value is stored in an individual bit. Thus elements cannot be addressed. Thus std::vector<bool> cannot be used in connection with libpninexus. This type prevents the C++ compiler to overload std:vector<bool_t> making boolean values available for libpninexus.
pni::none
¶
-
struct none¶
none type
This type is used in situations where a type for initialization is required but not provided (or at the moment not available). It thus denotes the absence of type information.
Operators¶
-
PNINEXUS_EXPORT std::ostream &pni::operator<<(std::ostream &stream, const none &n)¶
output stream for none
Using the none type with the output stream operator has no effect and does not modify the stream.
- Parameters:
stream – reference the output stream
n – none instance
- Returns:
reference to the output stream
-
PNINEXUS_EXPORT std::istream &pni::operator>>(std::istream &stream, none &n)¶
input stream for none
Using the none type with the input stream operator has no effect and does not modify the stream.
- Parameters:
stream – reference the input stream
n – none instance
- Returns:
reference to the input stream
pni::binary_t
¶
-
template<typename NativeT>
class binary_t¶ Binary data type.
This class represents a binary data type. Typically binary data is represented by a typedef to an unsigned char type. However, this has an inconvenience: the unsigned char and the typedef for binary are indistinguishable by the compiler. Thus, such a binary type cannot be used for function overloading or for template specialization - it would always be treated by the compiler as the underlying unsigned char type.
To circumvent this problem
libpninexus
defines this binary type which can be used instead of a simple typedef to unsigned char. The BinaryType template has several advantages:it can be distinguished from the type used to store binary data
all arithmetic operators are stripped from the type.
- Template Parameters:
NativeT – native type used to store binary data
Public Functions
-
inline explicit binary_t()¶
default constructor
-
inline binary_t(const storage_type &value)¶
constructor
-
inline binary_t(const binary_t<storage_type> &o)¶
copy constructor
-
template<typename NativeT>
std::ostream &pni::operator<<(std::ostream &os, const binary_t<NativeT> &o)¶ output stream operator for binary data
This is the overloaded output stream operator for binary data.
- Template Parameters:
NativeT – basic type for binary
- Parameters:
os – reference to the output stream
o – reference to the binary object
- Returns:
reference to the modified output stream