[dasher: 143/217] Extracted scanning for xml files into separate class



commit 2852f77c750b545873e3c559d09def30083868bc
Author: ipomoena <amajorek google com>
Date:   Fri Dec 11 17:28:57 2015 -0800

    Extracted scanning for xml files into separate class
    
    Extracted scanning for xml files in system and user directories into
    separate class which can be instantiated before dasher interface to read
    settings.

 Src/DasherCore/DashIntfScreenMsgs.cpp  |    4 +-
 Src/DasherCore/DashIntfScreenMsgs.h    |    2 +-
 Src/DasherCore/DashIntfSettings.cpp    |    4 +-
 Src/DasherCore/DashIntfSettings.h      |    2 +-
 Src/DasherCore/DasherInterfaceBase.cpp |   29 ++-------------------------
 Src/DasherCore/DasherInterfaceBase.h   |   33 +++++++++++++++++++++++++++++--
 Src/Win32/Dasher.cpp                   |   10 ++++----
 Src/Win32/Dasher.h                     |    9 +++++++-
 Src/Win32/DasherWindow.cpp             |    3 +-
 9 files changed, 54 insertions(+), 42 deletions(-)
---
diff --git a/Src/DasherCore/DashIntfScreenMsgs.cpp b/Src/DasherCore/DashIntfScreenMsgs.cpp
index 19653a5..8a26d58 100644
--- a/Src/DasherCore/DashIntfScreenMsgs.cpp
+++ b/Src/DasherCore/DashIntfScreenMsgs.cpp
@@ -3,8 +3,8 @@
 
 using namespace Dasher;
 
