25 #ifndef FABLE_SCHEMA_PATH_HPP_ 26 #define FABLE_SCHEMA_PATH_HPP_ 32 #include <boost/filesystem/path.hpp> 60 using Type = boost::filesystem::path;
76 Path(Type* ptr, std::string&& desc) :
Base(JsonType::string, std::move(desc)), ptr_(ptr) {}
89 return std::move(*
this);
91 void set_state(
State s) { req_state_ = s; }
101 Path not_empty() && {
103 return std::move(*
this);
111 return std::move(*
this);
135 return std::move(*
this);
137 void set_resolve(
bool value) { resolve_ = value; }
139 bool normalize()
const {
return normalize_; }
140 Path normalize(
bool value) && {
142 return std::move(*
this);
144 void set_normalize(
bool value) { normalize_ = value; }
146 bool interpolate()
const {
return interpolate_; }
147 void set_interpolate(
bool value) { interpolate_ = value; }
148 Path interpolate(
bool value) && {
149 interpolate_ = value;
150 return std::move(*
this);
154 void set_environment(
Environment* env) { env_ = env; }
157 return std::move(*
this);
160 size_t min_length()
const {
return min_length_; }
161 void set_min_length(
size_t value) { min_length_ = value; }
162 Path min_length(
size_t value) && {
164 return std::move(*
this);
167 size_t max_length()
const {
return max_length_; }
168 void set_max_length(
size_t value) { max_length_ = value; }
169 Path max_length(
size_t value) && {
171 return std::move(*
this);
174 const std::string& pattern()
const {
return pattern_; }
175 void set_pattern(
const std::string& value) { pattern_ = value; }
176 Path pattern(
const std::string& value) && {
178 return std::move(*
this);
187 assert(ptr_ !=
nullptr);
188 j = serialize(*ptr_);
192 assert(ptr_ !=
nullptr);
193 *ptr_ = deserialize(c);
196 Json serialize(
const Type& x)
const {
return x.native(); }
198 Type deserialize(
const Conf& c)
const;
203 Type resolve_path(
const Conf&,
const Type&)
const;
206 State req_state_{State::Any};
207 bool req_abs_{
false};
209 bool normalize_{
false};
210 bool interpolate_{
false};
211 size_t min_length_{0};
212 size_t max_length_{std::numeric_limits<size_t>::max()};
213 std::string pattern_{};
218 inline Path make_schema(boost::filesystem::path* ptr, std::string&& desc) {
219 return Path(ptr, std::move(desc));
228 struct adl_serializer<
boost::filesystem::path> {
229 static void to_json(json& j,
const boost::filesystem::path& p) { j = p.native(); }
230 static void from_json(
const json& j, boost::filesystem::path& p) { p = j.get<std::string>(); }
235 #endif // FABLE_SCHEMA_PATH_HPP_ path does not exist or is a directory
State state() const
Definition: path.hpp:82
Path absolute() &&
Definition: path.hpp:109
path exists and is a directory
State
Definition: path.hpp:65
path exists and is a file
Path state(State s) &&
Definition: path.hpp:87
nlohmann::json Json
Definition: json.hpp:62
void from_conf(const Conf &c) override
Definition: path.hpp:191
Definition: confable.hpp:132
Definition: environment.hpp:37
void to_json(Json &j) const override
Definition: path.hpp:186
path exists in search path or locally and has executable permission
bool resolve() const
Definition: path.hpp:119
virtual Json to_json() const
Definition: interface.hpp:220
Json json_schema() const override
Definition: path.cpp:65
void reset_ptr() override
Definition: path.hpp:200
void validate(const Conf &c) const override
Definition: path.cpp:87
Definition: interface.hpp:354
Path resolve(bool value) &&
Definition: path.hpp:133