[dasher] Const-ify events, remove CCommandEvent



commit 0c3f4f0b23aa90417798e86b9e03bafa56d61ae5
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date:   Fri Feb 18 11:01:01 2011 +0000

    Const-ify events, remove CCommandEvent
    
    (preserve CDasherInterfaceBase::ExecuteCommand as no-op,
      override in Gtk2 to emit Gtk signal)

 Src/DasherCore/DasherInterfaceBase.cpp       |    9 ---
 Src/DasherCore/DasherInterfaceBase.h         |    6 ++-
 Src/DasherCore/Event.h                       |   71 +++++++++-----------------
 Src/DasherCore/FrameRate.cpp                 |    7 +--
 Src/Gtk2/DasherControl.cpp                   |    8 ++--
 Src/Gtk2/DasherControl.h                     |    3 +
 Src/MacOSX/COSXDasherControl.mm              |    3 -
 Src/iPhone/Classes/CDasherInterfaceBridge.mm |    3 -
 8 files changed, 39 insertions(+), 71 deletions(-)
---
diff --git a/Src/DasherCore/DasherInterfaceBase.cpp b/Src/DasherCore/DasherInterfaceBase.cpp
index 58c6890..c13d9d3 100644
--- a/Src/DasherCore/DasherInterfaceBase.cpp
+++ b/Src/DasherCore/DasherInterfaceBase.cpp
@@ -946,15 +946,6 @@ void CDasherInterfaceBase::HandleClickDown(int iTime, int iX, int iY) {
   KeyDown(iTime, 100, true, iX, iY);
 }
 
-
-void CDasherInterfaceBase::ExecuteCommand(const std::string &strName) {
-  // TODO: Pointless - just insert event directly
-
-  CCommandEvent *pEvent = new CCommandEvent(strName);
-  m_pEventHandler->InsertEvent(pEvent);
-  delete pEvent;
-}
-
 void CDasherInterfaceBase::AddActionButton(const std::string &strName) {
   m_vRightButtons.push_back(new CActionButton(this, strName, false));
 }
diff --git a/Src/DasherCore/DasherInterfaceBase.h b/Src/DasherCore/DasherInterfaceBase.h
index 21d9a91..62f3215 100644
--- a/Src/DasherCore/DasherInterfaceBase.h
+++ b/Src/DasherCore/DasherInterfaceBase.h
@@ -334,8 +334,10 @@ public:
   /// @name Action buttons
   /// TODO, how much of this was ever implemented???
   /// @{
-
-  void ExecuteCommand(const std::string &strName);
+  /// ACL in answer to previous: not much, not sure whether it's worth keeping anything;
+  /// but for now, I'm preserving this as overridable by subclasses which do want to handle
+  /// commands, so they can make it do something. The default implementation does nothing.
+  virtual void ExecuteCommand(const std::string &strName) {};
 
   void AddActionButton(const std::string &strName);
 
diff --git a/Src/DasherCore/Event.h b/Src/DasherCore/Event.h
index e171c10..6b109d4 100644
--- a/Src/DasherCore/Event.h
+++ b/Src/DasherCore/Event.h
@@ -14,11 +14,10 @@ namespace Dasher {
   class CControlEvent;
   class CLockEvent;
   class CMessageEvent;
-  class CCommandEvent;
 }
 
 enum {
-  EV_PARAM_NOTIFY = 1, EV_EDIT, EV_EDIT_CONTEXT, EV_CONTROL, EV_LOCK, EV_MESSAGE, EV_COMMAND
+  EV_PARAM_NOTIFY = 1, EV_EDIT, EV_EDIT_CONTEXT, EV_CONTROL, EV_LOCK, EV_MESSAGE
 };
 
 /// \ingroup Core
