]> git.lyx.org Git - features.git/commitdiff
remove casts add consts to ButtonPolicy
authorLars Gullik Bjønnes <larsbj@gullik.org>
Thu, 31 Aug 2000 13:54:03 +0000 (13:54 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Thu, 31 Aug 2000 13:54:03 +0000 (13:54 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@995 a592a061-630c-0410-9148-cb99ea01b6c8

ChangeLog
src/frontends/ButtonPolicies.C
src/frontends/ButtonPolicies.h

index 6951623b1a4c99cb3c88c169ab68c17deb9bd392..fa29d0ff07a960535ff48faf461d3cf434ac646c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2000-08-31  Lars Gullik Bjønnes  <larsbj@lyx.org>
+
+       * src/frontends/ButtonPolicies.h: add a Button AllButtons.
+       make buttonStatus and isReadOnly be const methods. (also reflect
+       this in derived classes.)
+
+       * src/frontends/ButtonPolicies.C: remove sum_ and bogus_
+       (nextState): change to be static inline, pass the StateMachine as
+       a const reference
+       (PreferencesPolicy): remove casts
+       (OkCancelPolicy): remvoe casts
+       (OkCancelReadOnlyPolicy): remove casts
+       (NoRepeatedApplyReadOnlyPolicy): remove casts
+       (OkApplyCancelReadOnlyPolicy): remove casts
+       (OkApplyCancelPolicy): remove casts
+       (NoRepeatedApplyPolicy): remove casts
+
 2000-08-31  Angus Leeming  <a.leeming@ic.ac.uk>
 
        * src/converter.C: added some using directives
index 46952e3e1180bf6c1f8acfc28e4cc8d97317dd33..585a5e4270d3a1d5ddc7db6d18fb318e3521237f 100644 (file)
  */
 
 #include <config.h>
+
 #include "ButtonPolicies.h"
 #include "debug.h"
 
-// These shenanigans needed or DEC c++ complains that expression must
-// be an lvalue
-static const int sum_ = ( PreferencesPolicy::OKAY |
-                         PreferencesPolicy::APPLY |
-                         PreferencesPolicy::CANCEL |
-                         PreferencesPolicy::UNDO_ALL );
-static const PreferencesPolicy::State bogus_ = PreferencesPolicy::BOGUS;
 
-// Helper function
-inline void nextState(ButtonPolicy::State & state,
+/// Helper function
+static inline
+void nextState(ButtonPolicy::State & state,
               ButtonPolicy::SMInput in,
-              ButtonPolicy::StateMachine s_m,
+              ButtonPolicy::StateMachine const & s_m,
               char const * function_name = "nextState")
 {
        ButtonPolicy::State tmp = s_m[state][in];
@@ -53,11 +48,9 @@ inline void nextState(ButtonPolicy::State & state,
 
 PreferencesPolicy::PreferencesPolicy()
        : state_(INITIAL),
-         outputs_(APPLIED+1,
-                  static_cast<int const &>( sum_ )),
-         state_machine_(APPLIED+1,
-                        StateArray(SMI_TOTAL,
-                                   static_cast<State const &>( bogus_ )))
+         outputs_(APPLIED + 1, PreferencesPolicy::AllButtons),
+         state_machine_(APPLIED + 1,
+                        StateArray(SMI_TOTAL, PreferencesPolicy::BOGUS))
 {
        // Build the state output map
        outputs_[INITIAL] = CLOSE;
@@ -128,11 +121,9 @@ void PreferencesPolicy::input(SMInput input)
 
 OkCancelPolicy::OkCancelPolicy()
        : state_(INITIAL),
-         outputs_(INVALID+1,
-                  static_cast<int const &>( sum_ )),
-         state_machine_(INVALID+1, 
-                        StateArray(SMI_TOTAL,
-                                   static_cast<State const &>( bogus_ )))
+         outputs_(INVALID + 1, PreferencesPolicy::AllButtons),
+         state_machine_(INVALID + 1,
+                        StateArray(SMI_TOTAL, PreferencesPolicy::BOGUS))
 {
        // Build the state output map
        outputs_[INITIAL] = CLOSE;
@@ -183,11 +174,9 @@ void OkCancelPolicy::input(SMInput input)
 
 OkCancelReadOnlyPolicy::OkCancelReadOnlyPolicy()
        : state_(INITIAL),
-         outputs_(RO_INVALID+1,
-                  static_cast<int const &>( sum_ )),
-         state_machine_(RO_INVALID+1,
-                        StateArray(SMI_TOTAL,
-                                   static_cast<State const &>( bogus_ )))
+         outputs_(RO_INVALID + 1, PreferencesPolicy::AllButtons),
+         state_machine_(RO_INVALID + 1,
+                        StateArray(SMI_TOTAL, PreferencesPolicy::BOGUS))
 {
        // Build the state output map
        outputs_[INITIAL] = CLOSE;
@@ -260,11 +249,9 @@ void OkCancelReadOnlyPolicy::input(SMInput input)
 
 NoRepeatedApplyReadOnlyPolicy::NoRepeatedApplyReadOnlyPolicy()
        : state_(INITIAL),
-         outputs_(RO_INVALID+1,
-                  static_cast<int const &>( sum_ )),
-         state_machine_(RO_INVALID+1,
-                        StateArray(SMI_TOTAL,
-                                   static_cast<State const &>( bogus_ )))
+         outputs_(RO_INVALID + 1, PreferencesPolicy::AllButtons),
+         state_machine_(RO_INVALID + 1,
+                        StateArray(SMI_TOTAL, PreferencesPolicy::BOGUS))
 {
        // Build the state output map
        outputs_[INITIAL] = CLOSE;
@@ -338,11 +325,9 @@ void NoRepeatedApplyReadOnlyPolicy::input(SMInput input)
 
 OkApplyCancelReadOnlyPolicy::OkApplyCancelReadOnlyPolicy()
        : state_(INITIAL),
-         outputs_(RO_APPLIED+1,
-                  static_cast<int const &>( sum_ )),
-         state_machine_(RO_APPLIED+1,
-                        StateArray(SMI_TOTAL,
-                                   static_cast<State const &>( bogus_ )))
+         outputs_(RO_APPLIED + 1, PreferencesPolicy::AllButtons),
+         state_machine_(RO_APPLIED + 1,
+                        StateArray(SMI_TOTAL, PreferencesPolicy::BOGUS))
 {
        // Build the state output map
        outputs_[INITIAL] = CLOSE;
@@ -430,11 +415,9 @@ void OkApplyCancelReadOnlyPolicy::input(SMInput input)
 
 OkApplyCancelPolicy::OkApplyCancelPolicy()
        : state_(INITIAL),
-         outputs_(APPLIED+1,
-                  static_cast<int const &>( sum_ )),
-         state_machine_(APPLIED+1,
-                        StateArray(SMI_TOTAL,
-                                   static_cast<State const &>( bogus_ )))
+         outputs_(APPLIED + 1, PreferencesPolicy::AllButtons),
+         state_machine_(APPLIED + 1,
+                        StateArray(SMI_TOTAL, PreferencesPolicy::BOGUS))
 {
        // Build the state output map
        outputs_[INITIAL] = CLOSE;
@@ -496,11 +479,9 @@ void OkApplyCancelPolicy::input(SMInput input)
 
 NoRepeatedApplyPolicy::NoRepeatedApplyPolicy()
        : state_(INITIAL),
-         outputs_(INVALID+1,
-                  static_cast<int const &>( sum_ )),
-         state_machine_(INVALID+1,
-                        StateArray(SMI_TOTAL,
-                                   static_cast<State const &>( bogus_ )))
+         outputs_(INVALID + 1, PreferencesPolicy::AllButtons),
+         state_machine_(INVALID + 1,
+                        StateArray(SMI_TOTAL, PreferencesPolicy::BOGUS))
 {
        // Build the state output map
        outputs_[INITIAL] = CLOSE;
index 29a7483792eb680f59a96fc77e128b17792a3358..40aed42457d76d385449936517159a9405052e4f 100644 (file)
        button is actually a Save button -- its always reasonable to Save the
        preferences if the dialog has changed since the last save.
  */
-class ButtonPolicy : public noncopyable
-{
+class ButtonPolicy : public noncopyable {
 public:
-       /**@name Constructors and Deconstructors */
-       //@{
        ///
        virtual ~ButtonPolicy() {}
-       //@}
 
-       /**@name Enums */
-       //@{
        /** The various possible state names.
            Not all state-machines have this many states.  However, we need
            to define them all here so we can share the code.
        */
        enum State {
+               ///
                INITIAL = 0,
+               ///
                VALID,
+               ///
                INVALID,
+               ///
                APPLIED,
+               ///
                RO_INITIAL,
+               ///
                RO_VALID,
+               ///
                RO_INVALID,
+               ///
                RO_APPLIED,
+               ///
                BOGUS = 55
        };
+       
        /// The various button types.
        enum Button {
+               ///
                CLOSE    = 0,  // Not a real button, but effectively !CANCEL
+               ///
                OKAY     = 1,
+               ///
                APPLY    = 2,
+               ///
                CANCEL   = 4,
+               ///
                UNDO_ALL = 8
        };
+       ///
+       static const Button AllButtons =
+       Button(OKAY | APPLY | CANCEL | UNDO_ALL);
+       
        /** State machine inputs.
            All the policies so far have both CANCEL and HIDE always going to
            INITIAL. This won't necessarily be true for all [future] policies
@@ -105,57 +118,59 @@ public:
            HIDE are treated differently.
         */
        enum SMInput {
+               ///
                SMI_VALID = 0,
+               ///
                SMI_INVALID,
+               ///
                SMI_OKAY,
+               ///
                SMI_APPLY,
+               ///
                SMI_CANCEL,
+               ///
                SMI_UNDO_ALL,
+               ///
                SMI_HIDE,
+               ///
                SMI_READ_ONLY,
+               ///
                SMI_READ_WRITE,
+               ///
                SMI_TOTAL       // not a real input
        };
-       //@}
 
-       /**@name Access Functions */
-       //@{
        /// Trigger a transition with this input.
        virtual void input(SMInput) = 0;
        /// Activation status of a button
-       virtual bool buttonStatus(Button) = 0;
+       virtual bool buttonStatus(Button) const = 0;
        /// Are we in a read-only state?
-       virtual bool isReadOnly() = 0;
-       //@}
+       virtual bool isReadOnly() const = 0;
 
-       /**@name Typedefs */
-       //@{
        /// Transition map of the state machine.
        typedef std::vector<State> StateArray;
+       ///
        typedef std::vector<StateArray> StateMachine;
        /// The state outputs are the status of the buttons.
        typedef std::vector<int> StateOutputs;
-       //@}
 };
 
 
-//--------------------- Actual Policy Classes ----------------------------------
+//--------------------- Actual Policy Classes -----------------------------
 
 /** Ok and Cancel buttons for dialogs with read-only operation.
-    Note: This scheme supports the relabelling of Cancel to Close and vice versa.
+    Note: This scheme supports the relabelling of Cancel to Close and
+    vice versa.
     This is based on the value of the bool state of the Button::CANCEL.
     true == Cancel, false == Close
  */
-class OkCancelPolicy : public ButtonPolicy
-{
+class OkCancelPolicy : public ButtonPolicy {
 public:
        ///
        OkCancelPolicy();
        ///
        virtual ~OkCancelPolicy() {}
        
-       /**@name Access Functions */
-       //@{
        /// Trigger a transition with this input.
        virtual void input(SMInput);
        /** Activation status of a button.
@@ -165,22 +180,20 @@ public:
            the outputs_ variable.  Perhaps we can do something at compile
            time to check that all the states have corresponding outputs.
         */
-       virtual bool buttonStatus(Button button)
-               { return button & outputs_[state_]; }
+       virtual bool buttonStatus(Button button) const {
+               return button & outputs_[state_];
+       }
        /// Are we in a read-only state?
-       virtual bool isReadOnly()
-               { return false; }
-       //@}
+       virtual bool isReadOnly() const {
+               return false;
+       }
 private:
-       /**@name Private Data Members */
-       //@{
        /// Current state.
        State state_;
        /// Which buttons are active for a given state.
        StateOutputs outputs_;
        ///
        StateMachine state_machine_;
-       //@}
 };
 
 
@@ -193,40 +206,33 @@ private:
     This is based on the value of the bool state of the Button::CANCEL.
     true == Cancel, false == Close
  */
-class OkCancelReadOnlyPolicy : public ButtonPolicy
-{
+class OkCancelReadOnlyPolicy : public ButtonPolicy {
 public:
        ///
        OkCancelReadOnlyPolicy();
        ///
        virtual ~OkCancelReadOnlyPolicy() {}
        
-       /**@name Access Functions */
-       //@{
        /// Trigger a transition with this input.
        virtual void input(SMInput);
        /// Activation status of a button.
-       virtual bool buttonStatus(Button button)
-               { return button & outputs_[state_]; }
+       virtual bool buttonStatus(Button button) const {
+               return button & outputs_[state_];
+       }
        /// Are we in a read-only state?
-       virtual bool isReadOnly()
-               {
-                       return RO_INITIAL == state_
-                               || RO_VALID == state_
-                               || RO_INVALID == state_
-                               || RO_APPLIED == state_;
-               }
-       //@}
+       virtual bool isReadOnly() const {
+               return RO_INITIAL == state_
+                       || RO_VALID == state_
+                       || RO_INVALID == state_
+                       || RO_APPLIED == state_;
+       }
 private:
-       /**@name Private Data Members */
-       //@{
        /// Current state.
        State state_;
        /// Which buttons are active for a given state.
        StateOutputs outputs_;
        ///
        StateMachine state_machine_;
-       //@}
 };
 
 
@@ -251,32 +257,26 @@ public:
        ///
        virtual ~NoRepeatedApplyReadOnlyPolicy() {}
        
-       /**@name Access Functions */
-       //@{
        /// Trigger a transition with this input.
        virtual void input(SMInput);
        /// Activation status of a button.
-       virtual bool buttonStatus(Button button)
-               { return button & outputs_[state_]; }
+       virtual bool buttonStatus(Button button) const {
+               return button & outputs_[state_];
+       }
        /// Are we in a read-only state?
-       virtual bool isReadOnly()
-               {
-                       return RO_INITIAL == state_
-                               || RO_VALID == state_
-                               || RO_INVALID == state_
-                               || RO_APPLIED == state_;
-               }
-       //@}
+       virtual bool isReadOnly() const {
+               return RO_INITIAL == state_
+                       || RO_VALID == state_
+                       || RO_INVALID == state_
+                       || RO_APPLIED == state_;
+       }
 private:
-       /**@name Private Data Members */
-       //@{
        /// Current state.
        State state_;
        /// Which buttons are active for a given state.
        StateOutputs outputs_;
        ///
        StateMachine state_machine_;
-       //@}
 };
 
 
@@ -291,40 +291,33 @@ private:
     This is based on the value of the bool state of the Button::CANCEL.
     true == Cancel, false == Close
  */
-class OkApplyCancelReadOnlyPolicy : public ButtonPolicy
-{
+class OkApplyCancelReadOnlyPolicy : public ButtonPolicy {
 public:
        ///
        OkApplyCancelReadOnlyPolicy();
        ///
        virtual ~OkApplyCancelReadOnlyPolicy() {}
        
-       /**@name Access Functions */
-       //@{
        /// Trigger a transition with this input.
        virtual void input(SMInput);
        /// Activation status of a button.
-       virtual bool buttonStatus(Button button)
-               { return button & outputs_[state_]; }
+       virtual bool buttonStatus(Button button) const {
+               return button & outputs_[state_];
+       }
        /// Are we in a read-only state?
-       virtual bool isReadOnly()
-               {
-                       return RO_INITIAL == state_
-                               || RO_VALID == state_
-                               || RO_INVALID == state_
-                               || RO_APPLIED == state_;
-               }
-       //@}
+       virtual bool isReadOnly() const {
+               return RO_INITIAL == state_
+                       || RO_VALID == state_
+                       || RO_INVALID == state_
+                       || RO_APPLIED == state_;
+       }
 private:
-       /**@name Private Data Members */
-       //@{
        /// Current state.
        State state_;
        /// Which buttons are active for a given state.
        StateOutputs outputs_;
        ///
        StateMachine state_machine_;
-       //@}
 };
 
 
@@ -333,35 +326,30 @@ private:
     This is based on the value of the bool state of the Button::CANCEL.
     true == Cancel, false == Close
  */
-class OkApplyCancelPolicy : public ButtonPolicy
-{
+class OkApplyCancelPolicy : public ButtonPolicy {
 public:
        ///
        OkApplyCancelPolicy();
        ///
        virtual ~OkApplyCancelPolicy() {}
        
-       /**@name Access Functions */
-       //@{
        /// Trigger a transition with this input.
        virtual void input(SMInput);
        /// Activation status of a button.
-       virtual bool buttonStatus(Button button)
-               { return button & outputs_[state_]; }
+       virtual bool buttonStatus(Button button) const {
+               return button & outputs_[state_];
+       }
        /// Are we in a read-only state?
-       virtual bool isReadOnly()
-               { return false; }
-       //@}
+       virtual bool isReadOnly() const {
+               return false;
+       }
 private:
-       /**@name Private Data Members */
-       //@{
        /// Current state.
        State state_;
        /// Which buttons are active for a given state.
        StateOutputs outputs_;
        ///
        StateMachine state_machine_;
-       //@}
 };
 
 
@@ -370,35 +358,30 @@ private:
     This is based on the value of the bool state of the Button::CANCEL.
     true == Cancel, false == Close
  */
-class NoRepeatedApplyPolicy : public ButtonPolicy
-{
+class NoRepeatedApplyPolicy : public ButtonPolicy {
 public:
        ///
        NoRepeatedApplyPolicy();
        ///
        virtual ~NoRepeatedApplyPolicy() {}
        
-       /**@name Access Functions */
-       //@{
        /// Trigger a transition with this input.
        virtual void input(SMInput);
        /// Activation status of a button.
-       virtual bool buttonStatus(Button button)
-               { return button & outputs_[state_]; }
+       virtual bool buttonStatus(Button button) const {
+               return button & outputs_[state_];
+       }
        /// Are we in a read-only state?
-       virtual bool isReadOnly()
-               { return false; }
-       //@}
+       virtual bool isReadOnly() const {
+               return false;
+       }
 private:
-       /**@name Private Data Members */
-       //@{
        /// Current state.
        State state_;
        /// Which buttons are active for a given state.
        StateOutputs outputs_;
        ///
        StateMachine state_machine_;
-       //@}
 };
 
 
@@ -408,35 +391,30 @@ private:
     This is based on the value of the bool state of the Button::CANCEL.
     true == Cancel, false == Close
  */
-class PreferencesPolicy : public ButtonPolicy
-{
+class PreferencesPolicy : public ButtonPolicy {
 public:
        ///
        PreferencesPolicy();
        ///
        virtual ~PreferencesPolicy() {}
        
-       /**@name Access Functions */
-       //@{
        /// Trigger a transition with this input.
        virtual void input(SMInput);
        /// Activation status of a button.
-       virtual bool buttonStatus(Button button)
-               { return button & outputs_[state_]; }
+       virtual bool buttonStatus(Button button) const {
+               return button & outputs_[state_];
+       }
        /// Are we in a read-only state?
-       virtual bool isReadOnly()
-               { return false; }
-       //@}
+       virtual bool isReadOnly() const {
+               return false;
+       }
 private:
-       /**@name Private Data Members */
-       //@{
        /// Current state.
        State state_;
        /// Which buttons are active for a given state.
        StateOutputs outputs_;
        ///
        StateMachine state_machine_;
-       //@}
 };
 
 #endif