]> gitweb.hamatoma.de Git - reqt/commitdiff
cuReMatcher works
authorhama <hama@siduction.net>
Thu, 17 Sep 2015 21:55:34 +0000 (23:55 +0200)
committerhama <hama@siduction.net>
Thu, 17 Sep 2015 21:55:34 +0000 (23:55 +0200)
15 files changed:
base/ReMatcher.cpp [new file with mode: 0644]
base/ReMatcher.hpp [new file with mode: 0644]
base/ReQStringUtils.cpp
base/ReQStringUtils.hpp
base/rebase.hpp
cunit/allTests.cpp
cunit/cuReFileSystem.cpp [new file with mode: 0644]
cunit/cuReMatcher.cpp [new file with mode: 0644]
cunit/cunit.pro
gui/ReSettings.cpp
gui/ReSettings.hpp
os/ReFileSystem.cpp
os/ReFileSystem.hpp
os/ReTraverser.hpp
os/reos.hpp

diff --git a/base/ReMatcher.cpp b/base/ReMatcher.cpp
new file mode 100644 (file)
index 0000000..3b9a5a9
--- /dev/null
@@ -0,0 +1,197 @@
+/*
+ * ReQStringUtil.cpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
+ */
+
+/** @file
+ * @brief Processors for pattern matching.
+ *
+ * Patterns can contain wildcards: '*' for any string
+ */
+/** @file base/ReMatcher.hpp
+ *
+ * @brief Efficient pattern matching.
+ */
+#include "base/rebase.hpp"
+
+
+/**
+ * Constructor.
+ *
+ * @param pattern                      a pattern with wildcards '*' (any string)
+ * @param caseSensitivity      caseSensitive or caseInsensitive
+ * @param anchored                     <code>true<code>: the pattern starts at the strings
+ *                                                     start<br>
+ *                                                     <code>false<code>: the pattern can start anywhere in
+ *                                                     the string
+ */
+
+ReMatcher::ReMatcher(const QString& pattern, Qt::CaseSensitivity caseSensivity,
+       bool anchored) :
+               m_needles(),
+               m_restLengths(),
+               m_anchored(anchored),
+               m_caseSensivitiy(caseSensivity) {
+       setPattern(pattern);
+}
+
+/**
+ * Tests whether the given string matches the pattern.
+ *
+ * @param text the text to test
+ * @return             <code>true</code>: the pattern matches
+ */
+bool ReMatcher::matches(const QString& text) {
+       bool found = m_needles.size() == 0;
+       if (!found) {
+               found =
+                       m_anchored ?
+                               text.startsWith(m_needles.at(0), m_caseSensivitiy) : true;
+               if (found) {
+                       int startIx = m_anchored ? 1 : 0;
+                       int textIndex = m_anchored ? m_needles.at(0).length() : 0;
+                       for (int ix = startIx; found && ix < m_needles.size(); ix++) {
+                               found = text.size() - textIndex >= m_restLengths.at(ix);
+                               if (found)
+                                       found = (textIndex = text.indexOf(m_needles.at(ix),
+                                               textIndex, m_caseSensivitiy)) >= 0;
+                       }
+               }
+       }
+       return found;
+}
+
+/**
+ * Sets the search pattern.
+ *
+ * @param pattern      the search pattern, with wildcards '*' (any string)
+ */
+void ReMatcher::setPattern(const QString& pattern) {
+       if (pattern.isEmpty())
+               m_needles.clear();
+       else {
+               if (pattern.startsWith("*"))
+                       m_anchored = false;
+               m_needles = pattern.split('*');
+               // Eliminate empty entries:
+               for (int ix = m_needles.size() - 1; ix >= 0; ix--) {
+                       if (m_needles.at(ix).length() == 0)
+                               m_needles.removeAt(ix);
+                       else
+                               m_restLengths.append(0);
+               }
+               int sum = 0;
+               for (int ix = m_needles.size() - 1; ix >= 0; ix--) {
+                       int size = m_needles.at(ix).size();
+                       m_restLengths.append(size + sum);
+                       sum += size;
+               }
+       }
+}
+
+/**
+ * Constructor.
+ *
+ * @param patterns                     a list of patterns with wildcards '*' (any string)
+ * @param caseSensitivity      caseSensitive or caseInsensitive
+ * @param anchored                     <code>true<code>: the pattern starts at the strings
+ *                                                     start<br>
+ *                                                     <code>false<code>: the pattern can start anywhere in
+ *                                                     the string
+ */
+ReListMatcher::ReListMatcher(const QStringList& patterns,
+                                                        Qt::CaseSensitivity caseSensitivty, bool anchored) :
+       m_list(),
+       m_empty(false)
+{
+       QStringList::const_iterator it;
+       for (it = patterns.constBegin(); it != patterns.cend(); ++it){
+               m_list.append(new ReMatcher(*it, caseSensitivty, anchored));
+               m_empty = true;
+       }
+}
+/**
+  * Destructor.
+  */
+ReListMatcher::~ReListMatcher(){
+       destroy();
+}
+/**
+ * Frees the resources.
+ */
+void ReListMatcher::destroy(){
+       QList<ReMatcher*>::const_iterator it;
+       for (it = m_list.constBegin(); it != m_list.cend(); ++it){
+               delete *it;
+       }
+       m_list.clear();
+}
+
+/**
+ * Returns whether the pattern list is empty.
+ *
+ * @return     <code>true</code>: the pattern list is empty
+ */
+bool ReListMatcher::empty() const
+{
+       return m_empty;
+}
+
+/**
+ * Tests whether at least one pattern of the list matches the given text
+ * @param text text to test
+ * @return             <code>true</code>: one of the stored patterns matches the text<br>
+ *                             <code>false</code>: none of the patterns matches
+ */
+bool ReListMatcher::matches(const QString& text)
+{
+       QList<ReMatcher*>::const_iterator it;
+       bool rc = false;
+       for (it = m_list.constBegin(); ! rc && it != m_list.cend(); ++it){
+               rc = (*it)->matches(text);
+       }
+       return rc;
+}
+
+
+/**
+ * Constructor.
+ *
+ * @param includes                     a list of include patterns
+ * @param excludes                     a list of exclude patterns
+ * @param caseSensitivity      caseSensitive or caseInsensitive
+ * @param anchored                     <code>true<code>: the pattern starts at the strings
+ *                                                     start<br>
+ *                                                     <code>false<code>: the pattern can start anywhere in
+ *                                                     the string
+ */
+ReIncludeExcludeMatcher::ReIncludeExcludeMatcher(const QStringList& includes,
+       const QStringList& excludes, Qt::CaseSensitivity caseSensitivty,
+       bool anchored) :
+       m_includes(includes, caseSensitivty, anchored),
+       m_excludes(excludes, caseSensitivty, anchored)
+{
+}
+
+/**
+ * Tests whether a text matches the include patterns and does not match the
+ * exclude patterns.
+ *
+ * @param text                 text to test
+ * @param excludeToo   <code>true</code>: the exclude patterns will be tested
+ * @return                             <code>true</code>: at least one of the include patterns
+ *                                             matches and none of the exclude patterns matches
+ */
+bool ReIncludeExcludeMatcher::matches(const QString& text, bool excludeToo)
+{
+       bool rc = m_includes.matches(text);
+       if (rc && excludeToo && ! m_excludes.empty())
+               rc = ! m_excludes.matches(text);
+       return rc;
+}
diff --git a/base/ReMatcher.hpp b/base/ReMatcher.hpp
new file mode 100644 (file)
index 0000000..c5eb9b7
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * ReQStringUtil.hpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
+ */
+
+#ifndef REMATCHER_HPP
+#define REMATCHER_HPP
+
+
+/**
+ * Processor for an efficient test whether a text matches a pattern.
+ *
+ * A pattern can contain wildcards: '*' for any string.
+ */
+class ReMatcher {
+public:
+       ReMatcher(const QString& pattern, Qt::CaseSensitivity caseSensitivty =
+               Qt::CaseSensitive, bool anchored = false);
+public:
+       bool matches(const QString& text);
+       void setPattern(const QString& pattern);
+protected:
+       QStringList m_needles;
+       // m_restLengths[ix] = sum(m_needles[ix..last].size()
+       QList<int> m_restLengths;
+       bool m_anchored;
+       Qt::CaseSensitivity m_caseSensivitiy;
+};
+
+/**
+ * Processor for efficient test whether a text matches a list of patterns.
+ */
+class ReListMatcher {
+public:
+       ReListMatcher(const QStringList& patterns, Qt::CaseSensitivity caseSensitivty =
+                       Qt::CaseSensitive, bool anchored = false);
+       ~ReListMatcher();
+public:
+       bool matches(const QString& text);
+       bool empty() const;
+protected:
+       void destroy();
+protected:
+       QList<ReMatcher*> m_list;
+       bool m_empty;
+};
+
+/**
+ * Processor for efficient test whether a text matches an include pattern list
+ * and not an exclude pattern list.
+ */
+class ReIncludeExcludeMatcher{
+public:
+       ReIncludeExcludeMatcher(const QStringList& includes, const QStringList& excludes,
+                       Qt::CaseSensitivity caseSensitivty = Qt::CaseSensitive,
+                       bool anchored = false);
+public:
+       bool matches(const QString& text, bool excludeToo = true);
+protected:
+       ReListMatcher m_includes;
+       ReListMatcher m_excludes;
+};
+
+#endif // REMATCHER_HPP
index a31bc7256cf3525ca93855500a7845fdd78225b9..e1cb8b0f8cacd8ea2c8bfd3f242dcdb179c7c270 100644 (file)
@@ -9,16 +9,17 @@
  * The latest sources: https://github.com/republib
  */
 
