1. remusao
  2. StatUtils

Commits

remusao  committed 18d031c

improved factorization

  • Participants
  • Parent commits ddab27e
  • Branches master

Comments (0)

Files changed (3)

File include/basicTypes/bag_of_words.hh

View file
 namespace stat
 {
     template <typename W>
-    class BagOfWords final : public BasicDocument<std::set<W>>
+    class BagOfWords final : public BasicDocument<W, std::set<W>>
     {
         public:
-            // Types
-            typedef typename W::word_internal_type  word_internal_type;
-            typedef W                               word_type;
-
             // Constructors
             ~BagOfWords() = default;
             BagOfWords() = delete;
 
             // Transform a Document to a BagOfWords
             BagOfWords(Document<W>&& document)
-                : BasicDocument<std::set<W>>(document.getUrl(), document.begin(), document.end())
+                : BasicDocument<W, std::set<W>>(
+                        document.getUrl(),
+                        document.begin(),
+                        document.end())
             {
             }
 

File include/basicTypes/basic_document.hh

View file
 
 namespace stat
 {
-    template <typename T>
+    template <typename W, typename T>
     class BasicDocument
     {
         public:
-            ~BasicDocument() = default;
-            BasicDocument() = default;
-            
-            template <typename Iterator>
-            BasicDocument(const char* url, const Iterator& b, const Iterator& e)
-                : document_(b, e),
-                  url_(url)
-            {
-            }
+            // Types
+            typedef typename W::word_internal_type  word_internal_type;
+            typedef W                               word_type;
 
-            // Copy
-            BasicDocument(const BasicDocument&) = delete;
-            BasicDocument& operator=(const BasicDocument&) = delete;
-
-            // Move
-            BasicDocument(BasicDocument&&) = default;
-            BasicDocument& operator=(BasicDocument&&) = default;
 
             // Methods
-
             typename T::iterator begin()
             {
                 return document_.begin();
             }
 
         protected:
+           // Should not be created by user
+
+            BasicDocument() = default;
+            ~BasicDocument() = default;
+            
+            template <typename Iterator>
+            BasicDocument(const char* url, const Iterator& b, const Iterator& e)
+                : document_(b, e),
+                  url_(url)
+            {
+            }
+
+            // Copy
+            BasicDocument(const BasicDocument&) = delete;
+            BasicDocument& operator=(const BasicDocument&) = delete;
+
+            // Move
+            BasicDocument(BasicDocument&&) = default;
+            BasicDocument& operator=(BasicDocument&&) = default;
+
+
+            // Attributes
             T           document_;
             std::string url_;
     };

File include/basicTypes/document.hh

View file
 namespace stat
 {
     template <typename W>
-    class Document final : public BasicDocument<std::vector<W>>
+    class Document final : public BasicDocument<W, std::vector<W>>
     {
         public:
-            // Types
-            typedef typename W::word_internal_type  word_internal_type;
-            typedef W                               word_type;
-
-
             // Constructors
             ~Document() = default;