Author Topic: decouple more things in token.h and tokenstree.h  (Read 9493 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
decouple more things in token.h and tokenstree.h
« on: February 07, 2012, 07:55:59 am »
Would it possible to do more decoupling on the Token class and TokensTree class.
I would like to move some typedef like:
Code
typedef SearchTree<TokenIdxSet>                                  TokenSearchTree;
typedef BasicSearchTree                                          TokenFilenamesMap;
typedef std::map< size_t, TokenIdxSet,       std::less<size_t> > TokenFilesMap;
typedef std::map< size_t, FileParsingStatus, std::less<size_t> > TokenFilesStatus;
from token.h to tokenstree.h.

But I can't move this one:
Code
typedef std::set< size_t, std::less<size_t> >                    TokenFilesSet;
Because Token class use this kind of declaration.
Any ideas?
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: decouple more things in token.h and tokenstree.h
« Reply #1 on: February 10, 2012, 03:37:31 pm »
What I try to do is:
Code
Index: token.h
===================================================================
--- token.h (revision 7785)
+++ token.h (working copy)
@@ -6,40 +6,18 @@
 #ifndef TOKEN_H
 #define TOKEN_H
 
-#include <wx/arrstr.h>
-#include <wx/dynarray.h> // WX_DEFINE_ARRAY
-#include <wx/string.h>
+#include <wx/arrstr.h>  //wxArrayString
+#include <wx/string.h>  //wxString
 
-#include <deque>
 #include <set>
-#include <vector>
+#include <map>   //template map
 
-#include "searchtree.h"
-
-class wxEvtHandler;
-
 class Token;
 class TokensTree;
 
-enum FileParsingStatus
-{
-    fpsNotParsed = 0,
-    fpsAssigned,
-    fpsBeingParsed,
-    fpsDone
-};
+typedef std::set< int, std::less<int> >           TokenIdxSet;
+typedef std::set< size_t, std::less<size_t> >     TokenFilesSet;
 
-WX_DEFINE_ARRAY(Token*, TokensArray);
-
-typedef std::vector<Token*>                                      TokenList;
-typedef std::deque<int>                                          TokenIdxList;
-typedef std::set< int, std::less<int> >                          TokenIdxSet;
-typedef SearchTree<TokenIdxSet>                                  TokenSearchTree;
-typedef BasicSearchTree                                          TokenFilenamesMap;
-typedef std::map< size_t, TokenIdxSet,       std::less<size_t> > TokenFilesMap;
-typedef std::map< size_t, FileParsingStatus, std::less<size_t> > TokenFilesStatus;
-typedef std::set< size_t, std::less<size_t> >                    TokenFilesSet;
-
 enum TokenScope
 {
     tsUndefined = 0,
Index: tokenstree.h
===================================================================
--- tokenstree.h (revision 7785)
+++ tokenstree.h (working copy)
@@ -8,9 +8,29 @@
 
 #include <wx/string.h>
 #include <wx/thread.h>
+#include <vector>
+#include <deque>
 
 #include "token.h"
+#include "searchtree.h"
 
+enum FileParsingStatus
+{
+    fpsNotParsed = 0,
+    fpsAssigned,
+    fpsBeingParsed,
+    fpsDone
+};
+
+typedef std::deque<int>                                          TokenIdxList;
+typedef std::vector<Token*>                                      TokenList;
+typedef SearchTree<TokenIdxSet>                                  TokenSearchTree;
+typedef BasicSearchTree                                          TokenFilenamesMap;
+typedef std::map< size_t, TokenIdxSet,       std::less<size_t> > TokenFilesMap;
+typedef std::map< size_t, FileParsingStatus, std::less<size_t> > TokenFilesStatus;
+
+
+
 extern wxMutex s_TokensTreeMutex;
 
 class TokensTree


It looks like most typedef should not be in token.h, so I moved to tokenstree.h, any ideas?
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: decouple more things in token.h and tokenstree.h
« Reply #2 on: February 10, 2012, 08:20:07 pm »
What I try to do is:
Go ahead... Looks good to me.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: decouple more things in token.h and tokenstree.h
« Reply #3 on: February 11, 2012, 03:45:08 am »
Ok, done in rev 7789.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.