libpnicore
|
Macros | |
#define | EXCEPTION_RECORD exception_record(__FILE__,__LINE__,BOOST_CURRENT_FUNCTION) |
macro creating an instance of ExceptionRecord | |
#define | EXCEPTION_FORWARD(ETYPE) |
forward an exception More... | |
Functions | |
template<typename VTYPE > | |
void | pni::core::print_vector (std::ostream &o, const VTYPE &v) |
print vector content More... | |
template<typename A , typename B > | |
bool | pni::core::check_equal_size (const A &a, const B &b) |
check if two container have equal size More... | |
template<typename A , typename B > | |
void | pni::core::check_equal_size (const A &a, const B &b, const exception_record &i) |
check if two objects have different size More... | |
bool | pni::core::check_index_in_dim (size_t index, size_t dimsize) |
check index in dim More... | |
void | pni::core::check_index_in_dim (size_t index, size_t dimsize, const exception_record &i) |
check index in dim More... | |
template<typename ITYPE , typename STYPE > | |
bool | pni::core::check_indexes (const ITYPE &index, const STYPE &shape) |
check indexes More... | |
template<typename ITYPE , typename STYPE > | |
void | pni::core::check_indexes (const ITYPE &index, const STYPE &shape, const exception_record &record) |
check indexes More... | |
template<typename A , typename B > | |
bool | pni::core::check_equal_rank (const A &a, const B &b) |
check equal rank More... | |
template<typename A , typename B > | |
void | pni::core::check_equal_rank (const A &a, const B &b, const exception_record &i) |
check equal rank More... | |
template<typename A , typename B > | |
bool | pni::core::check_equal_shape (const A &a, const B &b) |
check for shape equality | |
template<typename A , typename B > | |
void | pni::core::check_equal_shape (const A &a, const B &b, const exception_record &i) |
check shape equality More... | |
template<typename OTYPE > | |
void | pni::core::check_allocation_state (const OTYPE &o, const exception_record &i) |
check allocation state More... | |
template<typename T > | |
void | pni::core::check_ptr_state (const T *ptr, const exception_record &i) |
check pointer state More... | |
std::ostream & | pni::core::operator<< (std::ostream &o, const exception_record &rec) |
error record output operator | |
In version 0.2.5 the exception backend has undergone a major rewrite. The old macros are no longer available. Exceptions provide much more detailed information about where they are thrown and can be stacked to provide a kind of stack trace where an exception has occurred and how it was propagated through the code. All information where an exception occurred is stored in an instance of ExceptionRecord. An instance of this class can easily created using the EXCEPTION_RECORD macro (as in most cases the construction of an ExceptionRecord will look equal). An exception record includes the exact signature of the method or function, the line in the file, and the source file name where the exception was thrown. This should make it easier to identify the location where an exception occurred.
#define EXCEPTION_FORWARD | ( | ETYPE | ) |
This macro can be used to forward an exception caught from another function. It appends the exception_record of the current function to the existing exception and throws the exception again. Consider the following examples
Please note that the MUST NOT BE a semicolon at the end of this macro.
void pni::core::check_allocation_state | ( | const OTYPE & | o, |
const exception_record & | i | ||
) |
Checks the allocation state of an allocateable object. If the object is not allocated an exception will be thrown.
memory_not_allocated_error | if object not allocated |
o | object to check |
i | exception_record for the location where to perform the check |
bool pni::core::check_equal_rank | ( | const A & | a, |
const B & | b | ||
) |
Return true of the two array like objects have an equal number of dimensions. In any other case return false.
A | first array type |
B | second array type |
a | reference to an instance of A |
b | reference to an instance of B |
void pni::core::check_equal_rank | ( | const A & | a, |
const B & | b, | ||
const exception_record & | i | ||
) |
Throwing version of check_equal_rank.
shape_mismatch_error | if a and b have different rank |
A | first array type |
B | second array type |
a | reference to an instance of A |
b | reference to an instance of B |
i | exception record of the calling function |
void pni::core::check_equal_shape | ( | const A & | a, |
const B & | b, | ||
const exception_record & | i | ||
) |
Checks if two Shape objects are equal and throws an exception if they are not.
A | container type for the first shape |
B | container type for the second shape |
size_mismatch_error | if array sizes do not match |
shape_mismatch_error | if shapes do not match |
a | first shape |
b | second shape |
i | exception_record for the location where to perform the check |
bool pni::core::check_equal_size | ( | const A & | a, |
const B & | b | ||
) |
This helper function checks if two container instances have equal size and returns true if this is the case. Otherwise false will be returned. Both container types have to provide a size() method returning the number of elements the container can hold.
A | first container type |
B | second container type |
a | reference to an instance of A |
b | reference to an instance of B |
void pni::core::check_equal_size | ( | const A & | a, |
const B & | b, | ||
const exception_record & | i | ||
) |
This utilty function can be used to check for the equality of the size of two objects. It is typically used to compare the size of a shape and a buffer or any other container object. If the sizes do not match an exception is thrown.
size_mismatch_error | if sizes do not match |
A | first container type |
B | second container type |
a | instance of container type A |
b | instance of container type B |
i | exception_record for the location where to perform the check performed |
bool pni::core::check_index_in_dim | ( | size_t | index, |
size_t | dimsize | ||
) |
Check if an index resides within a dimension range. The index must be than the size of the dimension. If the index is within the dimension size true is returned. false otherwise.
index | the index to check |
dimsize | size of the dimension |
void pni::core::check_index_in_dim | ( | size_t | index, |
size_t | dimsize, | ||
const exception_record & | i | ||
) |
Throwing version of check_index_in_dim. Throws an index_error exception if the index is not within the dimension range.
index_error | if i exceeds dimsize |
index | actual index |
dimsize | dimension size |
i | exception_record for the location where to perform the check performed |
bool pni::core::check_indexes | ( | const ITYPE & | index, |
const STYPE & | shape | ||
) |
Check if all index values stored in a container do not exceed their dimensions limits.
ITYPE | index container type |
STYPE | shape container type |
index | reference to an index container |
shape | reference to a shape container |
void pni::core::check_indexes | ( | const ITYPE & | index, |
const STYPE & | shape, | ||
const exception_record & | record | ||
) |
Checks if all indexes stored in a container lie within a given range determined by the shape. In addition the function checks if the number of indexes matches the number of elements in the shape.
index_error | if one of the indexes exceeds the number of elements in its dimension |
shape_mismatch_error | if the number of indexes does not match the number of dimensions (elements in the shape) |
ITYPE | index container type |
STYPE | shape container type |
index | container with index data |
shape | container with shape data |
record | the exception record of the calling function |
void pni::core::check_ptr_state | ( | const T * | ptr, |
const exception_record & | i | ||
) |
Checks if a pointer is nullptr or not and throws an exception if it is.
memory_not_allocated_error | if pointer is a nullptr |
ptr | pointer to check |
i | exception_record for the location where to perform the check |
void pni::core::print_vector | ( | std::ostream & | o, |
const VTYPE & | v | ||
) |
Print the content of an interable as a vector. The output is embraced by () and each element is separated by a comma.
VTYPE | container type |
o | output stream |
v | iterable instance |