tweaking pointers
This commit is contained in:
parent
85941393bf
commit
560b613ca5
@ -2,8 +2,8 @@
|
||||
|
||||
namespace kc {
|
||||
|
||||
FileContext::FileContext(kc::FileEntry entry)
|
||||
: file_entry(std::make_shared<kc::FileEntry>(entry))
|
||||
FileContext::FileContext(std::shared_ptr<kc::FileEntry> entry)
|
||||
: file_entry(entry)
|
||||
{
|
||||
|
||||
}
|
||||
@ -33,7 +33,7 @@ void FileContext::parse()
|
||||
std::smatch image_match;
|
||||
while(std::regex_search(file_content, image_match, image_regex)) {
|
||||
|
||||
images.push_back(image_match.str());
|
||||
images.push_back(kc::Link(image_match.str()));
|
||||
file_content = image_match.suffix();
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ namespace kc {
|
||||
class FileContext {
|
||||
public:
|
||||
|
||||
FileContext(kc::FileEntry entry);
|
||||
FileContext(std::shared_ptr<kc::FileEntry> entry);
|
||||
|
||||
std::shared_ptr<kc::FileEntry> file_entry;
|
||||
std::vector<kc::Link> links;
|
||||
|
@ -1,20 +1,25 @@
|
||||
#include "FileContextCache.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <execution>
|
||||
|
||||
#include "../fs/fs.hpp"
|
||||
#include "../logging.hpp"
|
||||
|
||||
namespace kc {
|
||||
|
||||
void FileContextCache::load(std::string root_path)
|
||||
void FileContextCache::load(const std::string root_path)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(trace) << "Beginning cache load";
|
||||
|
||||
auto entries = kc::walk_dir(root_path);
|
||||
this->root_path.assign(root_path);
|
||||
|
||||
for (auto entry : entries)
|
||||
{
|
||||
if (entry.relative_path.extension() == ".md")
|
||||
if (entry->relative_path.extension() == ".md")
|
||||
{
|
||||
entry.load_content();
|
||||
entry->load_content();
|
||||
}
|
||||
|
||||
file_contexts.push_back(std::make_shared<kc::FileContext>(entry));
|
||||
@ -26,7 +31,13 @@ void FileContextCache::load(std::string root_path)
|
||||
void FileContextCache::parse_all()
|
||||
{
|
||||
tag_map.clear();
|
||||
for (auto context: file_contexts)
|
||||
|
||||
#if __APPLE__
|
||||
std::for_each(file_contexts.begin(), file_contexts.end(), [this](std::shared_ptr<kc::FileContext> &context)
|
||||
#else
|
||||
std::for_each(std::execution::par_unseq, file_contexts.begin(), file_contexts.end(), [this](std::shared_ptr<kc::FileContext> &context)
|
||||
#endif
|
||||
|
||||
{
|
||||
if (context->file_entry->relative_path.extension() == ".md")
|
||||
{
|
||||
@ -40,7 +51,7 @@ void FileContextCache::parse_all()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void FileContextCache::clear()
|
||||
@ -49,14 +60,19 @@ void FileContextCache::clear()
|
||||
file_contexts.shrink_to_fit();
|
||||
}
|
||||
|
||||
size_t FileContextCache::size()
|
||||
size_t FileContextCache::size() const
|
||||
{
|
||||
return file_contexts.size();
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<kc::FileContext>> FileContextCache::get()
|
||||
std::vector<std::shared_ptr<kc::FileContext>> FileContextCache::get() const
|
||||
{
|
||||
return file_contexts;
|
||||
}
|
||||
|
||||
std::string FileContextCache::get_root_path() const
|
||||
{
|
||||
return root_path;
|
||||
}
|
||||
|
||||
}
|
@ -12,14 +12,16 @@ class FileContextCache {
|
||||
public:
|
||||
void load(std::string root_path);
|
||||
void clear();
|
||||
size_t size();
|
||||
std::vector<std::shared_ptr<kc::FileContext>> get();
|
||||
size_t size() const;
|
||||
std::vector<std::shared_ptr<kc::FileContext>> get() const;
|
||||
void parse_all();
|
||||
std::string get_root_path() const;
|
||||
|
||||
std::unordered_map<std::string, std::vector<std::shared_ptr<kc::FileEntry>>> tag_map;
|
||||
|
||||
private:
|
||||
std::vector<std::shared_ptr<kc::FileContext>> file_contexts;
|
||||
std::string root_path;
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user