appendInt(minutes, stdFormat).append(":");
appendInt(sec, sec > 10 || minimum > 5 ? stdFormat : "%d").append(".");
appendInt(msec, "%03d");
+ return *this;
}
/** Converts a subsequence into an integer.
if (end == -1)
end = m_length;
if (start >= 0 && start < end){
- if (end > m_length)
+ if (end > (int) m_length)
setLength(end);
memset(m_buffer + start, filler, end - start);
}
* @param deltaList If there is not enough space in the content buffer
* this amount of bytes is the minimum to reserve.
*/
-ReSeqArray::ReSeqArray(size_t deltaList, int deltaBuffer) :
+ReSeqArray::ReSeqArray(int deltaList, int deltaBuffer) :
m_content(deltaBuffer),
m_list(deltaList),
m_lost(0),
Tag m_tag;
} Sequence;
public:
- ReSeqArray(size_t deltaList = -1024*sizeof(size_t), int deltaBuffer = - 1024*1024);
+ ReSeqArray(int deltaList = -1024 * (int) sizeof(size_t), int deltaBuffer = - 1024*1024);
virtual ~ReSeqArray();
ReSeqArray(const ReSeqArray& source);
ReSeqArray& operator = (const ReSeqArray& source);
#if defined __linux__
int64_t diff = clock() - start;
return diff * 1000 / CLOCKS_PER_SEC;
+#elif defined __WIN32__
+ int64_t diff = clock() - start;
+ return diff * 1000 / CLOCKS_PER_SEC;
#else
# error "timer not defined"
#endif
int64_t ReTestUnit::timer(){
#if defined __linux__
return clock();
+#elif defined __WIN32__
+ return clock();
+#if 0
+ FILETIME timeBuffer;
+ GetSystemTimeAsFileTime(&timeBuffer);
+ return (int64_t) (((uint64_t) timeBuffer.dwHighDateTime << 32) + timeBuffer.dwLowDateTime);
+#endif
#else
# error "timer not defined"
#endif
return *this;
}
+/* @brief Defines an 64 bit integer argument.
+ *
+ * @param value The integer value of the argument.
+ * @param format The format (used with sprintf()) of the argument, e.g. "%lld".
+ *
+ * @return The instance itself. This is useful for chaining.
+ */
+ReVarArgs& ReVarArgs::arg(int64_t value, const char* format){
+ char number[256];
+ _snprintf(number, sizeof number, format, value);
+ store(number);
+ return *this;
+}
+
+/** @brief Stores an long argument.
+ *
+ * @param value The argument value.
+ * @param format The format (used with sprintf()) of the argument, e.g. "%d".
+ *
+ * @return The instance itself. This is useful for chaining.
+ */
+ReVarArgs& ReVarArgs::arg(unsigned int value, const char* format){
+ char number[256];
+ _snprintf(number, sizeof number, format, value);
+ store(number);
+ return *this;
+}
/** @brief Stores an long argument.
*
* @param value The argument value.
*
* @return The instance itself. This is useful for chaining.
*/
-ReVarArgs& ReVarArgs::arg(long value, const char* format){
+ReVarArgs& ReVarArgs::arg(uint64_t value, const char* format){
char number[256];
_snprintf(number, sizeof number, format, value);
store(number);
public:
ReVarArgs& reset(const char* format);
ReVarArgs& arg(int value, const char* format = "%d");
- ReVarArgs& arg(long arg, const char* format = "%ld");
+ ReVarArgs& arg(int64_t value, const char* format = "%lld");
+ ReVarArgs& arg(unsigned int arg, const char* format = "%u");
+ ReVarArgs& arg(uint64_t value, const char* format = "%llu");
ReVarArgs& arg(const char* arg, int minWidth = 0, int maxWidth = 1024, bool alignRight = false);
ReVarArgs& arg(double arg, const char* format = "%f");
const char* asCString();
testNext();
}
void massTest(){
- const int maxKeys = 50*1000;
+ const int maxKeys = 20*1000;
const int minLength = 3;
const int maxLength = 10;
const int countGet = maxKeys * 50;
checkDirExists("/etc/");
checkFileExists("/etc/passwd");
#elif defined __WIN32__
- checkDirExists("c:\\windows")
+ checkDirExists("c:\\windows");
#endif
log(false, "8 errors follow:");
checkT(false);
* cuReTraverser.cpp
*
* Created on: 23.12.2014
- * Author: hm
*/
#include "base/rebase.hpp"
makeDir("dir1/dir1_1");
makeDir("dir1/dir1_2");
makeDir("dir1/dir1_2/dir1_2_1");
+ makeDir("dir1/cache");
makeFile("dir1/dir1_2/dir1_2_1/x1.txt");
makeFile("dir1/dir1_2/dir1_2_1/x2.txt");
makeFile("dir2/2.x");
+ makeFile("dir1/cache/cache.txt");
}
void run(){
- initTree();
- testDirOptions();
- checkSetFilterFromProgramArgs();
- testDirStatistic();
+ initTree();
testBasic();
+ testDirOptions();
+ checkSetFilterFromProgramArgs();
+ testDirStatistic();
testCopyFile();
testList();
}
tools.list(2, argv);
}
void testCopyFile(){
+#if defined __linux__
ReByteBuffer src(m_base);
src.append("dir1/dir1_2/dir1_2_1/x1.txt");
ReByteBuffer trg(testDir());
buffer.ensureSize(5);
ReDirSync::copyFile(src.str(), 0, -1ll, trg.str(), buffer, ReLogger::globalLogger());
checkFileEqu(src.str(), trg.str());
+#else
+ log(false, "testCopyFile not implemented");
+#endif
}
void checkRelDate(time_t absTime, int relTime){
}
void testBasic(){
ReTraverser traverser(m_base.str());
+ RePatternList patterns;
+ // exclude */cache/*
+ ReByteBuffer buffer(";*;-*");
+ buffer.append(ReTraverser::m_separatorStr).append("cache")
+ .append(ReTraverser::m_separatorStr);
+ patterns.set(buffer.str());
+ traverser.setDirPattern(&patterns);
int level = 0;
ReDirStatus_t* entry;
ReHashList hash;
checkOneFile("dir1_1", "dir1", hash);
checkOneFile("dir1_2", "dir1", hash);
checkOneFile("dir1", m_base.str(), hash);
+ checkF(hash.get("cache.txt", buffer));
}
void testDirStatistic(){
ReDirStatistic stat;
log(false, list2.join("\n", buffer).str());
buffer.set(list.strOf(0), list.strLengthOf(0));
- checkT(buffer.startsWith(" 0.000054 MB 2 3\t"));
+ checkT(buffer.startsWith(" 0.000074 MB 3 4\t"));
expected.set(m_base.str(), m_base.length()).append("dir1", -1)
.append(ReTraverser::m_separatorStr);
checkT(buffer.endsWith(expected.str()));
checkT(buffer.endsWith(expected.str()));
buffer.set(list.strOf(2), list.strLengthOf(2));
- checkT(buffer.startsWith(" 0.000067 MB 4 5\t"));
+ checkT(buffer.startsWith(" 0.000087 MB 5 6\t"));
expected.set(m_base.str(), m_base.length());
}
};
#endif
void testBase(){
- extern void testReHashList(void);
- testReHashList();
-
extern void testReTestUnit();
- testReTestUnit();
+ //testReTestUnit();
extern void testReByteBuffer();
testReByteBuffer();
extern void testReSeqArray(void);
void testAll(){
try
{
- testBase();
testOs();
+ testBase();
testMath();
testString();
} catch (ReException e){
if (read(fh, buffer, sizeof buffer) > 0)
rc ^= *(seed_t*) buffer;
close(fh);
+#elif defined __WIN32__
#else
#error "no true random"
#endif
+ return rc;
}
/**
* @brief Returns the next random integer.
* @return The next seed.
*/
int64_t ReRandomizer::nextInt64(int64_t maxValue, int64_t minValue){
- int rc;
+ seed_t rc;
if (minValue > maxValue){
rc = minValue;
minValue = maxValue;
if (minValue == maxValue)
rc = minValue;
else if (minValue == 0 && maxValue == LLONG_MAX)
- rc = abs(seed);
+ rc = abs((int64_t) seed);
else if (uint64_t(maxValue - minValue) < LLONG_MAX)
// no signed int64 overflow:
rc = minValue + seed % (maxValue - minValue + 1);
m_level(-1),\r
m_base(base),\r
// m_dirs\r
- m_passNoForDirSearch(2)\r
+ m_passNoForDirSearch(2),\r
+ m_dirPatterns(NULL)\r
{\r
memset(m_dirs, 0, sizeof m_dirs);\r
m_dirs[0] = new ReDirStatus_t();\r
+ // remove a preceeding "./". This simplifies the pattern expressions:\r
+ if (m_base.startsWith(ReByteBuffer(".").append(m_separatorStr, 1).str())){\r
+ m_base.remove(0, 2);\r
+ }\r
}\r
\r
/**\r
} else {\r
// we are interested only in true subdirectories:\r
again = true;\r
- if (current->isDirectory() && ! current->isDotDir() && ! current->isLink()\r
- && m_level < m_maxLevel){\r
+ if (m_level < m_maxLevel && current->isDirectory()\r
+ && ! current->isDotDir() && ! current->isLink()\r
+ && (m_dirPatterns == NULL || isAllowedDir(current->m_path,\r
+ current->node()))){\r
// open a new level\r
alreadyRead = initEntry(current->m_path, current->node() , m_level + 1);\r
}\r
public:
ReDirStatus_t* rawNextFile(int& level);
ReDirStatus_t* nextFile(int& level, ReDirEntryFilter_t* filter = NULL);
+ /** Sets directory filter (pattern list).
+ * @param pattern pattern list for the subdirs to be entered
+ */
+ void setDirPattern(RePatternList* pattern)
+ { m_dirPatterns = pattern; }
/** Sets the maximal depth.
* @param value the value to set
*/
- void setMinLevel(int value)
- { m_minLevel = value; }
+ void setMaxLevel(int value)
+ { m_maxLevel = value; }
/** Sets the minimal depth.
* @param value the value to set
*/
- void setMaxLevel(int value)
- { m_maxLevel = value; }
+ void setMinLevel(int value)
+ { m_minLevel = value; }
protected:
bool initEntry(const ReByteBuffer& parent, const char* node, int level);
void freeEntry(int level);
+ /**
+ * Tests whether a directory should be processed.
+ * @param path the path of the subdir
+ * @param node the base name of the subdir
+ * @return <code>true</code>: the subdir will be processed<br>
+ * <code>false</code>: do not enter this subdir
+ */
+ inline bool isAllowedDir(const ReByteBuffer& path, const char* node){
+ bool rc = m_dirPatterns->match(ReByteBuffer(path).append(node).str());
+ return rc;
+ }
protected:
int m_minLevel;
int m_maxLevel;
/// each directory will be passed twice: for all files + for directories only
/// 1: depth first 2: breadth first
int m_passNoForDirSearch;
+ /// a subdirectory will be entered only if this pattern list matches
+ /// if NULL any directory will be entered
+ RePatternList* m_dirPatterns;
public:
static const char m_separator;
static const char* const m_separatorStr;