+#include "base/rebase.hpp"
+QStringList ReQStringUtils::m_emptyList;
+
 /** @file
- * @brief Missed operation for <code>ReString</code>s.
+ * @brief Missed operation for <code>QString</code>s.
  */
-/** @file rplcore/rplqstring.hpp
+/** @file base/ReQStringUtils.hpp
  *
- * @brief Definitions for missed operation for <code>ReString</code>s.
+ * @brief Definitions for missed operation for <code>QString</code>s.
  */
 #include "base/rebase.hpp"
-#include <QtCore/qmath.h>
-#include <QDateTime>
 
 /**
  * Removes end of line characters if any.
@@ -811,152 +812,3 @@ QDateTime ReDateTimeParser::parseDateTime(const QString& expr) {
        return rc;
 }
 
-/**
- * Constructor.
- *
- * @param pattern                      a pattern with wildcards '*' (any string)
- * @param caseSensitivity      caseSensitive or caseInsensitive
- * @param anchored                     <code>true<code>: the pattern starts at the strings
- *                                                     start<br>
- *                                                     <code>false<code>: the pattern can start anywhere in
- *                                                     the string
- */
-
-ReMatcher::ReMatcher(const QString& pattern, Qt::CaseSensitivity caseSensivity,
-       bool anchored) :
-               m_needles(),
-               m_restLengths(),
-               m_anchored(anchored),
-               m_caseSensivitiy(caseSensivity) {
-       setPattern(pattern);
-}
-
-/**
- * Tests whether the given string matches the pattern.
- *
- * @param text the text to test
- * @return             <code>true</code>: the pattern matches
- */
-bool ReMatcher::matches(const QString& text) {
-       bool found = m_needles.size() == 0;
-       if (!found) {
-               found =
-                       m_anchored ?
-                               text.startsWith(m_needles.at(0), m_caseSensivitiy) : true;
-               if (found) {
-                       int startIx = m_anchored ? 1 : 0;
-                       int textIndex = m_anchored ? m_needles.at(0).length() : 0;
-                       for (int ix = startIx; found && ix < m_needles.size(); ix++) {
-                               found = text.size() - textIndex >= m_restLengths.at(ix);
-                               if (found)
-                                       found = (textIndex = text.indexOf(m_needles.at(ix),
-                                               textIndex, m_caseSensivitiy)) >= 0;
-                       }
-               }
-       }
-       return found;
-}
-
-/**
- * Sets the search pattern.
- *
- * @param pattern      the search pattern, with wildcards '*' (any string)
- */
-void ReMatcher::setPattern(const QString& pattern) {
-       m_needles = pattern.split('*');
-       // Eliminate empty entries:
-       for (int ix = m_needles.size() - 1; ix >= 0; ix--) {
-               if (m_needles.at(ix).length() == 0)
-                       m_needles.removeAt(ix);
-               else
-                       m_restLengths.append(0);
-       }
-       int sum = 0;
-       for (int ix = m_needles.size() - 1; ix >= 0; ix--) {
-               int size = m_needles.at(ix).size();
-               m_restLengths.append(size + sum);
-               sum += size;
-       }
-
-}
-
-/**
- * Constructor.
- *
- * @param patterns                     a list of patterns with wildcards '*' (any string)
- * @param caseSensitivity      caseSensitive or caseInsensitive
- * @param anchored                     <code>true<code>: the pattern starts at the strings
- *                                                     start<br>
- *                                                     <code>false<code>: the pattern can start anywhere in
- *                                                     the string
- */
-ReListMatcher::ReListMatcher(const QStringList& patterns,
-                                                        Qt::CaseSensitivity caseSensitivty, bool anchored) :
-       m_patternList(patterns.size())
-{
-       QStringList::const_iterator it;
-       for (it = patterns.constBegin(); it != patterns.cend(); ++it){
-               m_list.append(new ReMatcher(*it, caseSensitivty, anchored));
-       }
-}
-/**
-  * Destructor.
-  */
-ReListMatcher::~ReListMatcher(){
-       QList<ReMatcher*>::const_iterator it;
-       for (it = m_list.constBegin(); it != patterns.cend(); ++it){
-               delete *it;
-       }
-       m_list.clear();
-}
-/**
- * Tests whether at least one pattern of the list matches the given text
- * @param text text to test
- * @return             <code>true</code>: one of the stored patterns matches the text<br>
- *                             <code>false</code>: none of the patterns matches
- */
-bool ReListMatcher::matches(const QString& text)
-{
-       QList<ReMatcher*>::const_iterator it;
-       bool rc = false;
-       for (it = m_list.constBegin(); ! rc && it != patterns.cend(); ++it){
-               rc = it->matches(text);
-       }
-       return rc;
-}
-
-/**
- * Constructor.
- *
- * @param includes                     a list of include patterns
- * @param excludes                     a list of exclude patterns
- * @param caseSensitivity      caseSensitive or caseInsensitive
- * @param anchored                     <code>true<code>: the pattern starts at the strings
- *                                                     start<br>
- *                                                     <code>false<code>: the pattern can start anywhere in
- *                                                     the string
- */
-ReIncludeExcludeMatcher::ReIncludeExcludeMatcher(const QStringList& includes,
-       const QStringList& excludes, Qt::CaseSensitivity caseSensitivty,
-       bool anchored) :
-       m_includes(includes, caseSensitivty, anchored),
-       m_excludes(excludes, caseSensitivty, anchored)
-{
-}
-
-/**
- * Tests whether a text matches the include patterns and does not match the
- * exclude patterns.
- *
- * @param text                 text to test
- * @param excludeToo   <code>true</code>: the exclude patterns will be tested
- * @return                             <code>true</code>: at least one of the include patterns
- *                                             matches and none of the exclude patterns matches
- */
-bool ReIncludeExcludeMatcher::matches(const QString& text, bool excludeToo)
-{
-       bool rc = m_includes.matches(text);
-       if (rc && excludeToo && m_excludes.size() > 0)
-               rc = ! m_excludes.matches(text);
-       return rc;
-}
index 5afb71d8a280ae0ed78e2a9b5ed622f80a0d60a3..67d4a984919f73faf66521c36b94b6d9193a9611 100644 (file)
@@ -9,8 +9,8 @@
  * The latest sources: https://github.com/republib
  */
 
