[dasher] Modularise the NodeManager-subclass-specific void *'s
- From: Patrick Welche <pwelche src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [dasher] Modularise the NodeManager-subclass-specific void *'s
- Date: Mon, 24 Aug 2009 18:00:10 +0000 (UTC)
commit e0076a509e987067bffc09cb450fa5a33da6b15c
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date: Sat Aug 22 23:48:39 2009 +0100
Modularise the NodeManager-subclass-specific void *'s
Add virtual methods to support ConversionManager/ConversionHelper:
- cloning of parent alph node context
- accessing iSymbols of preceding alph nodes
(SConversionData *) ptrs no longer cast to (SAlphabetData *) to access iSymbol
(This was working at the time, as iSymbol was first field of both structs!)
ChangeLog | 7 +++++++
Src/DasherCore/AlphabetManager.cpp | 10 ++++++++++
Src/DasherCore/AlphabetManager.h | 3 +++
Src/DasherCore/ConversionHelper.cpp | 19 +++++++------------
Src/DasherCore/MandarinAlphMgr.cpp | 2 +-
Src/DasherCore/NodeManager.h | 12 +++++++++++-
Src/DasherCore/PinYinConversionHelper.cpp | 2 +-
7 files changed, 40 insertions(+), 15 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index c7c2c8d..399e9b3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2009-08-22 Alan Lawrence <acl33 inf phy cam ac uk>
+ * Modularise the NodeManager-subclass-specific void *'s
+ * Add virtual methods to support ConversionManager/ConversionHelper:
+ - cloning of parent alph node context
+ - accessing iSymbols of preceding alph nodes
+
+2009-08-22 Alan Lawrence <acl33 inf phy cam ac uk>
+
* Move iOffset field into DasherNode (now m_iOffset).
* Remove SControlData structure and use its single member directly.
* AlphabetManager.cpp: Move node creation outside of if statement.
diff --git a/Src/DasherCore/AlphabetManager.cpp b/Src/DasherCore/AlphabetManager.cpp
index ddd8eb7..4b4aa5c 100644
--- a/Src/DasherCore/AlphabetManager.cpp
+++ b/Src/DasherCore/AlphabetManager.cpp
@@ -138,6 +138,16 @@ bool CAlphabetManager::GameSearchNode(CDasherNode *pNode, string strTargetUtf8Ch
return false;
}
+CLanguageModel::Context CAlphabetManager::CloneAlphContext(CDasherNode *pNode, CLanguageModel *pLanguageModel) {
+ SAlphabetData *pData = static_cast<SAlphabetData *>(pNode->m_pUserData);
+ if(pData->iContext) return pLanguageModel->CloneContext(pData->iContext);
+ return CNodeManager::CloneAlphContext(pNode, pLanguageModel);
+}
+
+symbol CAlphabetManager::GetAlphSymbol(CDasherNode *pNode) {
+ return static_cast<SAlphabetData *>(pNode->m_pUserData)->iSymbol;
+}
+
void CAlphabetManager::PopulateChildren( CDasherNode *pNode ) {
PopulateChildrenWithSymbol( pNode, -2, 0 );
}
diff --git a/Src/DasherCore/AlphabetManager.h b/Src/DasherCore/AlphabetManager.h
index cc71be8..d470915 100644
--- a/Src/DasherCore/AlphabetManager.h
+++ b/Src/DasherCore/AlphabetManager.h
@@ -88,6 +88,9 @@ namespace Dasher {
virtual bool GameSearchNode(CDasherNode *pNode, std::string strTargetUtf8Char);
+ virtual CLanguageModel::Context CloneAlphContext(CDasherNode *pNode, CLanguageModel *pLanguageModel);
+ virtual symbol GetAlphSymbol(CDasherNode *pNode);
+
struct SAlphabetData {
symbol iSymbol;
int iPhase;
diff --git a/Src/DasherCore/ConversionHelper.cpp b/Src/DasherCore/ConversionHelper.cpp
index e716f76..2fb6cd3 100644
--- a/Src/DasherCore/ConversionHelper.cpp
+++ b/Src/DasherCore/ConversionHelper.cpp
@@ -59,15 +59,10 @@ CDasherNode *CConversionHelper::GetRoot(CDasherNode *pParent, int iLower, int iU
pNodeUserData->pLanguageModel = m_pLanguageModel;
- CAlphabetManager::SAlphabetData *pParentAlphabetData = static_cast<CAlphabetManager::SAlphabetData *>(pParent->m_pUserData);
- if((pParent->m_pNodeManager->GetID()==0)&&(pParentAlphabetData->iContext)){
- pNodeUserData->iContext=m_pLanguageModel->CloneContext(pParentAlphabetData->iContext);
- }
- else{
- CLanguageModel::Context iContext;
- iContext = m_pLanguageModel->CreateEmptyContext();
- pNodeUserData->iContext = iContext;
- }
+ // context of a conversion node (e.g. ^) is the context of the
+ // letter (e.g. e) before it (as the ^ entails replacing the e with
+ // a single accented character e-with-^)
+ pNodeUserData->iContext = pParent->m_pNodeManager->CloneAlphContext(pParent, m_pLanguageModel);
return pNewNode;
}
@@ -355,9 +350,9 @@ void CConversionHelper::BuildTree(CDasherNode *pRoot) {
pNode = pNode->Parent()) {
// TODO: Need to make this the edit text rather than the display text
- CAlphabetManager::SAlphabetData *pAlphabetData = static_cast<CAlphabetManager::SAlphabetData *>(pNode->m_pUserData);
-
- strCurrentString = m_pAlphabet->GetText(pAlphabetData->iSymbol) + strCurrentString;
+ strCurrentString =
+ m_pAlphabet->GetText(pNode->m_pNodeManager->GetAlphSymbol(pNode))
+ + strCurrentString;
}
// Handle/store the result.
SCENode *pStartTemp;
diff --git a/Src/DasherCore/MandarinAlphMgr.cpp b/Src/DasherCore/MandarinAlphMgr.cpp
index 895269e..dad5f93 100644
--- a/Src/DasherCore/MandarinAlphMgr.cpp
+++ b/Src/DasherCore/MandarinAlphMgr.cpp
@@ -71,7 +71,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<SAlphabetData *>(pNewNode->m_pUserData)->iSymbol = iSymbol;
+ static_cast<CConversionManager::SConversionData *>(pNewNode->m_pUserData)->iSymbol = 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 c745403..b3e35d6 100644
--- a/Src/DasherCore/NodeManager.h
+++ b/Src/DasherCore/NodeManager.h
@@ -20,7 +20,7 @@
#ifndef __nodemanager_h__
#define __nodemanager_h__
-
+#include "LanguageModel.h"
#include "DasherTypes.h"
namespace Dasher {
@@ -122,6 +122,16 @@ namespace Dasher {
///
virtual bool GameSearchNode(CDasherNode *pNode, std::string strTargetUtf8Char) {return false;}
+ /// Clone the context of the specified node, if it's an alphabet node;
+ /// else return an empty context. (Used by ConversionManager)
+ virtual CLanguageModel::Context CloneAlphContext(CDasherNode *pNode, CLanguageModel *pLanguageModel) {
+ return pLanguageModel->CreateEmptyContext();
+ };
+
+ virtual symbol GetAlphSymbol(CDasherNode *pNode) {
+ throw "Hack for pre-MandarinDasher ConversionManager::BuildTree method, needs to access CAlphabetManager-private struct";
+ }
+
private:
int m_iID;
};
diff --git a/Src/DasherCore/PinYinConversionHelper.cpp b/Src/DasherCore/PinYinConversionHelper.cpp
index da159e8..ac412a7 100644
--- a/Src/DasherCore/PinYinConversionHelper.cpp
+++ b/Src/DasherCore/PinYinConversionHelper.cpp
@@ -77,7 +77,7 @@ void CPinYinConversionHelper::BuildTree(CDasherNode *pRoot) {
bool CPinYinConversionHelper::Convert(const std::string &strSource, SCENode ** pRoot) {
*pRoot = 0;
-cout<<"Convert \"" << strSource << "\"\n";
+std::cout<<"Convert \"" << strSource << "\"\n";
return (pParser && pParser->Convert(strSource, pRoot));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]