class post_mem_fun

A post condition class. More...

Full namedbg::post_mem_fun
Definition#include <dbg.h>
Template formpost_mem_fun<class obj_t>
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

Public Methods


Detailed Description

A post condition class. This utility automates the checking of post conditions using assertion. It requires a member function with the signature:


     bool some_class::invariant() const;

When you create a post_mem_fun object you specify a post condition member function. When the post_mem_fun object is destroyed the postcondition is asserted.

This is useful for methods where there are a number of exit points which would make it tedious to put the same dbg::assertion in multiple places.

It is also handy when an exception might be thrown and propagated by a function, ensuring that a postcondition is first checked. Bear in mind that Bad Things can happen if the assertion_behaviour is assertions_throw and this is triggered via a propagating exception.

An example of usage, the do_test method below uses the post_mem_fun object:


     class test
     {
         public:
             test() : a(10) {}
             do_test()
             {
                 dbg::post_mem_fun
                    post(dbg::info, this, &test::invariant, DBG_HERE);
                 a = 9;
                 if (SOME_CONDITION)
                 {
                     return;                                      // (*)
                 }
                 else if (SOME_OTHER_CONDITION)
                 {
                     throw std::exception();                      // (*)
                 }
                                                                  // (*)
             }
         private:
             bool invariant()
             {
                 return a == 10;
             }
             int a;
     };

The post condition will be asserted at each point marked (*).

See also: post

 post_mem_fun (level lvl, obj_t *obj, fn_t fn, const source_pos &pos)

post_mem_fun

Parameters:
lvlDiagnostic level
objObject to invoke fn on (usually "this")
fnPost condition member function
hereSupply DBG_HERE

 post_mem_fun (level lvl, dbg_source src, obj_t *obj, fn_t fn, const source_pos &pos)

post_mem_fun

Parameters:
lvlDiagnostic level
srcString describing the diagnostic source
objObject to invoke fn on (usually "this")
fnPost condition member function
hereSupply DBG_HERE

 post_mem_fun (obj_t *obj, fn_t fn, const source_pos &pos)

post_mem_fun

Overloaded version of constructor which defaults to the warning diagnostic level.

Parameters:
objObject to invoke fn on (usually "this")
fnPost condition member function
hereSupply DBG_HERE

 post_mem_fun (dbg_source src, obj_t *obj, fn_t fn, const source_pos &pos)

post_mem_fun

Overloaded version of constructor which defaults to the warning diagnostic level.

Parameters:
srcString describing the diagnostic source
objObject to invoke fn on (usually "this")
fnPost condition member function
hereSupply DBG_HERE

 ~post_mem_fun ()

~post_mem_fun

The destructor asserts the post condition.

 post_mem_fun (level, void *, fn_t, void *)

post_mem_fun

 post_mem_fun (level, dbg_source, void *, fn_t, void *)

post_mem_fun

 post_mem_fun (void *, fn_t, void *)

post_mem_fun

 post_mem_fun (dbg_source, void *, fn_t, void *)

post_mem_fun

 ~post_mem_fun ()

~post_mem_fun


Generated by: pg1 on imgpc030 on Tue Sep 16 13:46:16 2003, using kdoc 2.0a54.