-#ifndef RPLQSTRING_HPP
-#define RPLQSTRING_HPP
+#ifndef REQSTRINGUTILS_HPP
+#define REQSTRINGUTILS_HPP
 
 /**
  * Some useful static functions handling <code>QString</code> instances.
@@ -68,6 +68,8 @@ public:
                           digit >= 'a' && digit <= 'f' ? digit - 'a' + 10 : -1;
        }
        static char* utf8(const ReString& source, char buffer[], size_t bufferSize);
+public:
+       static QStringList m_emptyList;
 };
 
 /**
@@ -121,52 +123,4 @@ private:
        QDateTime m_dateTime;
 };
 
-/**
- * Processor for efficient test whether a text matches a pattern ('*' for any string).
- */
-class ReMatcher {
-public:
-       ReMatcher(const QString& pattern, Qt::CaseSensitivity caseSensitivty =
-               Qt::CaseSensitive, bool anchored = false);
-public:
-       bool matches(const QString& text);
-       void setPattern(const QString& pattern);
-protected:
-       QStringList m_needles;
-       // m_restLengths[ix] = sum(m_needles[ix..last].size()
-       QList<int> m_restLengths;
-       bool m_anchored;
-       Qt::CaseSensitivity m_caseSensivitiy;
-};
-
-/**
- * Processor for efficient test whether a text matches a list of patterns.
- */
-class ReListMatcher {
-public:
-       ReListMatcher(const QStringList& patterns, Qt::CaseSensitivity caseSensitivty =
-                       Qt::CaseSensitive, bool anchored = false);
-       ~ReListMatcher();
-public:
-       bool matches(const QString& text);
-protected:
-       QList<ReMatcher*> m_list;
-};
-
-/**
- * Processor for efficient test whether a text matches an include pattern list
- * and not an exclude pattern list.
- */
-class ReIncludeExcludeMatcher{
-public:
-       ReIncludeExcludeMatcher(const QStringList& includes, const QStringList& excludes,
-                       Qt::CaseSensitivity caseSensitivty = Qt::CaseSensitive,
-                       bool anchored = false);
-public:
-       bool matches(const QString& text, bool excludeToo = true);
-protected:
-       ReListMatcher m_includes;
-       ReListMatcher m_excludes;
-};
-
-#endif // RPLQSTRING_HPP
+#endif // REQSTRINGUTILS_HPP
index 4894bf12b5beaa50a1c011dbc542e7f1bf3bb68d..23166873d11c9132d5e96bdac7c8a46705027771 100644 (file)
@@ -34,6 +34,7 @@
 #include <QDataStream>
 #include <QMutex>
 #include <QRegularExpression>
