2014-05-12 12:41:46 -04:00
|
|
|
/*
|
2026-02-23 13:22:21 -06:00
|
|
|
ISC License
|
|
|
|
|
|
|
|
|
|
Copyright (c) 2026, Antonio SJ Musumeci <trapexit@spawn.link>
|
2016-01-14 16:50:22 -05:00
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
|
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
2014-05-12 12:41:46 -04:00
|
|
|
*/
|
|
|
|
|
|
2017-06-30 11:15:20 -04:00
|
|
|
#pragma once
|
2014-05-12 12:41:46 -04:00
|
|
|
|
2020-12-19 15:06:08 -05:00
|
|
|
#include "branches.hpp"
|
|
|
|
|
#include "strvec.hpp"
|
2025-09-17 23:51:16 -04:00
|
|
|
#include "fs_path.hpp"
|
2014-05-12 12:41:46 -04:00
|
|
|
|
2018-10-12 11:04:33 -04:00
|
|
|
#include <string>
|
2025-05-17 16:35:18 -05:00
|
|
|
#include <memory>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2016-02-12 19:16:04 -05:00
|
|
|
|
2020-12-19 15:06:08 -05:00
|
|
|
namespace Policy
|
2014-05-12 12:41:46 -04:00
|
|
|
{
|
2020-12-19 15:06:08 -05:00
|
|
|
class ActionImpl
|
2014-05-12 12:41:46 -04:00
|
|
|
{
|
2020-12-19 15:06:08 -05:00
|
|
|
public:
|
|
|
|
|
ActionImpl(const std::string &name_)
|
|
|
|
|
: name(name_)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
std::string name;
|
2025-05-17 16:35:18 -05:00
|
|
|
virtual int operator()(const Branches::Ptr&,
|
2025-09-17 23:51:16 -04:00
|
|
|
const fs::path&,
|
2025-05-17 16:35:18 -05:00
|
|
|
std::vector<Branch*>&) const = 0;
|
2019-01-06 12:52:55 -05:00
|
|
|
};
|
2015-06-23 22:24:55 -04:00
|
|
|
|
2020-12-19 15:06:08 -05:00
|
|
|
class Action
|
2019-01-06 12:52:55 -05:00
|
|
|
{
|
2020-12-19 15:06:08 -05:00
|
|
|
public:
|
|
|
|
|
Action(ActionImpl *impl_)
|
|
|
|
|
: impl(impl_)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
Action&
|
|
|
|
|
operator=(ActionImpl *impl_)
|
|
|
|
|
{
|
|
|
|
|
impl = impl_;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const
|
|
|
|
|
std::string&
|
|
|
|
|
name(void) const
|
|
|
|
|
{
|
|
|
|
|
return impl->name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2025-09-18 01:07:28 -04:00
|
|
|
operator()(const Branches::Ptr &branches_,
|
|
|
|
|
const fs::path &fusepath_,
|
|
|
|
|
std::vector<Branch*> &output_) const
|
2020-12-19 15:06:08 -05:00
|
|
|
{
|
2025-05-17 16:35:18 -05:00
|
|
|
return (*impl)(branches_,fusepath_,output_);
|
2020-12-19 15:06:08 -05:00
|
|
|
}
|
|
|
|
|
|
2022-07-09 16:06:18 -04:00
|
|
|
operator bool() const
|
|
|
|
|
{
|
|
|
|
|
return (bool)impl;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-19 15:06:08 -05:00
|
|
|
private:
|
|
|
|
|
ActionImpl *impl;
|
2014-05-12 12:41:46 -04:00
|
|
|
};
|
2019-01-06 12:52:55 -05:00
|
|
|
|
2020-12-19 15:06:08 -05:00
|
|
|
class CreateImpl
|
2019-01-06 12:52:55 -05:00
|
|
|
{
|
2020-12-19 15:06:08 -05:00
|
|
|
public:
|
|
|
|
|
CreateImpl(const std::string &name_)
|
|
|
|
|
: name(name_)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
std::string name;
|
|
|
|
|
virtual bool path_preserving(void) const = 0;
|
2025-05-17 16:35:18 -05:00
|
|
|
virtual int operator()(const Branches::Ptr&,
|
2025-09-18 01:07:28 -04:00
|
|
|
const fs::path&,
|
2025-05-17 16:35:18 -05:00
|
|
|
std::vector<Branch*>&) const = 0;
|
2020-12-19 15:06:08 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Create
|
2019-01-06 12:52:55 -05:00
|
|
|
{
|
2020-12-19 15:06:08 -05:00
|
|
|
public:
|
|
|
|
|
Create(CreateImpl *impl_)
|
|
|
|
|
: impl(impl_)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
Create&
|
|
|
|
|
operator=(CreateImpl *impl_)
|
|
|
|
|
{
|
|
|
|
|
impl = impl_;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const
|
|
|
|
|
std::string&
|
|
|
|
|
name(void) const
|
|
|
|
|
{
|
|
|
|
|
return impl->name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
path_preserving(void) const
|
|
|
|
|
{
|
|
|
|
|
return impl->path_preserving();
|
|
|
|
|
}
|
2019-01-06 12:52:55 -05:00
|
|
|
|
2020-12-19 15:06:08 -05:00
|
|
|
int
|
2025-09-18 01:07:28 -04:00
|
|
|
operator()(const Branches::Ptr &branches_,
|
|
|
|
|
const fs::path &fusepath_,
|
|
|
|
|
std::vector<Branch*> &output_) const
|
2020-12-19 15:06:08 -05:00
|
|
|
{
|
2025-05-17 16:35:18 -05:00
|
|
|
return (*impl)(branches_,fusepath_,output_);
|
2020-12-19 15:06:08 -05:00
|
|
|
}
|
|
|
|
|
|
2022-07-09 16:06:18 -04:00
|
|
|
operator bool() const
|
|
|
|
|
{
|
|
|
|
|
return (bool)impl;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-19 15:06:08 -05:00
|
|
|
private:
|
|
|
|
|
CreateImpl *impl;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class SearchImpl
|
2019-01-06 12:52:55 -05:00
|
|
|
{
|
2020-12-19 15:06:08 -05:00
|
|
|
public:
|
|
|
|
|
SearchImpl(const std::string &name_)
|
|
|
|
|
: name(name_)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
std::string name;
|
2025-05-17 16:35:18 -05:00
|
|
|
virtual int operator()(const Branches::Ptr&,
|
2025-09-18 01:07:28 -04:00
|
|
|
const fs::path&,
|
2025-05-17 16:35:18 -05:00
|
|
|
std::vector<Branch*>&) const = 0;
|
2020-12-19 15:06:08 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Search
|
2019-09-24 10:27:46 -04:00
|
|
|
{
|
2020-12-19 15:06:08 -05:00
|
|
|
public:
|
|
|
|
|
Search(SearchImpl *impl_)
|
|
|
|
|
: impl(impl_)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
Search&
|
|
|
|
|
operator=(SearchImpl *impl_)
|
|
|
|
|
{
|
|
|
|
|
impl = impl_;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const
|
|
|
|
|
std::string&
|
|
|
|
|
name(void) const
|
|
|
|
|
{
|
|
|
|
|
return impl->name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2025-05-17 16:35:18 -05:00
|
|
|
operator()(const Branches::Ptr &branches_,
|
2025-09-18 01:07:28 -04:00
|
|
|
const fs::path &fusepath_,
|
2025-05-17 16:35:18 -05:00
|
|
|
std::vector<Branch*> &output_) const
|
2020-12-19 15:06:08 -05:00
|
|
|
{
|
2025-05-17 16:35:18 -05:00
|
|
|
return (*impl)(branches_,fusepath_,output_);
|
2020-12-19 15:06:08 -05:00
|
|
|
}
|
|
|
|
|
|
2022-07-09 16:06:18 -04:00
|
|
|
operator bool() const
|
|
|
|
|
{
|
|
|
|
|
return (bool)impl;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-19 15:06:08 -05:00
|
|
|
private:
|
|
|
|
|
SearchImpl *impl;
|
|
|
|
|
};
|
2019-09-24 10:27:46 -04:00
|
|
|
}
|