.. Jynx documentation master file, created by sphinx-quickstart on Sun Jul 05 12:43:34 2009. You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. C++ Chooser API =============== Introduction ------------ This is the documentation of the ``Chooser`` API for C++. The major references for ``Chooser`` objects are the * `eXplode paper `_ where Choosers originated. * the article `How to do model checking of Python code `_ by Mark Seaborn who gave a simple implementation and whose blog article introduced me to the method. * finally there is my own blog article `Choosers in Python and C++ `_ which contains yet another introduction along with an even more simplified Python algorithm. It covers also some aspects of interest for C++ programmers. Download -------- `chooser.h `_ Classes ------- .. class:: Chooser .. cfunction:: int choose(int choices) choose(k) is a short form for :: int A[] = {0,1,2,...,k-1}; choose(A, k); .. cfunction:: template T choose(T choices[], int cnt) The array expression :: T A[] = {t1, t2, t3,...,tk}; choose(A, k); will be translated into :: vector V; for(int i=0; i typename Container::value_type choose(Container& C) This is the most general form of ``choose()``. The template parameter is a single-parametric STL-container, for example ``set`` or ``vector``. The type parameter of the container becomes the return type. It will be determined by the compiler. .. class:: ChooserMixin Mixin class used to provide a ``Chooser`` valued member variable to classes which derive from ``ChooserMixin`` .. cfunction:: void check() Function being analog to the unbound ``check`` function. It takes no argument but calls the ``test`` method instead which is responsible for invoking an arbitrary method that can access the ``Chooser`` member of the mixin. .. cfunction:: void test() = 0 Abstract test method which has to be overridden in classes which inherit from ``ChooserMixin``. Functions --------- .. cfunction:: template void check(Functor& func) ``check`` is implemented as an unbound function. Check accepts functions as parameters having the following shape :: void funcname(Chooser& chooser) { ... } as well as "Functor" objects i.e. objects which overload the function call operator ``()`` :: class Foo { ... public: void operator()(Chooser& chooser); ... } Usage ----- The following example demonstrates how Chooser objects are used in practice :: void test(Chooser& chooser) { int x = chooser.choose(2); string y; if(x) { string w[] = {"a", "b", "c"}; y = chooser.choose(w, 3); } else { set w; w.insert("x"); w.insert("y"); w.insert("z"); y = chooser.choose(w); } printf("x = %d, y = %s\n", x, y.c_str()); } When we aooly ``check(test)`` the following result will be yielded :: x = 0, y = x x = 0, y = y x = 0, y = z x = 1, y = a x = 1, y = b x = 1, y = c