There were a bunch of silly mistakes in the ActionPolicy and ReturnPolicy
implementations.  The attached patch fixes the ActionPolicy and
ReturnPolicy requirements in StateMachineEngine.h and the ActionPolicies.h
header should replace StateMachinePolicies.h.

This makes the use of ActionPolicies a bit more logical and fixes a really
dumb error in the Continue policy (which is now corrected in the revised
Ignore policy -- confused?).

Allan. (ARRae)
--- StateMachineEngine.h.orig   2001/04/23 13:01:27     1.1
+++ StateMachineEngine.h        2001/04/23 13:33:43
@@ -114,15 +114,15 @@ protected:
  * @code
  * struct ReturnPolicy
  * {
- *     bool operator() ();
+ *     bool operator() (bool);
  * };
  *
- * template <class ReturnPolicy, class Data>
+ * template <class Data, class ReturnPolicy>
  * struct ActionPolicy
  * {
  *     bool operator() (bool assertion, string const & msg, Data const &) {
  *             ...
- *             return ReturnPolicy()();
+ *             return ReturnPolicy()(assertion);
  *     }
  * };
  * @endcode
@@ -137,11 +137,14 @@ protected:
  * if (ActionPolicy()(group_vector_.exists(group),
  *                   "This SMGroup doesn't exist : ",
  *                   group)) {
- *     // group doesn't exist and we should ignore it's use
+ *     // group exists or return policy == continue
  * } else {
- *     // even if group doesn't exist we continue
+ *     // group doesn't exist and we ignore this request
  * }
  * @endcode
+ *
+ * An additional requirement is that the template parameter Data must
+ * have an operator<< defined for stream output.
  *
  * By changing the ActionPolicy implementation we choose debugging operation.
  * By choosing the ReturnPolicy implementation we choose whether to allow
/**
 * @file ActionPolicies.h
 * @b Policy @b Actions
 * The policy actions all have the same signature and can be
 * interchanged to alter what other policies do when they encounter an
 * error condition.
 *
 * @author Allan Rae <[EMAIL PROTECTED]>
 */
#ifndef ACTION_POLICIES_H
#define ACTION_POLICIES_H

/**
 * Attempt to carry on even though the assertion was false.
 * Implementation of ReturnPolicy.
 */
struct Continue
{
        bool operator() (bool) {
                return true;
        }
};


/**
 * Implementation of ReturnPolicy.
 */
struct Ignore
{
        bool operator() (bool a) {
                return a;
        }
};


/// The default Continue/Ignore policy
typedef struct Ignore ReturnPolicy;


/**
 * The @a assertion expression is asserted but no other parameters are used.
 * This is an implementation of the ActionPolicy class.
 */
template <class Data = int, class RT = ReturnPolicy>
struct AssertPolicy
{
        bool operator() (bool assertion, string const &,  Data const &) {
                Assert(assertion);
                return RT()(assertion);
        };
};


/**
 * A message, @a msg, is output to lyxerr along with the @a data. 
 * This is an implementation of the ActionPolicy class.
 */
template <class Data = int, class RT = ReturnPolicy>
struct LyXErrPolicy
{
        bool operator() (bool a, string const & msg, Data const & data) {
                if (!a) {
                        lyxerr << msg << data << endl;
                }
                return RT()(a);
        }
};


/**
 * Inputs are ignored, no output, and execution continues
 * This is an implementation of the ActionPolicy class.
 */
template <class Data = int, class RT = ReturnPolicy>
struct DoNothingPolicy
{
        bool operator() (bool a, string const &, Data const &) {
                return RT()(a);
        }
};


/// I need a better idea for this.
#define ActionPolicy AssertPolicy

#endif

Reply via email to