|
casacore
|
Topics | |
| Utilities_module_internal_classes | |
| Internal Utilities_module classes and functions. | |
Functions | |
| template<typename t> | |
| void | casacore::assert_ (bool expr, const char *msg, const char *file, int line) |
| | |
| template<class T> | |
| uInt | casacore::genSort (T *data, uInt nr, Sort::Order order=Sort::Ascending, int options=0) |
| Global in-place sort functions The following global functions are easier to use than the static GenSort member functions. | |
| template<class T, class INX = uInt> | |
| uInt | casacore::genSort (Vector< INX > &indexVector, const T *data, INX nr, Sort::Order order=Sort::Ascending, int options=0) |
| Global indirect sort functions The following global functions easier to use than the static GenSortIndirect member functions. | |
| uInt | casacore::precisionForValueErrorPairs (const Vector< Double > &pair1, const Vector< Double > &pair2) |
| | |
Classes and global functions for general use
See below for an overview of the classes in this module.
This module is a bag of unrelated mini-modules, classes and global functions. The following functional groups can be recognized:
Tip: You may want to look at the individual header files to see whether you might not prefer to include only the header files you really need; it may be more efficient to do so;
| void casacore::assert_ | ( | bool | expr, |
| const char * | msg, | ||
| const char * | file, | ||
| int | line ) |
Utility function for Assert macros.
Public interface
Templated function assert_ is the basis for the macros DebugAssertExit, DebugAssert, AlwaysAssertExit, and AlwaysAssert which form the "public interface" to the Assertion mechanism.
The present Assertion mechanism uses the exception handling mechanism to throw the errors when an Assertion fails. It can be used in two ways:
Tip: DebugAssertExit and DebugAssert are only invoked in debug mode (i;e; when AIPS_DEBUG is defined); otherwise they preprocess to null statements; AlwaysAssertExit and AlwaysAssert are always invoked;
The implementation of the Array classes contains many examples of the Assertion mechanism. The following application of the Assertion mechanism is taken from the archive of the aips2.nosp@m.-wor.nosp@m.kers@.nosp@m.nrao.nosp@m..edu mail group (Brian Glendenning, 1994/03/23):
I thought I'd readvertise a technique I use that helps me find problems in the classes I write. I have found this to be an EXTREMELY useful way of discovering bugs automatically (so the users of your class don't have to manually).
In your class, write an ok() member function that returns a Bool. Allow for inheritance and make it a virtual function (in fact, the derived class's ok() would probably call the ok() from its parent, as well as doing specific stuff for the derived class).
Then in every member function, place a call to ok() in an Assertion. Like this:
The second argument is the exception you want to throw. AipsError will always do, although you can throw a more particular one if you want to. This Assertion will not be in production code – i.e. if AIPS_DEBUG is not defined, the above line will be a null statement. I place these lines at the entry to all member functions (except I place them at the end of a constructor!). (I normally don't put an Assertion in an inline function).
In the ok() function you should Assert a class's invariants. This is more or less the same as Asserting that an object's private and protected data are consistent. For example, one of the simple tests I do in the array classes is Assert that the number of elements (which I cache) is indeed equal to the product of its shape (I do ~15 tests in the ok() for the new Array<T> class).
this templated function is called from Assert macros
|
inline |
Global in-place sort functions The following global functions are easier to use than the static GenSort member functions.
They do an in-place sort of data, thus the data themselves are moved ending up in the requested order.
The default sorting method is QuickSort, which is the fastest. However, there are pathological cases where it can be slow. HeapSort is about twice a slow, but its speed is guaranteed. InsSort (insertion sort) can be very, very slow, but it is the only stable sort method (i.e. equal values are kept in their original order). However, (see (name=genSortIndirect)) indirect sorting methods
are available to make QuickSort and HeapSort stable.
All sort methods have an option to skip duplicate values. This is the only case where the returned number of values can be less than the original number of values.
Definition at line 312 of file GenSort.h.
References casacore::Sort::Ascending, order(), and casacore::GenSort< T >::sort().
|
inline |
Global indirect sort functions The following global functions easier to use than the static GenSortIndirect member functions.
They do an indirect sort of data, thus the data themselves are not moved. Rather an index vector is returned giving the sorted data indices.
The sorting method used is merge sort, which is always stable. It is the fastest, especially if it can use multiple threads.
Unlike the (see (name=genSortInPlace)) in-place sorting methods, all indirect sorting methods are stable (i.e. equal values are left in their original order).
All sort methods have an option to skip duplicate values. This is the only case where the returned number of values can be less than the original number of values.
Definition at line 358 of file GenSort.h.
References casacore::Sort::Ascending, order(), and casacore::GenSortIndirect< T, INX >::sort().