+#include <QDateTime>
 #include <QtCore/qmath.h>
 #include <QTranslator>
 #include <QDateTime>
@@ -101,7 +102,7 @@ inline int roundInt(double value) {
 #include "base/ReException.hpp"
 #include "base/ReContainer.hpp"
 #include "base/ReStringUtils.hpp"
-#include "ReQStringUtils.hpp"
+#include "base/ReQStringUtils.hpp"
 #include "base/ReConfigurator.hpp"
 #include "base/ReConfig.hpp"
 #include "base/ReTerminator.hpp"
@@ -109,6 +110,7 @@ inline int roundInt(double value) {
 #include "base/ReFileUtils.hpp"
 #include "base/ReFile.hpp"
 #include "base/ReDiff.hpp"
+#include "base/ReMatcher.hpp"
 #include "base/ReTest.hpp"
 
 #endif // REBASE_HPP
index 749e4ff763aeea3012150d377ea0cc92cfb0b052..9c16df1307e6e90ea636f2218a6b1a56d287cc1a 100644 (file)
@@ -39,6 +39,8 @@ static void testBase() {
        void testReWriter();
        void testReFile();
        void testReFileUtils();
+       void testReMatcher();
+       testReMatcher();
        testReQStringUtil();
        testReFile();
        testReFileUtils();
diff --git a/cunit/cuReFileSystem.cpp b/cunit/cuReFileSystem.cpp
new file mode 100644 (file)
index 0000000..6f732eb
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * cuReFileSystem.cpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
+ */
+#include "base/rebase.hpp"
+#include "os/reos.hpp"
+
+/** @file
+ * @brief Unit test of the basic exceptions.
+ */
+
+class TestReFileSystem: public ReTest {
+public:
+       TestReFileSystem() :
+                       ReTest("ReFileSystem") {
+               doIt();
+       }
+private:
+       QByteArray m_base;
+       QByteArray m_subDir1;
+protected:
+       void init(){
+               m_base = ReFileUtils::tempDir("refilesystem");
+               m_subDir1 = tempDir("dir1", "refilesystem");
+               tempDir("dir2", "refilesystem");
+               QString node;
+               for (int ix = 1; ix <= 7; ix++){
+                       node.sprintf("test%d.txt", ix);
+                       QString fn = ReFileUtils::tempFile(node, "refilesystem", false);
+                       ReFileUtils::writeToFile(fn, node);
+                       fn.sprintf("%stext%d.txt", m_subDir1.constData(), ix);
+                       ReFileUtils::writeToFile(fn, fn);
+               }
+       }
+       void testReLocalFileSystem() {
+               ReLocalFileSytem fs(m_base);
+               fs.
+
+       }
+       virtual void run() {
+               init();
+               testReLocalFileSystem();
+       }
+};
+void testReFileSystem() {
+       TestReFileSystem test;
+}
+
diff --git a/cunit/cuReMatcher.cpp b/cunit/cuReMatcher.cpp
new file mode 100644 (file)
index 0000000..4321c28
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * cuReMatcher.cpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
+ */
+/** @file
+ * @brief Unit test of the ReString tools.
+ */
+
+#include "../base/rebase.hpp"
+
+class TestReMatcher: public ReTest {
+public:
+       TestReMatcher() :
+                       ReTest("ReMatcher") {
+               doIt();
+       }
+
+public:
+       void testBasics() {
+               ReMatcher m1("a*b*c", Qt::CaseSensitive, true);
+               checkT(m1.matches("a b c d"));
+               checkT(m1.matches("abc d"));
+               checkT(m1.matches("ababc"));
+               checkT(m1.matches("abc"));
+               checkF(m1.matches("aBc"));
+
+               ReMatcher m2("a*b*c", Qt::CaseSensitive, false);
+               checkT(m2.matches("a b c d"));
+               checkT(m2.matches("ababc"));
+               checkT(m2.matches("a b a b c"));
+               checkT(m2.matches(" abc"));
+               checkF(m2.matches(" ab"));
+
+               ReMatcher m3("a**B*C", Qt::CaseInsensitive, true);
+               checkT(m3.matches("a b c d"));
+               checkT(m3.matches("abc d"));
+               checkT(m3.matches("ababc"));
+               checkT(m3.matches("abc"));
+
+               ReMatcher m4("A*B*c", Qt::CaseInsensitive, false);
+               checkT(m4.matches("a b c d"));
+               checkT(m4.matches("ababc"));
+               checkT(m4.matches("a b a b c"));
+               checkT(m4.matches(" abc"));
+               checkF(m4.matches(" ab"));
+
+               m4.setPattern("*");
+               checkT(m4.matches("x"));
+               m4.setPattern("");
+               checkT(m4.matches("any"));
+       }
+       void testList(){
+               QStringList patterns;
+               patterns << "*.txt" << "*.doc";
+               ReListMatcher matcher(patterns, Qt::CaseInsensitive, true);
+               checkT(matcher.matches("README.TXT"));
+               checkT(matcher.matches("Xyz.Doc"));
+               checkF(matcher.matches("a.doc.bak"));
+
+               ReListMatcher matcher2(ReQStringUtils::m_emptyList, Qt::CaseInsensitive, true);
+               checkT(matcher2.matches("abc"));
+
+       }
+
+       virtual void run(void) {
+               testBasics();
+               testList();
+       }
+};
+void testReMatcher() {
+       TestReMatcher test;
+}
+
index 6bb2b9eb4e99fd66fdd3944c72ee204ba2b6ed8d..717246bc58ba38660b669388cad9f51cc2225c78 100644 (file)
@@ -33,11 +33,14 @@ SOURCES += main.cpp \
         ../base/ReLogger.cpp \
         ../base/ReStringUtils.cpp \
         ../base/ReTerminator.cpp \
+        ../base/ReMatcher.cpp \
         ../base/ReTest.cpp \
         ../base/ReWriter.cpp \
         ../gui/ReStateStorage.cpp \
         ../gui/ReSettings.cpp \
        ../gui/ReEdit.cpp \
+       ../os/ReFileSystem.cpp \
+        cuReFileSystem.cpp \
         cuReConfig.cpp \
         cuReContainer.cpp \
         cuReWriter.cpp \
@@ -45,6 +48,7 @@ SOURCES += main.cpp \
        cuReEdit.cpp \
        cuReStateStorage.cpp \
        cuReSettings.cpp \
+       cuReMatcher.cpp \
         allTests.cpp
 
 HEADERS += \
index c8a10e16ec495e42f44de5a5f55278df620577b0..cde1280ae3244c1b4380ea6da03ae9d7d9e1b05b 100644 (file)
@@ -416,14 +416,6 @@ ReDelayedStorage::ReDelayedStorage(const QString& file, ReLogger* logger,
        connect(&m_timer, SIGNAL(timeout()), this, SLOT(timeout()));
 }
 
-/**
- * Destructor.
- */
-ReDelayedStorage::~ReDelayedStorage()
-{
-
-}
-
 /**
  * Finds the index of the widget in the list.
  *
index 526e50d03b0023ca115950c5e12564db9f01a9b5..eca2444bf7e54cef0d8a37316275d8fecd2b5846 100644 (file)
@@ -41,7 +41,6 @@ public:
 class ReLogger;
 class QMainWindow;
 class ReDelayedStorage : protected QObject{
-       Q_OBJECT
        enum ObjType {
                OT_UNDEF,
                OT_WINDOW
@@ -52,7 +51,7 @@ class ReDelayedStorage : protected QObject{
        } ObjInfo;
 public:
        ReDelayedStorage(const QString& file, ReLogger* m_logger, int delay = 5);
-       virtual ~ReDelayedStorage();
+       virtual ~ReDelayedStorage(){}
 public:
        void storeWindow(const QMainWindow* window);
 public:
index 05496d4f59a6e42629413f8b9477b53cbaea2f6e..862e77f6c9b75360d9ead4fc67a7561dd9de73f0 100644 (file)
@@ -53,22 +53,12 @@ void ReFileSystem::setWriteable(bool writeable)
        m_writeable = writeable;
 }
 
-/**
- * Tests whether a node matches at least one entry of a pattern list.
- * @param patterns     the list of patterns to test
- * @param node         the filename to test
- * @return                     <code>true</code>: at least one entry pattern matches
- */
-bool ReFileSystem::match(const QStringList& patterns, const QString& node)
-{
-       QStringUtils::
-}
-
 /**
  * Constructor.
  */
-ReLinuxFS::ReLinuxFS(const QString& basePath) :
-       m_path(basePath),
+ReLocalFileSytem::ReLocalFileSytem(const QString& basePath) :
+       ReFileSystem("localfs"),
+       m_basePath(basePath),
        m_currentPath(basePath),
        m_dir(basePath)
 {
@@ -83,7 +73,7 @@ ReLinuxFS::ReLinuxFS(const QString& basePath) :
  *                             EC_PATH_NOT_FOUND       directory does not exist<br>
  *                             EC_NOT_ACCESSIBLE       parent not readable
  */
-ReFileSystem::ErrorCode ReLinuxFS::setDirectory(const QString& path)
+ReFileSystem::ErrorCode ReLocalFileSytem::setDirectory(const QString& path)
 {
        ErrorCode rc = m_dir.setCurrent(path) ? EC_SUCCESS : EC_PATH_NOT_FOUND;
        m_currentPath = m_dir.absolutePath();
@@ -95,9 +85,9 @@ ReFileSystem::ErrorCode ReLinuxFS::setDirectory(const QString& path)
  *
  * @return     the name of the current directory
  */
-const QString&ReLinuxFS::directory() const
+const QString& ReLocalFileSytem::directory() const
 {
-       return m_currentDir;
+       return m_currentPath;
 }
 
 /**
@@ -107,8 +97,8 @@ const QString&ReLinuxFS::directory() const
  *                                     Can contain wildcard '*' (for any string)
  * @return                     a list of the files matching the patterns
  */
-QList<ReFileMetaData*> ReLinuxFS::listInfos(const QString& pattern,
-       const QStringList& excludePatterns)
+int ReLocalFileSytem::listInfos(const ReIncludeExcludeMatcher& matcher,
+                       QList<ReFileMetaData*>& list)
 {
        QList<ReFileMetaData*> rc;
        QStringList list = pattern.size() == 0 ? m_dir.entryList()
index 0ce2fc72b8d1f85214256675e0551c7adf8d1b54..d48648c7eb8e57e5b0ec80dbfebf4dd5235f0fd4 100644 (file)
@@ -14,8 +14,8 @@
 
 class ReFileMetaData {
 public:
-       FileMetaData(const QString& node);
-       virtual ~FileMetaData();
+       ReFileMetaData(const QString& node);
+       virtual ~ReFileMetaData();
 public:
        QString m_node;
        QDateTime m_modified;
@@ -26,6 +26,7 @@ public:
 };
 
 class ReFileSystem {
+public:
        enum ListOption {
                LO_UNDEF = 0,
                LO_FILES = 1,
@@ -62,29 +63,26 @@ public:
         *                                                      can be in the result list
         * @return                      a list of the files matching the patterns
         */
-       virtual QList<ReFileMetaData*> listInfos(const QStringList& patterns,
-               const QStringList& excludePatterns) = 0;
+       virtual int listInfos(const ReIncludeExcludeMatcher& matcher,
+                                                 QList<ReFileMetaData*>& list) = 0;
 public:
-       bool getWriteable() const;
+       bool writeable() const;
        void setWriteable(bool writeable);
-public:
-       static bool match(const QStringList& patterns, const QString& node);
 protected:
        QString m_name;
        QString m_directory;
        bool m_writeable;
 };
 
-class ReLinuxFS : public ReFileSystem {
+class ReLocalFileSytem : public ReFileSystem {
 public:
-       ReLinuxFS(const QString& basePath);
-       virtual ~ReLinuxFS();
-       // ReFileSystem interface
+       ReLocalFileSytem(const QString& basePath);
+       virtual ~ReLocalFileSytem();
 public:
        ErrorCode setDirectory(const QString& path);
        const QString& directory() const;
-       QList<ReFileMetaData*> listInfos(const QStringList& patterns,
-               const QStringList& excludePatterns);
+       virtual int listInfos(const ReIncludeExcludeMatcher& matcher,
+                                                 QList<ReFileMetaData*>& list);
 protected:
        QString m_basePath;
        QString m_currentPath;
index 9fe3bacca8cdd4c682a2f107721add9404c1882e..a52f221cbed0e829481da6abefcac67aff7234f7 100644 (file)
@@ -12,7 +12,7 @@
 #ifndef OS_RETRAVERSER_HPP_
 #define OS_RETRAVERSER_HPP_
 
-#include "string/ReMatcher.hpp"
+#include "base/ReMatcher.hpp"
 #ifdef __linux__
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -66,7 +66,7 @@ public:
 public:
        const ReFileTime_t* accessed();
        ReFileSize_t fileSize();
-       const char* filetimeAsString(ReByteBuffer& buffer);
+       const char* filetimeAsString(QByteArray& buffer);
        bool findFirst();
        bool findNext();
        void freeEntry();
@@ -77,23 +77,23 @@ public:
        bool isRegular();
        const ReFileTime_t* modified();
        const char* node() const;
-       const char* rightsAsString(ReByteBuffer& buffer, bool numerical,
-           int ownerWidth);
+       const char* rightsAsString(QByteArray& buffer, bool numerical,
+               int ownerWidth);
        Type_t type();
        char typeAsChar();
 public:
        static const char* filetimeToString(const ReFileTime_t* time,
-           ReByteBuffer& buffer);
+               QByteArray& buffer);
        static time_t filetimeToTime(const ReFileTime_t* time);
 #if defined __WIN32__
-       static bool getFileOwner(HANDLE handle, const char* file, ReByteBuffer& name,
+       static bool getFileOwner(HANDLE handle, const char* file, QByteArray& name,
                ReLogger* logger = NULL);
        static bool getPrivilege(const char* privilege, ReLogger* logger);
 #endif
        static void timeToFiletime(time_t time, ReFileTime_t& filetime);
 public:
-       ReByteBuffer m_path;
-       ReByteBuffer m_fullName;
+       QByteArray m_path;
+       QByteArray m_fullName;
        int m_passNo;
        ReLogger* m_logger;
 #ifdef __linux__
@@ -108,14 +108,14 @@ public:
        bool m_getPrivilege;
 #endif
 };
-class ReDirEntryFilter: public ReSerializable {
+class ReDirEntryFilter {
 public:
        ReDirEntryFilter();
        ~ReDirEntryFilter();
 public:
        virtual void deserialize(const uint8_t*& sequence, size_t& length);
        bool match(ReDirStatus_t& entry);
-       virtual ReByteBuffer& serialize(ReByteBuffer& sequence);
+       virtual QByteArray& serialize(QByteArray& sequence);
 public:
        ReDirStatus_t::Type_t m_types;
        RePatternList* m_nodePatterns;
@@ -170,9 +170,9 @@ class ReDirTreeStatistic {
 public:
        ReDirTreeStatistic();
 public:
-       const char* statisticAsString(ReByteBuffer& buffer, bool append = false,
-           const char* formatFiles = "%8d ", const char* formatSizes = "%12.6f",
-           const char* formatDirs = "%7d ");
+       const char* statisticAsString(QByteArray& buffer, bool append = false,
+               const char* formatFiles = "%8d ", const char* formatSizes = "%12.6f",
+               const char* formatDirs = "%7d ");
        /**
         * Resets the counters.
         */
@@ -190,7 +190,7 @@ public:
 class ReTraverser: public ReDirTreeStatistic {
 public:
        ReTraverser(const char* base, ReTraceUnit* tracer = NULL, ReLogger* logger =
-           NULL);
+               NULL);
        virtual ~ReTraverser();
 public:
        void changeBase(const char* base);
@@ -259,7 +259,7 @@ public:
 protected:
        void destroy();
        void freeEntry(int level);
-       bool initEntry(const ReByteBuffer& parent, const char* node, int level);
+       bool initEntry(const QByteArray& parent, const char* node, int level);
        /**
         * Tests whether a directory should be processed.
         * @param node          the base name of the subdir
@@ -274,7 +274,7 @@ protected:
        int m_minLevel;
        int m_maxLevel;
        int m_level;
-       ReByteBuffer m_base;
+       QByteArray m_base;
        ReDirStatus_t* m_dirs[MAX_ENTRY_STACK_DEPTH];
        /// each directory will be passed twice: for all files + for directories only
        /// 1: depth first 2: breadth first
index f4b0fe6119cd2cf0c6b06dac4550ae2d89a08bd8..a93b8d87728cbc9ec08866d9cc7eb0e4654999aa 100644 (file)
@@ -11,7 +11,9 @@
 
 #ifndef OS_REOS_HPP_
 #define OS_REOS_HPP_
-
+#ifndef REBASE_HPP
+#include "base/rebase.hpp"
+#endif
 #if defined __linux__
 #include "unistd.h"
 #include <dirent.h>
 #error "unknown os"
 #endif
 
+#if defined __linux__
+typedef struct timespec ReFileTime_t;
+typedef __off_t ReFileSize_t;
+#elif defined __WIN32__
+typedef FILETIME ReFileTime_t;
+typedef int64_t ReFileSize_t;
+#endif
 /** Returns whether a time is greater (younger) than another.
  * @param time1                first operand
  * @param time2                second operand
@@ -36,14 +45,10 @@ inline bool operator >(const ReFileTime_t& time1, const ReFileTime_t& time2) {
        || (time1.tv_sec == time2.tv_sec && time1.tv_nsec > time2.tv_nsec);
 #else
        return time1.dwHighDateTime > time2.dwHighDateTime
-           || (time1.dwHighDateTime == time2.dwHighDateTime
-               && time1.dwLowDateTime > time2.dwLowDateTime);
+               || (time1.dwHighDateTime == time2.dwHighDateTime
+                       && time1.dwLowDateTime > time2.dwLowDateTime);
 #endif
 }
-#include "os/ReTraverser.hpp"
-#include "os/ReDirTools.hpp"
-#include "net/renet.hpp"
-#include "os/ReRemoteDir.hpp"
 #include "os/ReFileSystem.hpp"
 
 #endif /* OS_REOS_HPP_ */