-CDashIntfScreenMsgs::CDashIntfScreenMsgs(CSettingsStore *pSettingsStore)
- : CDashIntfSettings(pSettingsStore) {
+CDashIntfScreenMsgs::CDashIntfScreenMsgs(CSettingsStore *pSettingsStore, CFileUtils* fileUtils)
+       : CDashIntfSettings(pSettingsStore, fileUtils) {
 }
 
 void CDashIntfScreenMsgs::Message(const string &strText, bool bInterrupt) {
diff --git a/Src/DasherCore/DashIntfScreenMsgs.h b/Src/DasherCore/DashIntfScreenMsgs.h
index 9f2c013..9d63377 100644
--- a/Src/DasherCore/DashIntfScreenMsgs.h
+++ b/Src/DasherCore/DashIntfScreenMsgs.h
@@ -35,7 +35,7 @@ namespace Dasher {
 class CDashIntfScreenMsgs : public CDashIntfSettings {
 public:
 
-  CDashIntfScreenMsgs(CSettingsStore *pSettingsStore);
+  CDashIntfScreenMsgs(CSettingsStore *pSettingsStore, CFileUtils* fileUtils);
 
   /// Stores messages for Redraw to render onto the Screen on top of the view.
   /// For modal messages (bInterrupt=true), pauses Dasher, and keeps the message
diff --git a/Src/DasherCore/DashIntfSettings.cpp b/Src/DasherCore/DashIntfSettings.cpp
index 607c0ec..75e3448 100644
--- a/Src/DasherCore/DashIntfSettings.cpp
+++ b/Src/DasherCore/DashIntfSettings.cpp
@@ -3,8 +3,8 @@
 using namespace Dasher;
 using std::string;
 
-CDashIntfSettings::CDashIntfSettings(CSettingsStore *pSettingsStore)
- : CDasherInterfaceBase(pSettingsStore) {
+CDashIntfSettings::CDashIntfSettings(CSettingsStore *pSettingsStore, CFileUtils* fileUtils)
+       : CDasherInterfaceBase(pSettingsStore, fileUtils) {
 }
 
 bool CDashIntfSettings::GetBoolParameter(int iParameter) const {
diff --git a/Src/DasherCore/DashIntfSettings.h b/Src/DasherCore/DashIntfSettings.h
index 7164981..9f774c8 100644
--- a/Src/DasherCore/DashIntfSettings.h
+++ b/Src/DasherCore/DashIntfSettings.h
@@ -37,7 +37,7 @@ namespace Dasher {
 class CDashIntfSettings : public CDasherInterfaceBase {
 public:
 
-  CDashIntfSettings(CSettingsStore *pSettingsStore);
+       CDashIntfSettings(CSettingsStore *pSettingsStore, CFileUtils* fileUtils);
 
   CSettingsUser* GetSettingsUser() { return this; }
   bool GetBoolParameter(int iParameter) const;
diff --git a/Src/DasherCore/DasherInterfaceBase.cpp b/Src/DasherCore/DasherInterfaceBase.cpp
index ab806ca..82e4410 100644
--- a/Src/DasherCore/DasherInterfaceBase.cpp
+++ b/Src/DasherCore/DasherInterfaceBase.cpp
@@ -31,10 +31,8 @@
 #include "Observable.h"
 #include "Event.h"
 #include "NodeCreationManager.h"
-#ifndef _WIN32_WCE
 #include "UserLog.h"
 #include "BasicLog.h"
-#endif
 #include "GameModule.h"
 #include "FileWordGenerator.h"
 
@@ -68,9 +66,7 @@ const eLogLevel g_iLogLevel   = logNORMAL;
 const int       g_iLogOptions = logTimeStamp | logDateStamp;
 #endif
 
-#ifndef _WIN32_WCE
 CFileLogger* g_pLogger = NULL;
-#endif
 
 using namespace Dasher;
 using namespace std;
@@ -85,9 +81,10 @@ static char THIS_FILE[] = __FILE__;
 #endif
 #endif
 
-CDasherInterfaceBase::CDasherInterfaceBase(CSettingsStore *pSettingsStore) : CSettingsUser(pSettingsStore), 
m_pDasherModel(new CDasherModel()), m_pFramerate(new CFrameRate(this)), m_pSettingsStore(pSettingsStore), 
m_pLockLabel(NULL) {
+CDasherInterfaceBase::CDasherInterfaceBase(CSettingsStore *pSettingsStore, CFileUtils* fileUtils) : 
CSettingsUser(pSettingsStore), m_pDasherModel(new CDasherModel()), m_pFramerate(new CFrameRate(this)), 
m_pSettingsStore(pSettingsStore), m_pLockLabel(NULL) {
   
   pSettingsStore->Register(this);
+  m_fileUtils = fileUtils;
   
   // Ensure that pointers to 'owned' objects are set to NULL.
   m_DasherScreen = NULL;
@@ -107,13 +104,10 @@ CDasherInterfaceBase::CDasherInterfaceBase(CSettingsStore *pSettingsStore) : CSe
 
   //  m_bGlobalLock = false;
 
-#ifndef _WIN32_WCE
   // Global logging object we can use from anywhere
   g_pLogger = new CFileLogger("dasher.log",
                               g_iLogLevel,
                               g_iLogOptions);
-#endif
-
 }
 
 void CDasherInterfaceBase::Realize(unsigned long ulTime) {
@@ -139,16 +133,12 @@ void CDasherInterfaceBase::Realize(unsigned long ulTime) {
 
   // TODO: Sort out log type selection
 
-#ifndef _WIN32_WCE
   int iUserLogLevel = GetLongParameter(LP_USER_LOG_LEVEL_MASK);
 
   if(iUserLogLevel == 10)
     m_pUserLog = new CBasicLog(this, this);
   else if (iUserLogLevel > 0)
     m_pUserLog = new CUserLog(this, this, iUserLogLevel);
-#else
-  m_pUserLog = NULL;
-#endif
 
   CreateModules();
 
@@ -170,12 +160,10 @@ void CDasherInterfaceBase::Realize(unsigned long ulTime) {
   // InvalidateContext(true);
   ScheduleRedraw();
 
-#ifndef _WIN32_WCE
   // All the setup is done by now, so let the user log object know
   // that future parameter changes should be logged.
   if (m_pUserLog != NULL)
     m_pUserLog->InitIsDone();
-#endif
 }
 
 CDasherInterfaceBase::~CDasherInterfaceBase() {
@@ -187,7 +175,6 @@ CDasherInterfaceBase::~CDasherInterfaceBase() {
   delete m_pNCManager;
   // Do NOT delete Edit box or Screen. This class did not create them.
 
-#ifndef _WIN32_WCE
   // When we destruct on shutdown, we'll output any detailed log file
   if (m_pUserLog != NULL)
   {
@@ -200,9 +187,9 @@ CDasherInterfaceBase::~CDasherInterfaceBase() {
     delete g_pLogger;
     g_pLogger = NULL;
   }
-#endif
 
   delete m_pFramerate;
+  delete m_fileUtils;
 
 }
 
@@ -446,10 +433,8 @@ bool CDasherInterfaceBase::hasDone() {
 void CDasherInterfaceBase::Done() {
   ScheduleRedraw();
 
-#ifndef _WIN32_WCE
   if (m_pUserLog != NULL)
     m_pUserLog->StopWriting((float) GetNats());
-#endif
 
   if (GetBoolParameter(BP_COPY_ALL_ON_STOP) && SupportsClipboard()) {
     CopyToClipboard(GetAllContext());
@@ -750,9 +735,7 @@ void CDasherInterfaceBase::CreateInputFilter() {
     m_pInputFilter = NULL;
   }
 
-#ifndef _WIN32_WCE
   m_pInputFilter = (CInputFilter *)GetModuleByName(GetStringParameter(SP_INPUT_FILTER));
-#endif
 
   if (m_pInputFilter == NULL)
     m_pInputFilter = m_oModuleManager.GetDefaultInputMethod();
@@ -785,13 +768,7 @@ void CDasherInterfaceBase::CreateModules() {
   RegisterModule(defFil);
   SetDefaultInputMethod(defFil);
   RegisterModule(new COneDimensionalFilter(this, this, m_pFramerate));
-#ifndef _WIN32_WCE
   RegisterModule(new CClickFilter(this, this));
-#else
-  SetDefaultInputMethod(
-    RegisterModule(new CClickFilter(this, this));
-  );
-#endif
   RegisterModule(new COneButtonFilter(this, this));
   RegisterModule(new COneButtonDynamicFilter(this, this, m_pFramerate));
   RegisterModule(new CTwoButtonDynamicFilter(this, this, m_pFramerate));
diff --git a/Src/DasherCore/DasherInterfaceBase.h b/Src/DasherCore/DasherInterfaceBase.h
index a7bcaff..e1d31a7 100644
--- a/Src/DasherCore/DasherInterfaceBase.h
+++ b/Src/DasherCore/DasherInterfaceBase.h
@@ -62,6 +62,28 @@ class CNodeCreationManager;
 /// @{
 
 
+/// @name Platform dependent utility functions
+/// These functions provide various platform dependent functions
+/// required by the core. A derived class is created for each
+/// supported platform which implements these.
+// @{
+class CFileUtils {
+public:
+       virtual ~CFileUtils(){}
+       ///
+       /// Obtain the size in bytes of a file - the way to do this is
+       /// dependent on the OS (TODO: Check this - any posix on Windows?)
+       ///
+       virtual int GetFileSize(const std::string &strFileName) = 0;
+
+       ///Look for files, matching a filename pattern, in whatever system and/or user
+       /// locations as may exist - e.g. on disk, in app package, on web, whatever.
+       /// TODO, can we add a default implementation that looks on the Dasher website?
+       /// \param pattern string matching just filename (not path), potentially
+       /// including '*'s (as per glob)
+       virtual void ScanFiles(AbstractParser *parser, const std::string &strPattern) = 0;
+};
+
 /// The central class in the core of Dasher. Ties together the rest of
 /// the platform independent stuff and provides a single interface for
 /// the UI to use. Note: CMessageDisplay unimplemented; platforms should
@@ -70,7 +92,7 @@ class CNodeCreationManager;
 class Dasher::CDasherInterfaceBase : public CMessageDisplay, public Observable<const CEditEvent *>, 
protected Observer<int>, protected CSettingsUser, private NoClones {
 public:
   ///Create a new interface by providing the only-and-only settings store that will be used throughout.
-  CDasherInterfaceBase(CSettingsStore *pSettingsStore);
+  CDasherInterfaceBase(CSettingsStore *pSettingsStore, CFileUtils* fileUtils);
   virtual ~CDasherInterfaceBase();
 
   /// @name Access to internal member classes
@@ -380,14 +402,18 @@ public:
   /// Obtain the size in bytes of a file - the way to do this is
   /// dependent on the OS (TODO: Check this - any posix on Windows?)
   ///
-  virtual int GetFileSize(const std::string &strFileName) = 0;
+  int GetFileSize(const std::string &strFileName) {
+         return m_fileUtils->GetFileSize(strFileName);
+  }
   
   ///Look for files, matching a filename pattern, in whatever system and/or user
   /// locations as may exist - e.g. on disk, in app package, on web, whatever.
   /// TODO, can we add a default implementation that looks on the Dasher website?
   /// \param pattern string matching just filename (not path), potentially
   /// including '*'s (as per glob)
-  virtual void ScanFiles(AbstractParser *parser, const std::string &strPattern) = 0;
+  void ScanFiles(AbstractParser *parser, const std::string &strPattern)  {
+         m_fileUtils->ScanFiles(parser, strPattern);
+  }
   
   // @}
   
@@ -488,6 +514,7 @@ protected:
   /// this interface was created, as ClSet and ResetParameter need to access it.
   /// (TODO _could_ move these into CSettingsUser, but that seems uglier given so few clients?)
   CSettingsStore * const m_pSettingsStore;
+  CFileUtils* m_fileUtils;
 
   //The default expansion policy to use - an amortized policy depending on the LP_NODE_BUDGET parameter.
   CExpansionPolicy *m_defaultPolicy;
diff --git a/Src/Win32/Dasher.cpp b/Src/Win32/Dasher.cpp
index cd794ce..c92f898 100644
--- a/Src/Win32/Dasher.cpp
+++ b/Src/Win32/Dasher.cpp
@@ -32,8 +32,8 @@ using namespace WinUTF8;
 
 CONST UINT WM_DASHER_FOCUS = RegisterWindowMessage(L"WM_DASHER_FOCUS");
 
-CDasher::CDasher(HWND Parent, CDasherWindow *pWindow, CEdit *pEdit, Dasher::CSettingsStore* settings)
- : CDashIntfScreenMsgs(settings), m_hParent(Parent), m_pWindow(pWindow), m_pEdit(pEdit) {
+CDasher::CDasher(HWND Parent, CDasherWindow *pWindow, CEdit *pEdit, Dasher::CSettingsStore* settings, 
CFileUtils* fileUtils)
+  : CDashIntfScreenMsgs(settings, fileUtils), m_hParent(Parent), m_pWindow(pWindow), m_pEdit(pEdit) {
   // This class will be a wrapper for the Dasher 'control' - think ActiveX
 
 #ifndef _WIN32_WCE
@@ -191,7 +191,7 @@ void Dasher::CDasher::WriteTrainFile(const std::string &filename, const std::str
   }
 }
 
-void CDasher::ScanDirectory(const Tstring &strMask, std::vector<std::string> &vFileList) {
+void CWinFileUtils::ScanDirectory(const Tstring &strMask, std::vector<std::string> &vFileList) {
   using namespace WinUTF8;
 
   std::string filename;
@@ -210,7 +210,7 @@ void CDasher::ScanDirectory(const Tstring &strMask, std::vector<std::string> &vF
   }
 }
 
-void CDasher::ScanFiles(AbstractParser *parser, const std::string &strPattern) {
+void CWinFileUtils::ScanFiles(AbstractParser *parser, const std::string &strPattern) {
   using namespace WinHelper;
   using namespace WinUTF8;
   
@@ -244,7 +244,7 @@ void CDasher::ScanFiles(AbstractParser *parser, const std::string &strPattern) {
     parser->ParseFile(userDir + (*it),true);
 }
 
-int CDasher::GetFileSize(const std::string &strFileName) {
+int CWinFileUtils::GetFileSize(const std::string &strFileName) {
 #ifndef _WIN32_WCE
   struct _stat sStatInfo;
   _stat(strFileName.c_str(), &sStatInfo);
diff --git a/Src/Win32/Dasher.h b/Src/Win32/Dasher.h
index ed21aa2..970b392 100644
--- a/Src/Win32/Dasher.h
+++ b/Src/Win32/Dasher.h
@@ -23,10 +23,17 @@ class CEdit;
 class CDasherWindow;
 
 namespace Dasher {
+class CWinFileUtils :public CFileUtils{
+  virtual int GetFileSize(const std::string &strFileName) override;
+  virtual void ScanFiles(AbstractParser *parser, const std::string &strPattern) override;
+private:
+  void ScanDirectory(const Tstring &strMask, std::vector<std::string> &vFileList);
+};
+
 class CDasher : public CDashIntfScreenMsgs
 {
 public:
-  CDasher(HWND Parent, CDasherWindow *pWindow, CEdit *pEdit, Dasher::CSettingsStore* settings);
+  CDasher(HWND Parent, CDasherWindow *pWindow, CEdit *pEdit, Dasher::CSettingsStore* settings, CFileUtils* 
fileUtils);
   ~CDasher(void);
 
   // The following functions will not be part of the final interface
diff --git a/Src/Win32/DasherWindow.cpp b/Src/Win32/DasherWindow.cpp
index 0f2c66a..4fe043d 100644
--- a/Src/Win32/DasherWindow.cpp
+++ b/Src/Win32/DasherWindow.cpp
@@ -81,6 +81,7 @@ HWND CDasherWindow::Create() {
   WinLocalisation::GetResourceString(IDS_APP_TITLE, &WindowTitle);
 
   static XmlErrorDisplay display;
+  CFileUtils* fileUtils = new CWinFileUtils();
   Dasher::CSettingsStore* settings;
   if (xml_config_file_.IsEmpty()) {
       settings = new CWinOptions("Inference Group", "Dasher3");
@@ -113,7 +114,7 @@ HWND CDasherWindow::Create() {
   m_pEdit->Create(hWnd, m_pAppSettings->GetBoolParameter(APP_BP_TIME_STAMP));
   m_pEdit->SetFont(m_pAppSettings->GetStringParameter(APP_SP_EDIT_FONT), 
m_pAppSettings->GetLongParameter(APP_LP_EDIT_FONT_SIZE));
 
-  m_pDasher = new CDasher(hWnd, this, m_pEdit, settings);
+  m_pDasher = new CDasher(hWnd, this, m_pEdit, settings, fileUtils); // Takes ownership of the fileUtils
 
   // Create a CAppSettings
   m_pAppSettings->SetHwnd(hWnd);


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