[dasher] * Made SConversionData protected in CConversionManager



commit a49623b78f6115ae1ca1af160faa0d12da87c9d3
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date:   Mon Nov 16 09:44:53 2009 +0100

    * Made SConversionData protected in CConversionManager
    * Bypassed by making CMandarinAlphMgr a friend of CPinYinConversionHelper
      ...and statically casting :-(
    * Made SAlphabetData protected in CAlphabetManager
    * Made CControlNode into a private struct, now SControlItem, in CControlManager
    * GC'd various methods

 ChangeLog                                 |   12 +++++++++++-
 Src/DasherCore/AlphabetManager.h          |    2 +-
 Src/DasherCore/ControlManager.cpp         |   22 +++++++++++-----------
 Src/DasherCore/ControlManager.h           |   17 ++++++++---------
 Src/DasherCore/ConversionHelper.cpp       |    2 +-
 Src/DasherCore/ConversionManager.cpp      |    2 +-
 Src/DasherCore/ConversionManager.h        |   21 +--------------------
 Src/DasherCore/DasherNode.cpp             |   10 ----------
 Src/DasherCore/DasherNode.h               |   12 +-----------
 Src/DasherCore/MandarinAlphMgr.cpp        |    9 ++++++---
 Src/DasherCore/NodeManager.h              |    4 ++--
 Src/DasherCore/PinYinConversionHelper.cpp |    8 ++++++++
 Src/DasherCore/PinYinConversionHelper.h   |    7 ++++++-
 13 files changed, 57 insertions(+), 71 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 32edfa5..dea52c6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,14 @@
-2009-08-22  Alan Lawrence <acl33 inf phy cam ac uk>
+2009-11-16  Alan Lawrence <acl33 inf phy cam ac uk>
+
+	 * Made SConversionData protected in CConversionManager
+	 * Bypassed by making CMandarinAlphMgr a friend of
+	   CPinYinConversionHelper ...and statically casting :-(
+	 * Made SAlphabetData protected in CAlphabetManager
+	 * Made CControlNode into a private struct, now SControlItem, in
+	   CControlManager
+	 * GC'd various methods
+
+2009-10-21  Alan Lawrence <acl33 inf phy cam ac uk>
 
 	This is what commit
 		05c615e8e6eb19c2bf189b44e3688afef5dc3926 Fixup Chinese BuildTree
diff --git a/Src/DasherCore/AlphabetManager.h b/Src/DasherCore/AlphabetManager.h
index d470915..526dd8f 100644
--- a/Src/DasherCore/AlphabetManager.h
+++ b/Src/DasherCore/AlphabetManager.h
@@ -91,6 +91,7 @@ namespace Dasher {
     virtual CLanguageModel::Context CloneAlphContext(CDasherNode *pNode, CLanguageModel *pLanguageModel);
     virtual symbol GetAlphSymbol(CDasherNode *pNode);
     
+  protected:
     struct SAlphabetData {
       symbol iSymbol;
       int iPhase;
@@ -100,7 +101,6 @@ namespace Dasher {
       int iGameOffset;
     };
 
-  protected:
 	virtual CDasherNode *CreateSymbolNode(CDasherNode *pParent, symbol iSymbol, unsigned int iLbnd, unsigned int iHbnd, symbol iExistingSymbol, CDasherNode *pExistingChild);
     virtual CLanguageModel::Context CreateSymbolContext(SAlphabetData *pParentData, symbol iSymbol);
 
diff --git a/Src/DasherCore/ControlManager.cpp b/Src/DasherCore/ControlManager.cpp
index a769ab8..8bec529 100644
--- a/Src/DasherCore/ControlManager.cpp
+++ b/Src/DasherCore/ControlManager.cpp
@@ -224,8 +224,8 @@ int CControlManager::ConnectNodes() {
 
 CControlManager::~CControlManager()
 {
-  for(std::map<int,CControlNode*>::iterator i = m_mapControlMap.begin(); i != m_mapControlMap.end(); i++) {
-    CControlNode* pNewNode = i->second;
+  for(std::map<int,SControlItem*>::iterator i = m_mapControlMap.begin(); i != m_mapControlMap.end(); i++) {
+    SControlItem* pNewNode = i->second;
     if (pNewNode != NULL) {
       delete pNewNode;
       pNewNode = NULL;
@@ -234,9 +234,9 @@ CControlManager::~CControlManager()
 }
 
 void CControlManager::RegisterNode( int iID, std::string strLabel, int iColour ) {
-  CControlNode *pNewNode;
+  SControlItem *pNewNode;
   
-  pNewNode = new CControlNode; // FIXME - do constructor sanely
+  pNewNode = new SControlItem; // FIXME - do constructor sanely
   pNewNode->strLabel = strLabel;
   pNewNode->iID = iID;
   pNewNode->iColour = iColour;
@@ -249,7 +249,7 @@ void CControlManager::ConnectNode(int iChild, int iParent, int iAfter) {
   // FIXME - iAfter currently ignored (eventually -1 = start, -2 = end)
 
   if( iChild == -1 ) {// Corresponds to escaping back to alphabet
-    CControlNode* node = m_mapControlMap[iParent];
+    SControlItem* node = m_mapControlMap[iParent];
     if(node)
       node->vChildren.push_back(NULL);
   }
@@ -258,10 +258,10 @@ void CControlManager::ConnectNode(int iChild, int iParent, int iAfter) {
 }
 
 void CControlManager::DisconnectNode(int iChild, int iParent) {
-  CControlNode* pParentNode = m_mapControlMap[iParent];
-  CControlNode* pChildNode = m_mapControlMap[iChild];
+  SControlItem* pParentNode = m_mapControlMap[iParent];
+  SControlItem* pChildNode = m_mapControlMap[iChild];
 
-  for(std::vector<CControlNode *>::iterator itChild(pParentNode->vChildren.begin()); itChild != pParentNode->vChildren.end(); ++itChild)
+  for(std::vector<SControlItem *>::iterator itChild(pParentNode->vChildren.begin()); itChild != pParentNode->vChildren.end(); ++itChild)
     if(*itChild == pChildNode)
       pParentNode->vChildren.erase(itChild);
 }
@@ -295,13 +295,13 @@ void CControlManager::PopulateChildren( CDasherNode *pNode ) {
   
   CDasherNode *pNewNode;
 
-   CControlNode *pControlNode(static_cast<CControlNode *>(pNode->m_pUserData));
+   SControlItem *pControlNode(static_cast<SControlItem *>(pNode->m_pUserData));
 
    int iNChildren( pControlNode->vChildren.size() );
 
    int iIdx(0);
 
-   for(std::vector<CControlNode *>::iterator it(pControlNode->vChildren.begin()); it != pControlNode->vChildren.end(); ++it) {
+   for(std::vector<SControlItem *>::iterator it(pControlNode->vChildren.begin()); it != pControlNode->vChildren.end(); ++it) {
 
      // FIXME - could do this better
 
@@ -344,7 +344,7 @@ void CControlManager::ClearNode( CDasherNode *pNode ) {
 
 void CControlManager::Output( CDasherNode *pNode, Dasher::VECTOR_SYMBOL_PROB* pAdded, int iNormalization ) {
 
-  CControlNode *pControlNode(static_cast<CControlNode *>(pNode->m_pUserData));
+  SControlItem *pControlNode(static_cast<SControlItem *>(pNode->m_pUserData));
 
   CControlEvent oEvent(pControlNode->iID);
   // TODO: Need to reimplement this
diff --git a/Src/DasherCore/ControlManager.h b/Src/DasherCore/ControlManager.h
index 172f112..07d455d 100644
--- a/Src/DasherCore/ControlManager.h
+++ b/Src/DasherCore/ControlManager.h
@@ -56,14 +56,6 @@ namespace Dasher {
   class CControlManager : public CNodeManager {
   public:
 
-    class CControlNode {
-    public: // Worry about encapsulation later
-      std::vector<CControlNode *> vChildren;
-      std::string strLabel;
-      int iID;
-      int iColour;
-    };
-
     enum { CTL_ROOT, CTL_STOP, CTL_PAUSE, CTL_MOVE, CTL_MOVE_FORWARD, 
 	   CTL_MOVE_FORWARD_CHAR, CTL_MOVE_FORWARD_WORD, CTL_MOVE_FORWARD_LINE,
 	   CTL_MOVE_FORWARD_FILE, CTL_MOVE_BACKWARD, CTL_MOVE_BACKWARD_CHAR, 
@@ -122,6 +114,13 @@ namespace Dasher {
 
   private:
 
+    struct SControlItem {
+      std::vector<SControlItem *> vChildren;
+      std::string strLabel;
+      int iID;
+      int iColour;
+    };
+    
     static void XmlStartHandler(void *pUserData, const XML_Char *szName, const XML_Char **aszAttr);
     static void XmlEndHandler(void *pUserData, const XML_Char *szName);
     static void XmlCDataHandler(void *pUserData, const XML_Char *szData, int iLength);
@@ -133,7 +132,7 @@ namespace Dasher {
     static int m_iNextID;
     CNodeCreationManager *m_pNCManager;
     CLanguageModel *m_pLanguageModel;
-    std::map<int,CControlNode*> m_mapControlMap;
+    std::map<int,SControlItem*> m_mapControlMap;
 
     ///Whether we'd temporarily disabled Automatic Speed Control
     ///(if _and only if_ so, should re-enable it when leaving a node)
diff --git a/Src/DasherCore/ConversionHelper.cpp b/Src/DasherCore/ConversionHelper.cpp
index 2fb6cd3..bf0f21e 100644
--- a/Src/DasherCore/ConversionHelper.cpp
+++ b/Src/DasherCore/ConversionHelper.cpp
@@ -258,7 +258,7 @@ void CConversionHelper::PopulateChildren( CDasherNode *pNode ) {
       // -----
 
       pNewNode->m_pNodeManager = this;
-      pNewNode->m_pNodeManager->Ref();
+      Ref();
 
       SConversionData *pNodeUserData = new SConversionData;
       pNodeUserData->bisRoot = false;
diff --git a/Src/DasherCore/ConversionManager.cpp b/Src/DasherCore/ConversionManager.cpp
index b2e9b2e..a7c0856 100644
--- a/Src/DasherCore/ConversionManager.cpp
+++ b/Src/DasherCore/ConversionManager.cpp
@@ -75,7 +75,7 @@ CDasherNode *CConversionManager::GetRoot(CDasherNode *pParent, int iLower, int i
   // -----
 
   pNewNode->m_pNodeManager = this;
-  pNewNode->m_pNodeManager->Ref();
+  Ref();
 
 
   SConversionData *pNodeUserData = new SConversionData;
diff --git a/Src/DasherCore/ConversionManager.h b/Src/DasherCore/ConversionManager.h
index c8e5572..aae9b75 100644
--- a/Src/DasherCore/ConversionManager.h
+++ b/Src/DasherCore/ConversionManager.h
@@ -117,26 +117,7 @@ namespace Dasher {
 
     virtual void Undo( CDasherNode *pNode );
 
-    ///
-    /// Entered backwards
-    ///
-
-    virtual void Enter(CDasherNode *pNode) {};
-
-    /// 
-    /// Left forwards
-    ///
-
-    virtual void Leave(CDasherNode *pNode) {};
-
-    ///
-    /// Rebuild the parent of a given node - used for when backoff occurs beyond the start of the tree
-    ///
-
-    virtual CDasherNode *RebuildParent(CDasherNode *pNode) {
-      return 0;
-    }
-
+  protected:
     //TODO: REVISE
     struct SConversionData {
       symbol iSymbol;
diff --git a/Src/DasherCore/DasherNode.cpp b/Src/DasherCore/DasherNode.cpp
index d1a920a..2f93fc3 100644
--- a/Src/DasherCore/DasherNode.cpp
+++ b/Src/DasherCore/DasherNode.cpp
@@ -181,16 +181,6 @@ double CDasherNode::GetProb(int iNormalization) {
   return (double) (m_iHbnd - m_iLbnd) / (double) iNormalization;
 }
 
-void CDasherNode::ConvertWithAncestors() {
-  if(GetFlag(NF_CONVERTED))
-    return;
-  
-  SetFlag(NF_CONVERTED, true);
-
-  if(m_pParent)
-    m_pParent->ConvertWithAncestors();
-}
-
 void CDasherNode::SetFlag(int iFlag, bool bValue) {
 
  if(bValue)
diff --git a/Src/DasherCore/DasherNode.h b/Src/DasherCore/DasherNode.h
index 586a782..d81ef02 100644
--- a/Src/DasherCore/DasherNode.h
+++ b/Src/DasherCore/DasherNode.h
@@ -85,7 +85,7 @@ class Dasher::CDasherNode:private NoClones {
 
   /// @brief Destructor
   ///
-  ~CDasherNode();
+  virtual ~CDasherNode();
 
   void Trace() const;           // diagnostic
 
@@ -130,16 +130,6 @@ class Dasher::CDasherNode:private NoClones {
   ///
   inline bool GetFlag(int iFlag) const;
 
-  /// @brief Recursively mark nodes as converted 
-  ///
-  /// Ensure that this node is marked as being converted, together with
-  /// all of its ancestors (assuming that unconverted nodes are
-  /// 'contiguous' at the brances of the tree).
-  ///
-  /// @todo replace with a generic 'recursive set flag'?
-  ///
-  void ConvertWithAncestors();
-
   /// @}
 
   /// @name Routines relating to the size of the node
diff --git a/Src/DasherCore/MandarinAlphMgr.cpp b/Src/DasherCore/MandarinAlphMgr.cpp
index dad5f93..042a19b 100644
--- a/Src/DasherCore/MandarinAlphMgr.cpp
+++ b/Src/DasherCore/MandarinAlphMgr.cpp
@@ -21,6 +21,7 @@
 #include "../Common/Common.h"
 
 #include "MandarinAlphMgr.h"
+#include "PinYinConversionHelper.h"
 #include "ConversionManager.h"
 #include "DasherInterfaceBase.h"
 #include "DasherNode.h"
@@ -56,8 +57,10 @@ CDasherNode *CMandarinAlphMgr::GetRoot(CDasherNode *pParent, int iLower, int iUp
 
   //Override context for Mandarin Dasher
   if (pParent){
-    CConversionManager::SConversionData *pParentConversionData = static_cast<CConversionManager::SConversionData *>(pParent->m_pUserData);
-    pNodeUserData->iContext = m_pLanguageModel->CloneContext(pParentConversionData->iContext);
+    CPinYinConversionHelper *pMgr = static_cast<CPinYinConversionHelper *>(pParent->m_pNodeManager);
+    //ACL think this is how this Mandarin thing works here...
+    // but would be nice if I could ASSERT that that cast is ok!
+    pNodeUserData->iContext = m_pLanguageModel->CloneContext(pMgr->GetConvContext(pParent));
   }
   else
 	pNodeUserData->iContext = m_pLanguageModel->CreateEmptyContext();
@@ -71,7 +74,7 @@ CDasherNode *CMandarinAlphMgr::CreateSymbolNode(CDasherNode *pParent, symbol iSy
     //Modified for Mandarin Dasher
     //The following logic switch allows punctuation nodes in Mandarin to be treated in the same way as English (i.e. display and populate next round) instead of invoking a conversion node
 	  CDasherNode *pNewNode = m_pNCManager->GetConvRoot(pParent, iLbnd, iHbnd, pParent->m_iOffset);
-	  static_cast<CConversionManager::SConversionData *>(pNewNode->m_pUserData)->iSymbol = iSymbol;
+	  static_cast<CPinYinConversionHelper *>(pNewNode->m_pNodeManager)->SetConvSymbol(pNewNode, iSymbol);
 	  return pNewNode;
   }
   return CAlphabetManager::CreateSymbolNode(pParent, iSymbol, iLbnd, iHbnd, iExistingSymbol, pExistingChild);
diff --git a/Src/DasherCore/NodeManager.h b/Src/DasherCore/NodeManager.h
index c9221c6..be76cdb 100644
--- a/Src/DasherCore/NodeManager.h
+++ b/Src/DasherCore/NodeManager.h
@@ -71,8 +71,8 @@ namespace Dasher {
     };
     
     /// Increment reference count
-    ///
-    virtual void Ref() = 0;
+    /// ACL 12/8/09 Never called polymorphically, so removing.
+    //virtual void Ref() = 0;
     
     /// Decrement reference count
     ///
diff --git a/Src/DasherCore/PinYinConversionHelper.cpp b/Src/DasherCore/PinYinConversionHelper.cpp
index 82abdc4..c705a29 100644
--- a/Src/DasherCore/PinYinConversionHelper.cpp
+++ b/Src/DasherCore/PinYinConversionHelper.cpp
@@ -260,3 +260,11 @@ void CPinYinConversionHelper::SetFlag(CDasherNode *pNode, int iFlag, bool bValue
 	if (iFlag == NF_COMMITTED && bValue) return;
 	CConversionHelper::SetFlag(pNode, iFlag, bValue);
 }
+
+CLanguageModel::Context CPinYinConversionHelper::GetConvContext(CDasherNode *pNode) {
+  return static_cast<SConversionData *>(pNode->m_pUserData)->iContext;
+}
+
+void CPinYinConversionHelper::SetConvSymbol(CDasherNode *pNode, int iSymbol) {
+  static_cast<SConversionData *> (pNode->m_pUserData)->iSymbol = iSymbol;
+}
diff --git a/Src/DasherCore/PinYinConversionHelper.h b/Src/DasherCore/PinYinConversionHelper.h
index 4608a22..e5e9cca 100644
--- a/Src/DasherCore/PinYinConversionHelper.h
+++ b/Src/DasherCore/PinYinConversionHelper.h
@@ -16,6 +16,7 @@
 namespace Dasher {
 
 class CPinYinConversionHelper : public CConversionHelper {
+  friend class CMandarinAlphMgr;
  public:
 
   CPinYinConversionHelper(CNodeCreationManager *pNCManager, Dasher::CEventHandler *pEventHandler,  CSettingsStore *pSettingsStore, Dasher::CAlphIO *pAlphIO, const std::string strCHAlphabetPath, Dasher::CAlphabet * pAlphabet);
@@ -38,7 +39,11 @@ class CPinYinConversionHelper : public CConversionHelper {
   virtual void SetFlag(CDasherNode *pNode, int iFlag, bool bValue);
 	
  private:
-     
+  ///Bit of a hack here - these two need to be accessed by CMandarinAlphMgr :-(.
+  ///Seems neater to make MandarinAlphMgr a friend, than these public...
+  virtual CLanguageModel::Context GetConvContext(CDasherNode *pNode);
+  virtual void SetConvSymbol(CDasherNode *pNode, int iSymbol);
+
   void TrainChPPM(CSettingsStore *pSettingsStore);
   void ProcessFile(CSettingsStore *pSettingsStore, int index);
 



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