From: hama Date: Thu, 17 Sep 2015 21:55:34 +0000 (+0200) Subject: cuReMatcher works X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=8368f7a4c3ca29904e3cabef64a6308c285a5266;p=reqt cuReMatcher works --- diff --git a/base/ReMatcher.cpp b/base/ReMatcher.cpp new file mode 100644 index 0000000..3b9a5a9 --- /dev/null +++ b/base/ReMatcher.cpp @@ -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 true: the pattern starts at the strings + * start
+ * false: 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 true: 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 true: the pattern starts at the strings + * start
+ * false: 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::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 true: 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 true: one of the stored patterns matches the text
+ * false: none of the patterns matches + */ +bool ReListMatcher::matches(const QString& text) +{ + QList::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 true: the pattern starts at the strings + * start
+ * false: 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 true: the exclude patterns will be tested + * @return true: 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 index 0000000..c5eb9b7 --- /dev/null +++ b/base/ReMatcher.hpp @@ -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 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 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 diff --git a/base/ReQStringUtils.cpp b/base/ReQStringUtils.cpp index a31bc72..e1cb8b0 100644 --- a/base/ReQStringUtils.cpp +++ b/base/ReQStringUtils.cpp @@ -9,16 +9,17 @@ * The latest sources: https://github.com/republib */ +#include "base/rebase.hpp" +QStringList ReQStringUtils::m_emptyList; + /** @file - * @brief Missed operation for ReStrings. + * @brief Missed operation for QStrings. */ -/** @file rplcore/rplqstring.hpp +/** @file base/ReQStringUtils.hpp * - * @brief Definitions for missed operation for ReStrings. + * @brief Definitions for missed operation for QStrings. */ #include "base/rebase.hpp" -#include -#include /** * 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 true: the pattern starts at the strings - * start
- * false: 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 true: 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 true: the pattern starts at the strings - * start
- * false: 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::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 true: one of the stored patterns matches the text
- * false: none of the patterns matches - */ -bool ReListMatcher::matches(const QString& text) -{ - QList::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 true: the pattern starts at the strings - * start
- * false: 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 true: the exclude patterns will be tested - * @return true: 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; -} diff --git a/base/ReQStringUtils.hpp b/base/ReQStringUtils.hpp index 5afb71d..67d4a98 100644 --- a/base/ReQStringUtils.hpp +++ b/base/ReQStringUtils.hpp @@ -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 QString 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 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 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 diff --git a/base/rebase.hpp b/base/rebase.hpp index 4894bf1..2316687 100644 --- a/base/rebase.hpp +++ b/base/rebase.hpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -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 diff --git a/cunit/allTests.cpp b/cunit/allTests.cpp index 749e4ff..9c16df1 100644 --- a/cunit/allTests.cpp +++ b/cunit/allTests.cpp @@ -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 index 0000000..6f732eb --- /dev/null +++ b/cunit/cuReFileSystem.cpp @@ -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 index 0000000..4321c28 --- /dev/null +++ b/cunit/cuReMatcher.cpp @@ -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; +} + diff --git a/cunit/cunit.pro b/cunit/cunit.pro index 6bb2b9e..717246b 100644 --- a/cunit/cunit.pro +++ b/cunit/cunit.pro @@ -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 += \ diff --git a/gui/ReSettings.cpp b/gui/ReSettings.cpp index c8a10e1..cde1280 100644 --- a/gui/ReSettings.cpp +++ b/gui/ReSettings.cpp @@ -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. * diff --git a/gui/ReSettings.hpp b/gui/ReSettings.hpp index 526e50d..eca2444 100644 --- a/gui/ReSettings.hpp +++ b/gui/ReSettings.hpp @@ -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: diff --git a/os/ReFileSystem.cpp b/os/ReFileSystem.cpp index 05496d4..862e77f 100644 --- a/os/ReFileSystem.cpp +++ b/os/ReFileSystem.cpp @@ -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 true: 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
* 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 ReLinuxFS::listInfos(const QString& pattern, - const QStringList& excludePatterns) +int ReLocalFileSytem::listInfos(const ReIncludeExcludeMatcher& matcher, + QList& list) { QList rc; QStringList list = pattern.size() == 0 ? m_dir.entryList() diff --git a/os/ReFileSystem.hpp b/os/ReFileSystem.hpp index 0ce2fc7..d48648c 100644 --- a/os/ReFileSystem.hpp +++ b/os/ReFileSystem.hpp @@ -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 listInfos(const QStringList& patterns, - const QStringList& excludePatterns) = 0; + virtual int listInfos(const ReIncludeExcludeMatcher& matcher, + QList& 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 listInfos(const QStringList& patterns, - const QStringList& excludePatterns); + virtual int listInfos(const ReIncludeExcludeMatcher& matcher, + QList& list); protected: QString m_basePath; QString m_currentPath; diff --git a/os/ReTraverser.hpp b/os/ReTraverser.hpp index 9fe3bac..a52f221 100644 --- a/os/ReTraverser.hpp +++ b/os/ReTraverser.hpp @@ -12,7 +12,7 @@ #ifndef OS_RETRAVERSER_HPP_ #define OS_RETRAVERSER_HPP_ -#include "string/ReMatcher.hpp" +#include "base/ReMatcher.hpp" #ifdef __linux__ #include #include @@ -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 diff --git a/os/reos.hpp b/os/reos.hpp index f4b0fe6..a93b8d8 100644 --- a/os/reos.hpp +++ b/os/reos.hpp @@ -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 @@ -25,6 +27,13 @@ #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_ */