1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2025-07-02 14:04:22 +00:00

Create DirTree class and start moving code around.

This commit is contained in:
King_DuckZ 2016-03-03 20:46:30 +01:00
parent c69d17395a
commit 5b3e15c45f
9 changed files with 326 additions and 129 deletions

View file

@ -1,62 +0,0 @@
/* Copyright 2015, 2016, Michele Santullo
* This file is part of "dindexer".
*
* "dindexer" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* "dindexer" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef idB6D385B7779240308449D6081CB790F1
#define idB6D385B7779240308449D6081CB790F1
#include "filestats.hpp"
#include <vector>
#include <functional>
#include <boost/utility/string_ref.hpp>
namespace fastf {
struct StringWithLength {
StringWithLength ( const char* parStr, int parLen ) :
str(parStr),
len(parLen)
{
}
const char* const str;
const int len;
};
class FileSearcher {
public:
typedef std::vector<StringWithLength> ConstCharVecType;
typedef std::function<bool(const char*, const FileStats&)> CallbackType;
explicit FileSearcher ( boost::string_ref parBaseDir );
~FileSearcher ( void ) noexcept;
void Search ( const ConstCharVecType& parExtensions, const ConstCharVecType& parIgnorePaths );
void SetFollowSymlinks ( bool parFollow ) noexcept { followSymlinks_ = parFollow; }
bool FollowSymlinks ( void ) const noexcept { return followSymlinks_; }
void SetRemainInFilesystem ( bool parRemain ) noexcept { remainInFilesystem_ = parRemain; }
bool RemainInFilesystem ( void ) const noexcept { return remainInFilesystem_; }
void SetCallback ( CallbackType parCallback );
private:
CallbackType callback_;
const std::string baseDir_;
bool followSymlinks_;
bool remainInFilesystem_;
};
} //namespace fastf
#endif

View file

@ -0,0 +1,68 @@
/* Copyright 2015, 2016, Michele Santullo
* This file is part of "dindexer".
*
* "dindexer" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* "dindexer" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef idCB253C1A5AFA46A18B8878ED4072CD96
#define idCB253C1A5AFA46A18B8878ED4072CD96
#include <ciso646>
namespace mchlib {
namespace scantask {
template <typename T>
class Base {
protected:
Base ( void );
virtual ~Base ( void ) noexcept = default;
public:
T& get_or_create ( void );
void clear_data ( void );
private:
virtual void on_data_destroy ( T& parData ) = 0;
virtual void on_data_create ( T& parData ) = 0;
T m_data;
bool m_data_created;
};
template <typename T>
Base<T>::Base() :
m_data_created(false)
{
}
template <typename T>
T& Base<T>::get_or_create() {
if (not m_data_created) {
m_data_created = true;
this->on_data_create(m_data);
}
return m_data;
}
template <typename T>
void Base<T>::clear_data() {
if (m_data_created) {
m_data_created = false;
this->on_data_destroy(m_data);
}
}
} //namespace scantask
} //namespace mchlib
#endif

View file

@ -15,19 +15,31 @@
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef id4A7D7AB671954418939FC0BDA19C5B3F
#define id4A7D7AB671954418939FC0BDA19C5B3F
#ifndef id0AA31B2E7D6244A08435CF9080E34AAE
#define id0AA31B2E7D6244A08435CF9080E34AAE
#include <ctime>
#include "dindexer-machinery/scantask/base.hpp"
#include <string>
#include <vector>
namespace fastf {
struct FileStats {
int level;
std::time_t atime;
std::time_t mtime;
bool is_dir;
bool is_symlink;
};
} //namespace fastf
namespace mchlib {
struct FileRecordData;
namespace scantask {
class DirTree : public Base<std::vector<FileRecordData>> {
public:
typedef std::vector<FileRecordData> PathList;
explicit DirTree ( std::string parRoot );
virtual ~DirTree ( void ) noexcept = default;
private:
virtual void on_data_destroy ( PathList& parData );
virtual void on_data_create ( PathList& parData );
std::string m_root;
};
} //namespace scantask
} //namespace mchlib
#endif