2014-05-12 12:41:46 -04:00
|
|
|
/*
|
2020-12-19 15:06:08 -05:00
|
|
|
Copyright (c) 2020, 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"
|
2014-05-12 12:41:46 -04:00
|
|
|
|
2018-10-12 11:04:33 -04:00
|
|
|
#include <string>
|
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;
|
|
|
|
|
virtual int operator()(const Branches::CPtr&,const char*,StrVec*) 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
|
|
|
|
|
operator()(const Branches::CPtr &branches_,
|
|
|
|
|
const char *fusepath_,
|
|
|
|
|
StrVec *paths_) const
|
|
|
|
|
{
|
|
|
|
|
return (*impl)(branches_,fusepath_,paths_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
operator()(const Branches::CPtr &branches_,
|
|
|
|
|
const std::string &fusepath_,
|
|
|
|
|
StrVec *paths_) const
|
|
|
|
|
{
|
|
|
|
|
return (*impl)(branches_,fusepath_.c_str(),paths_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 int operator()(const Branches::CPtr&,const char*,StrVec*) const = 0;
|
|
|
|
|
virtual bool path_preserving(void) const = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
operator()(const Branches::CPtr &branches_,
|
|
|
|
|
const char *fusepath_,
|
|
|
|
|
StrVec *paths_) const
|
|
|
|
|
{
|
|
|
|
|
return (*impl)(branches_,fusepath_,paths_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
operator()(const Branches::CPtr &branches_,
|
|
|
|
|
const std::string &fusepath_,
|
|
|
|
|
StrVec *paths_) const
|
|
|
|
|
{
|
|
|
|
|
return (*impl)(branches_,fusepath_.c_str(),paths_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
virtual int operator()(const Branches::CPtr&,const char*,StrVec*) const = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
operator()(const Branches::CPtr &branches_,
|
|
|
|
|
const char *fusepath_,
|
|
|
|
|
StrVec *paths_) const
|
|
|
|
|
{
|
|
|
|
|
return (*impl)(branches_,fusepath_,paths_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
operator()(const Branches::CPtr &branches_,
|
|
|
|
|
const std::string &fusepath_,
|
|
|
|
|
StrVec *paths_) const
|
|
|
|
|
{
|
|
|
|
|
return (*impl)(branches_,fusepath_.c_str(),paths_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
SearchImpl *impl;
|
|
|
|
|
};
|
2019-09-24 10:27:46 -04:00
|
|
|
}
|