Data types and type management

pni::type_id_t

enum 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

boolean data

Operators

PNINEXUS_EXPORT std::ostream &pni::operator<<(std::ostream &o, const type_id_t &tid)

output operator for type_id_t

Adds a string representation of a TypeID to the output stream.

Return

reference to output stream

Parameters
  • o: reference to output stream

  • tid: reference to the TypID

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.

Return

true if tid refers to a numeric type, false otherwise

Parameters
  • tid: type ID of the type to check

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.

Return

true if tid refers to an integer type, false otherwise

Parameters
  • tid: type ID of the type to check

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.

Return

true if tid refers to a complex type, false otherwise

Parameters
  • tid: type ID of the type to check

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.

Return

true if tid refers to a float type, false otherwise

Parameters
  • tid: id of the type to check

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.

Return

true if types are checked convertible, false otherwise

Parameters
  • source_tid: ID of the source type

  • target_tid: ID of the target type

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.

Return

true if types are unchecked convertible, false otherwise

Parameters
  • source_tid: ID of the source type

  • target_tid: ID of the target type

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.

Return

true if types are , false otherwise

Parameters
  • source_tid: ID of the source type

  • target_tid: ID of the target type

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.

Return

corresponding type ID

Exceptions
  • key_error: if the string does not describe a type

Parameters
  • s: string representation of the type

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.

Return

string representation of the type

Exceptions
  • key_error: if the type has no string representation

Parameters
  • id: type ID of the type

template<typename T>
type_id_t pni::type_id(const T&)

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.

Return

type ID

Template Parameters
  • T: type if the object

pni::type_class_t

enum 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

pni::bool_t

class pni::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.

Public Functions

bool_t()

default constructor

bool_t(bool v)

conversion constructor

operator bool() const

conversion operator

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.

Return

reference to the output stream

Parameters
  • stream: reference the output stream

  • n: none instance

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.

Return

reference to the input stream

Parameters
  • stream: reference the input stream

  • n: none instance

PNINEXUS_EXPORT bool pni::operator==(const none &a, const none &b)

equality operator for none

Two instance of none are always considered equal.

Return

always true

Parameters
  • a: instance on the lhs of the operator

  • b: instance on the rhs of the operator

PNINEXUS_EXPORT bool pni::operator!=(const none &a, const none &b)

inquality operator for none

Two instances of none are always equal and thus this will always return false.

Return

always false

Parameters
  • a: instance on the lhs of the operator

  • b: instnace on the rhs of the operator

pni::binary_t

template<typename NTYPE>
class pni::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.

Thus this type cannot be used for arithmetic operations directly. Its primary purpose is to hold uninterpreted binary data for transfer. However it can be converted to the native type used to hold the data. Stream operators are provided for IO operations using binary data.

Template Parameters
  • NTYPE: native type used to store binary data

Public Types

typedef NTYPE storage_type

native type that is used for binary data

Public Functions

binary_t()

default constructor

binary_t(const storage_type &value)

constructor

binary_t(const binary_t<storage_type> &o)

copy constructor

operator NTYPE() const

conversion operator

Allows a conversion from BinaryType<NTYPE> to the underlying NTYPE.

template<typename NTYPE>
std::ostream &pni::operator<<(std::ostream &os, const binary_t<NTYPE> &o)

output stream operator for binary data

This is the overloaded output stream operator for binary data.

Return

reference to the modified output stream

Template Parameters
  • NTYPE: basic type for binary

Parameters
  • os: reference to the output stream

  • o: reference to the binary object