@@ -27,65 +26,58 @@ enum {
 /// \defgroup Events Events generated by Dasher modules.
 /// @{
 class Dasher::CEvent {
+protected:
+  CEvent(int iEventType) : m_iEventType(iEventType) {}
 public:
-  int m_iEventType;
+  const int m_iEventType;
 };
 
 class Dasher::CParameterNotificationEvent:public Dasher::CEvent {
 public:
-  CParameterNotificationEvent(int iParameter) {
-    m_iEventType = EV_PARAM_NOTIFY;
-    m_iParameter = iParameter;
+  CParameterNotificationEvent(int iParameter) : CEvent(EV_PARAM_NOTIFY), m_iParameter(iParameter) {
   };
 
-  int m_iParameter;
+  const int m_iParameter;
 };
 
 class Dasher::CEditEvent:public Dasher::CEvent {
 public:
-  CEditEvent(int iEditType, const std::string & sText, int iOffset) {
-    m_iEventType = EV_EDIT;
-    m_iEditType = iEditType;
-    m_sText = sText;
-    m_iOffset = iOffset;
+  CEditEvent(int iEditType, const std::string & sText, int iOffset)
+  : CEvent(EV_EDIT), m_iEditType(iEditType), m_sText(sText), m_iOffset(iOffset) {
   };
 
-  int m_iEditType;
-  std::string m_sText;
-  int m_iOffset;
+  const int m_iEditType;
+  const std::string m_sText;
+  const int m_iOffset;
 };
 
 class Dasher::CEditContextEvent:public Dasher::CEvent {
 public:
-  CEditContextEvent(int iOffset, int iLength) {
-    m_iEventType = EV_EDIT_CONTEXT;
-    m_iOffset = iOffset;
-    m_iLength = iLength;
+  CEditContextEvent(int iOffset, int iLength) : CEvent(EV_EDIT_CONTEXT), m_iOffset(iOffset), m_iLength(iLength) {
   };
 
-  int m_iOffset;
-  int m_iLength;
+  const int m_iOffset;
+  const int m_iLength;
 };
 
 class Dasher::CControlEvent:public Dasher::CEvent {
 public:
-  CControlEvent(int iID) {
-    m_iEventType = EV_CONTROL;
-    m_iID = iID;
+  CControlEvent(int iID) : CEvent(EV_CONTROL), m_iID(iID) {
   };
   
-  int m_iID;
+  const int m_iID;
 };
 
 class Dasher::CLockEvent : public Dasher::CEvent {
 public:
-  CLockEvent(const std::string &strMessage, bool bLock, int iPercent) {
-    m_iEventType = EV_LOCK;
+  CLockEvent(const std::string &strMessage, bool bLock, int iPercent) : CEvent(EV_LOCK) {
     m_strMessage = strMessage;
     m_bLock = bLock;
     m_iPercent = iPercent;
   };
-  
+
+  ///Unlike other events, fields are mutable: CLockEvents may be
+  /// reused at the start, end, and during, the task requiring locking.
   std::string m_strMessage;
   bool m_bLock;
   int m_iPercent;
@@ -93,26 +85,13 @@ public:
 
 class Dasher::CMessageEvent : public Dasher::CEvent {
 public:
-  CMessageEvent(const std::string &strMessage, int iID, int iType) {
-    m_iEventType = EV_MESSAGE;
-    m_strMessage = strMessage;
-    m_iID = iID;
-    m_iType = iType;
-  };
-  
-  std::string m_strMessage;
-  int m_iID;
-  int m_iType;
-};
-
-class Dasher::CCommandEvent : public Dasher::CEvent {
-public:
-  CCommandEvent(const std::string &strCommand) {
-    m_iEventType = EV_COMMAND;
-    m_strCommand = strCommand;
+  CMessageEvent(const std::string &strMessage, int iID, int iType)
+  : CEvent(EV_MESSAGE), m_strMessage(strMessage), m_iID(iID), m_iType(iType) {
   };
   
-  std::string m_strCommand;
+  const std::string m_strMessage;
+  const int m_iID;
+  const int m_iType;
 };
 /// @}
 /// @}
diff --git a/Src/DasherCore/FrameRate.cpp b/Src/DasherCore/FrameRate.cpp
index ff69c24..d5f0f3c 100644
--- a/Src/DasherCore/FrameRate.cpp
+++ b/Src/DasherCore/FrameRate.cpp
@@ -11,10 +11,9 @@ CFrameRate::CFrameRate(CEventHandler *pEventHandler, CSettingsStore *pSettingsSt
   m_iTime = 0;                  // Hmmm, User must reset framerate before starting.
 
   //try and carry on from where we left off at last run
-  CParameterNotificationEvent evt(LP_FRAMERATE);
-  HandleEvent(&evt);
-  evt.m_iParameter = LP_MAX_BITRATE;
-  HandleEvent(&evt); //calls UpdateSteps(), which sets m_dRXMax and m_iSteps
+  {CParameterNotificationEvent evt(LP_FRAMERATE); HandleEvent(&evt);}
+  {CParameterNotificationEvent evt(LP_MAX_BITRATE); HandleEvent(&evt);}
+  //calls UpdateSteps(), which sets m_dRXMax and m_iSteps
 }
 
 void CFrameRate::RecordFrame(unsigned long Time)
diff --git a/Src/Gtk2/DasherControl.cpp b/Src/Gtk2/DasherControl.cpp
index 74e1af4..45cda0f 100644
--- a/Src/Gtk2/DasherControl.cpp
+++ b/Src/Gtk2/DasherControl.cpp
@@ -376,12 +376,12 @@ void CDasherControl::ExternalEventHandler(Dasher::CEvent *pEvent) {
 
     g_signal_emit_by_name(GTK_WIDGET(m_pDasherControl), "dasher_message", &sInfo);
   }
-  else if(pEvent->m_iEventType == EV_COMMAND) {
-    CCommandEvent *pCommandEvent(static_cast<CCommandEvent *>(pEvent));
-    g_signal_emit_by_name(GTK_WIDGET(m_pDasherControl), "dasher_command", pCommandEvent->m_strCommand.c_str());
-  }
 };
 
+void CDasherControl::ExecuteCommand(const std::string &strCommand) {
+    g_signal_emit_by_name(GTK_WIDGET(m_pDasherControl), "dasher_command", strCommand.c_str());
+}
+
 void CDasherControl::WriteTrainFile(const std::string &strNewText) {
   if(strNewText.length() == 0)
     return;
diff --git a/Src/Gtk2/DasherControl.h b/Src/Gtk2/DasherControl.h
index e68a2a2..c91d19a 100644
--- a/Src/Gtk2/DasherControl.h
+++ b/Src/Gtk2/DasherControl.h
@@ -165,6 +165,9 @@ private:
 
   void ExternalEventHandler(Dasher::CEvent *pEvent);
   
+  /// Override to emit Gtk2 signals (previously in response to CCommandEvent)
+  void ExecuteCommand(const std::string &strName);
+
   void GameMessageOut(int message, const void* messagedata);
 
   ///
diff --git a/Src/MacOSX/COSXDasherControl.mm b/Src/MacOSX/COSXDasherControl.mm
index e61d3bd..b2d7a77 100644
--- a/Src/MacOSX/COSXDasherControl.mm
+++ b/Src/MacOSX/COSXDasherControl.mm
@@ -195,9 +195,6 @@ void COSXDasherControl::ExternalEventHandler(Dasher::CEvent *pEvent) {
 //      CLockEvent *lockEvent(static_cast < CLockEvent * >(pEvent));
 //      NSLog(@"ExternalEventHandler, m_iEventType = EV_LOCK, mess: %@, bLock = %d, pct = %d", NSStringFromStdString(lockEvent->m_strMessage), lockEvent->m_bLock, lockEvent->m_iPercent);
       break;
-    case EV_COMMAND:
-      NSLog(@"ExternalEventHandler, m_iEventType = EV_COMMAND");
-      break;
     case EV_MESSAGE: {
       CMessageEvent *messageEvent(static_cast < CMessageEvent * >(pEvent));
       NSLog(@"ExternalEventHandler, m_iEventType = EV_MESSAGE, mess: %@, id = %d, type = %d", NSStringFromStdString(messageEvent->m_strMessage), messageEvent->m_iID, messageEvent->m_iType);
diff --git a/Src/iPhone/Classes/CDasherInterfaceBridge.mm b/Src/iPhone/Classes/CDasherInterfaceBridge.mm
index 9271040..554c25a 100644
--- a/Src/iPhone/Classes/CDasherInterfaceBridge.mm
+++ b/Src/iPhone/Classes/CDasherInterfaceBridge.mm
@@ -222,9 +222,6 @@ void CDasherInterfaceBridge::ExternalEventHandler(Dasher::CEvent *pEvent) {
         [dasherApp del:EDIT_FILE forwards:NO]; break;
       }
       break;
-    case EV_COMMAND:
-      NSLog(@"ExternalEventHandler, m_iEventType = EV_COMMAND");
-      break;
     case EV_LOCK:
     {
       CLockEvent *evt(static_cast<CLockEvent *>(pEvent));



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]