mirror of https://github.com/trapexit/mergerfs.git
Browse Source
rework config management
rework config management
* Add standard way to do str2val and val2str conversion * Add support for a config file * Add support for reading and writing settings via ioctlpull/766/head
Antonio SJ Musumeci
5 years ago
90 changed files with 3250 additions and 2577 deletions
-
10Makefile
-
38README.md
-
7libfuse/Makefile
-
22libfuse/include/fuse.h
-
10libfuse/include/fuse_common.h
-
13libfuse/include/fuse_lowlevel.h
-
186libfuse/lib/fuse.c
-
45libfuse/lib/fuse_lowlevel.c
-
69man/mergerfs.1
-
239src/branch.cpp
-
39src/branch.hpp
-
430src/config.cpp
-
174src/config.hpp
-
9src/dirinfo.hpp
-
21src/ef.hpp
-
78src/enum.hpp
-
31src/fh.hpp
-
9src/fileinfo.hpp
-
115src/from_string.cpp
-
32src/from_string.hpp
-
39src/func.cpp
-
221src/func.hpp
-
90src/func_category.cpp
-
69src/func_category.hpp
-
46src/funcs.hpp
-
16src/fuse_access.cpp
-
14src/fuse_chmod.cpp
-
14src/fuse_chown.cpp
-
30src/fuse_create.cpp
-
16src/fuse_fgetattr.cpp
-
7src/fuse_fgetattr.hpp
-
23src/fuse_getattr.cpp
-
5src/fuse_getattr.hpp
-
362src/fuse_getxattr.cpp
-
18src/fuse_init.cpp
-
227src/fuse_ioctl.cpp
-
2src/fuse_ioctl.hpp
-
50src/fuse_link.cpp
-
68src/fuse_listxattr.cpp
-
34src/fuse_mkdir.cpp
-
24src/fuse_mknod.cpp
-
16src/fuse_open.cpp
-
2src/fuse_opendir.cpp
-
4src/fuse_readdir_linux.icpp
-
12src/fuse_readdir_plus_linux.icpp
-
4src/fuse_readdir_plus_posix.icpp
-
4src/fuse_readdir_posix.icpp
-
12src/fuse_readlink.cpp
-
2src/fuse_release.cpp
-
20src/fuse_removexattr.cpp
-
74src/fuse_rename.cpp
-
14src/fuse_rmdir.cpp
-
436src/fuse_setxattr.cpp
-
16src/fuse_statfs.cpp
-
24src/fuse_symlink.cpp
-
14src/fuse_truncate.cpp
-
14src/fuse_unlink.cpp
-
15src/fuse_utimens.cpp
-
5src/fuse_write.cpp
-
43src/fuse_write_buf.cpp
-
95src/fusefunc.cpp
-
125src/fusefunc.hpp
-
35src/hw_cpu.cpp
-
27src/hw_cpu.hpp
-
16src/mergerfs.cpp
-
490src/option_parser.cpp
-
6src/option_parser.hpp
-
64src/policy.hpp
-
27src/policy_all.cpp
-
2src/policy_cache.cpp
-
27src/policy_epall.cpp
-
51src/policy_epff.cpp
-
21src/policy_eplfs.cpp
-
21src/policy_eplus.cpp
-
51src/policy_epmfs.cpp
-
6src/policy_eprand.cpp
-
8src/policy_erofs.cpp
-
9src/policy_ff.cpp
-
2src/policy_invalid.cpp
-
13src/policy_lfs.cpp
-
9src/policy_lus.cpp
-
13src/policy_mfs.cpp
-
21src/policy_newest.cpp
-
6src/policy_rand.cpp
-
45src/str.cpp
-
15src/str.hpp
-
58src/to_string.cpp
-
31src/to_string.hpp
-
47src/tofrom_string.hpp
-
131src/tofrom_wrapper.hpp
@ -0,0 +1,21 @@ |
|||
/*
|
|||
ISC License |
|||
|
|||
Copyright (c) 2019, Antonio SJ Musumeci <trapexit@spawn.link> |
|||
|
|||
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. |
|||
*/ |
|||
|
|||
#pragma once
|
|||
|
|||
#define ef(X) else if(X)
|
@ -0,0 +1,78 @@ |
|||
/*
|
|||
ISC License |
|||
|
|||
Copyright (c) 2019, Antonio SJ Musumeci <trapexit@spawn.link> |
|||
|
|||
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. |
|||
*/ |
|||
|
|||
#include "tofrom_string.hpp"
|
|||
|
|||
#include <string>
|
|||
|
|||
template<typename E> |
|||
class Enum : public ToFromString |
|||
{ |
|||
public: |
|||
typedef E ENUM; |
|||
|
|||
public: |
|||
Enum<ENUM>() |
|||
{ |
|||
} |
|||
|
|||
Enum<ENUM>(const ENUM data_) |
|||
: _data(data_) |
|||
{ |
|||
} |
|||
|
|||
public: |
|||
Enum<ENUM>& |
|||
operator=(const ENUM data_) |
|||
{ |
|||
_data = data_; |
|||
return *this; |
|||
} |
|||
|
|||
Enum<ENUM>& |
|||
operator=(const std::string &s_) |
|||
{ |
|||
from_string(s_); |
|||
return *this; |
|||
} |
|||
|
|||
public: |
|||
operator ENUM() const |
|||
{ |
|||
return _data; |
|||
} |
|||
|
|||
public: |
|||
bool operator==(const ENUM data_) const |
|||
{ |
|||
return (_data == data_); |
|||
} |
|||
|
|||
public: |
|||
std::string to_string() const; |
|||
int from_string(const std::string &); |
|||
|
|||
public: |
|||
int to_int() const |
|||
{ |
|||
return (int)_data; |
|||
} |
|||
|
|||
private: |
|||
ENUM _data; |
|||
}; |
@ -0,0 +1,31 @@ |
|||
/*
|
|||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|||
|
|||
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. |
|||
*/ |
|||
|
|||
#pragma once
|
|||
|
|||
#include <string>
|
|||
|
|||
class FH |
|||
{ |
|||
public: |
|||
FH(const char *fusepath_) |
|||
: fusepath(fusepath_) |
|||
{ |
|||
} |
|||
|
|||
public: |
|||
std::string fusepath; |
|||
}; |
@ -0,0 +1,115 @@ |
|||
/*
|
|||
ISC License |
|||
|
|||
Copyright (c) 2019, Antonio SJ Musumeci <trapexit@spawn.link> |
|||
|
|||
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. |
|||
*/ |
|||
|
|||
#include "ef.hpp"
|
|||
|
|||
#include <string>
|
|||
|
|||
#include <errno.h>
|
|||
#include <stdint.h>
|
|||
#include <stdlib.h>
|
|||
|
|||
namespace str |
|||
{ |
|||
int |
|||
from(const std::string &value_, |
|||
bool *bool_) |
|||
{ |
|||
if((value_ == "true") || |
|||
(value_ == "1") || |
|||
(value_ == "on") || |
|||
(value_ == "yes")) |
|||
*bool_ = true; |
|||
ef((value_ == "false") || |
|||
(value_ == "0") || |
|||
(value_ == "off") || |
|||
(value_ == "no")) |
|||
*bool_ = false; |
|||
else |
|||
return -EINVAL; |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
int |
|||
from(const std::string &value_, |
|||
int *int_) |
|||
{ |
|||
*int_ = ::strtol(value_.c_str(),NULL,10); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
int |
|||
from(const std::string &value_, |
|||
uint64_t *uint64_) |
|||
{ |
|||
char *endptr; |
|||
uint64_t tmp; |
|||
|
|||
tmp = ::strtoll(value_.c_str(),&endptr,10); |
|||
switch(*endptr) |
|||
{ |
|||
case 'k': |
|||
case 'K': |
|||
tmp *= 1024; |
|||
break; |
|||
|
|||
case 'm': |
|||
case 'M': |
|||
tmp *= (1024 * 1024); |
|||
break; |
|||
|
|||
case 'g': |
|||
case 'G': |
|||
tmp *= (1024 * 1024 * 1024); |
|||
break; |
|||
|
|||
case 't': |
|||
case 'T': |
|||
tmp *= (1024ULL * 1024 * 1024 * 1024); |
|||
break; |
|||
|
|||
case '\0': |
|||
break; |
|||
|
|||
default: |
|||
return -EINVAL; |
|||
} |
|||
|
|||
*uint64_ = tmp; |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
int |
|||
from(const std::string &value_, |
|||
std::string *str_) |
|||
{ |
|||
*str_ = value_; |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
int |
|||
from(const std::string &value_, |
|||
const std::string *key_) |
|||
{ |
|||
return -EINVAL; |
|||
} |
|||
} |
@ -0,0 +1,32 @@ |
|||
/*
|
|||
ISC License |
|||
|
|||
Copyright (c) 2019, Antonio SJ Musumeci <trapexit@spawn.link> |
|||
|
|||
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. |
|||
*/ |
|||
|
|||
#pragma once
|
|||
|
|||
#include <string>
|
|||
|
|||
#include <stdint.h>
|
|||
|
|||
namespace str |
|||
{ |
|||
int from(const std::string &, bool *); |
|||
int from(const std::string &, int *); |
|||
int from(const std::string &, uint64_t *); |
|||
int from(const std::string &, std::string *); |
|||
int from(const std::string &, const std::string *); |
|||
} |
@ -0,0 +1,39 @@ |
|||
/*
|
|||
ISC License |
|||
|
|||
Copyright (c) 2019, Antonio SJ Musumeci <trapexit@spawn.link> |
|||
|
|||
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. |
|||
*/ |
|||
|
|||
#include "func.hpp"
|
|||
|
|||
int |
|||
Func::from_string(const std::string &s_) |
|||
{ |
|||
const Policy *tmp; |
|||
|
|||
tmp = &Policy::find(s_); |
|||
if(tmp == Policy::invalid) |
|||
return -EINVAL; |
|||
|
|||
policy = tmp; |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
std::string |
|||
Func::to_string(void) const |
|||
{ |
|||
return policy->to_string(); |
|||
} |
@ -0,0 +1,221 @@ |
|||
/*
|
|||
ISC License |
|||
|
|||
Copyright (c) 2019, Antonio SJ Musumeci <trapexit@spawn.link> |
|||
|
|||
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. |
|||
*/ |
|||
|
|||
#pragma once
|
|||
|
|||
#include "policy.hpp"
|
|||
#include "tofrom_string.hpp"
|
|||
|
|||
#include <string>
|
|||
#include <iostream>
|
|||
|
|||
class Func : public ToFromString |
|||
{ |
|||
public: |
|||
Func(const Policy &policy_) |
|||
: policy(&policy_) |
|||
{ |
|||
} |
|||
|
|||
public: |
|||
int from_string(const std::string &s); |
|||
std::string to_string() const; |
|||
|
|||
public: |
|||
const Policy *policy; |
|||
}; |
|||
|
|||
class FuncAccess : public Func |
|||
{ |
|||
public: |
|||
FuncAccess() |
|||
: Func(Policy::ff) |
|||
{ |
|||
} |
|||
}; |
|||
|
|||
class FuncChmod : public Func |
|||
{ |
|||
public: |
|||
FuncChmod() |
|||
: Func(Policy::epall) |
|||
{ |
|||
} |
|||
}; |
|||
|
|||
class FuncChown : public Func |
|||
{ |
|||
public: |
|||
FuncChown() |
|||
: Func(Policy::epall) |
|||
{ |
|||
} |
|||
}; |
|||
|
|||
class FuncCreate : public Func |
|||
{ |
|||
public: |
|||
FuncCreate() |
|||
: Func(Policy::epmfs) |
|||
{ |
|||
} |
|||
}; |
|||
|
|||
class FuncGetAttr : public Func |
|||
{ |
|||
public: |
|||
FuncGetAttr() |
|||
: Func(Policy::ff) |
|||
{ |
|||
} |
|||
}; |
|||
|
|||
class FuncGetXAttr : public Func |
|||
{ |
|||
public: |
|||
FuncGetXAttr() |
|||
: Func(Policy::ff) |
|||
{ |
|||
} |
|||
}; |
|||
|
|||
class FuncLink : public Func |
|||
{ |
|||
public: |
|||
FuncLink() |
|||
: Func(Policy::epall) |
|||
{ |
|||
} |
|||
}; |
|||
|
|||
class FuncListXAttr : public Func |
|||
{ |
|||
public: |
|||
FuncListXAttr() |
|||
: Func(Policy::ff) |
|||
{ |
|||
} |
|||
}; |
|||
|
|||
class FuncMkdir : public Func |
|||
{ |
|||
public: |
|||
FuncMkdir() |
|||
: Func(Policy::epmfs) |
|||
{ |
|||
} |
|||
}; |
|||
|
|||
class FuncMknod : public Func |
|||
{ |
|||
public: |
|||
FuncMknod() |
|||
: Func(Policy::epmfs) |
|||
{ |
|||
} |
|||
}; |
|||
|
|||
class FuncOpen : public Func |
|||
{ |
|||
public: |
|||
FuncOpen() |
|||
: Func(Policy::ff) |
|||
{ |
|||
} |
|||
}; |
|||
|
|||
class FuncReadlink : public Func |
|||
{ |
|||
public: |
|||
FuncReadlink() |
|||
: Func(Policy::ff) |
|||
{ |
|||
} |
|||
}; |
|||
|
|||
class FuncRemoveXAttr : public Func |
|||
{ |
|||
public: |
|||
FuncRemoveXAttr() |
|||
: Func(Policy::epall) |
|||
{ |
|||
} |
|||
}; |
|||
|
|||
class FuncRename : public Func |
|||
{ |
|||
public: |
|||
FuncRename() |
|||
: Func(Policy::epall) |
|||
{ |
|||
} |
|||
}; |
|||
|
|||
class FuncRmdir : public Func |
|||
{ |
|||
public: |
|||
FuncRmdir() |
|||
: Func(Policy::epall) |
|||
{ |
|||
} |
|||
}; |
|||
|
|||
class FuncSetXAttr : public Func |
|||
{ |
|||
public: |
|||
FuncSetXAttr() |
|||
: Func(Policy::epall) |
|||
{ |
|||
} |
|||
}; |
|||
|
|||
class FuncSymlink : public Func |
|||
{ |
|||
public: |
|||
FuncSymlink() |
|||
: Func(Policy::epmfs) |
|||
{ |
|||
} |
|||
}; |
|||
|
|||
class FuncTruncate : public Func |
|||
{ |
|||
public: |
|||
FuncTruncate() |
|||
: Func(Policy::epall) |
|||
{ |
|||
} |
|||
}; |
|||
|
|||
class FuncUnlink : public Func |
|||
{ |
|||
public: |
|||
FuncUnlink() |
|||
: Func(Policy::epall) |
|||
{ |
|||
} |
|||
}; |
|||
|
|||
class FuncUtimens : public Func |
|||
{ |
|||
public: |
|||
FuncUtimens() |
|||
: Func(Policy::epall) |
|||
{ |
|||
} |
|||
}; |
@ -0,0 +1,90 @@ |
|||
/*
|
|||
ISC License |
|||
|
|||
Copyright (c) 2019, Antonio SJ Musumeci <trapexit@spawn.link> |
|||
|
|||
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. |
|||
*/ |
|||
|
|||
#include "func_category.hpp"
|
|||
#include "str.hpp"
|
|||
|
|||
#include "buildvector.hpp"
|
|||
|
|||
#include <algorithm>
|
|||
#include <string>
|
|||
#include <vector>
|
|||
|
|||
int |
|||
FuncCategory::from_string(const std::string &s_) |
|||
{ |
|||
const Policy *tmp; |
|||
|
|||
tmp = &Policy::find(s_); |
|||
if(tmp == &Policy::invalid) |
|||
return -EINVAL; |
|||
|
|||
for(uint64_t i = 0; i < _funcs.size(); i++) |
|||
_funcs[i]->policy = tmp; |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
std::string |
|||
FuncCategory::to_string(void) const |
|||
{ |
|||
std::vector<std::string> rv; |
|||
|
|||
for(uint64_t i = 0; i < _funcs.size(); i++) |
|||
rv.push_back(_funcs[i]->policy->to_string()); |
|||
|
|||
std::sort(rv.begin(),rv.end()); |
|||
rv.erase(std::unique(rv.begin(),rv.end()),rv.end()); |
|||
|
|||
return str::join(rv,','); |
|||
} |
|||
|
|||
FuncCategoryCreate::FuncCategoryCreate(Funcs &funcs_) |
|||
{ |
|||
_funcs = buildvector<Func*> |
|||
(&funcs_.create) |
|||
(&funcs_.mkdir) |
|||
(&funcs_.mknod) |
|||
(&funcs_.symlink); |
|||
} |
|||
|
|||
FuncCategoryAction::FuncCategoryAction(Funcs &funcs_) |
|||
{ |
|||
_funcs = buildvector<Func*> |
|||
(&funcs_.chmod) |
|||
(&funcs_.chown) |
|||
(&funcs_.link) |
|||
(&funcs_.removexattr) |
|||
(&funcs_.rename) |
|||
(&funcs_.rmdir) |
|||
(&funcs_.setxattr) |
|||
(&funcs_.truncate) |
|||
(&funcs_.unlink) |
|||
(&funcs_.utimens); |
|||
} |
|||
|
|||
FuncCategorySearch::FuncCategorySearch(Funcs &funcs_) |
|||
{ |
|||
_funcs = buildvector<Func*> |
|||
(&funcs_.access) |
|||
(&funcs_.getattr) |
|||
(&funcs_.getxattr) |
|||
(&funcs_.listxattr) |
|||
(&funcs_.open) |
|||
(&funcs_.readlink); |
|||
} |
@ -0,0 +1,69 @@ |
|||
/*
|
|||
ISC License |
|||
|
|||
Copyright (c) 2019, Antonio SJ Musumeci <trapexit@spawn.link> |
|||
|
|||
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. |
|||
*/ |
|||
|
|||
#pragma once
|
|||
|
|||
#include "funcs.hpp"
|
|||
#include "tofrom_string.hpp"
|
|||
|
|||
#include <string>
|
|||
#include <vector>
|
|||
|
|||
class FuncCategory : public ToFromString |
|||
{ |
|||
public: |
|||
int from_string(const std::string &); |
|||
std::string to_string(void) const; |
|||
|
|||
protected: |
|||
std::vector<Func*> _funcs; |
|||
}; |
|||
|
|||
class FuncCategoryCreate : public FuncCategory |
|||
{ |
|||
public: |
|||
FuncCategoryCreate(Funcs &funcs_); |
|||
}; |
|||
|
|||
class FuncCategoryAction : public FuncCategory |
|||
{ |
|||
public: |
|||
FuncCategoryAction(Funcs &funcs_); |
|||
}; |
|||
|
|||
class FuncCategorySearch : public FuncCategory |
|||
{ |
|||
public: |
|||
FuncCategorySearch(Funcs &funcs_); |
|||
}; |
|||
|
|||
class FuncCategories |
|||
{ |
|||
public: |
|||
FuncCategories(Funcs &funcs_) |
|||
: action(funcs_), |
|||
create(funcs_), |
|||
search(funcs_) |
|||
{ |
|||
} |
|||
|
|||
public: |
|||
FuncCategoryAction action; |
|||
FuncCategoryCreate create; |
|||
FuncCategorySearch search; |
|||
}; |
@ -0,0 +1,46 @@ |
|||
/*
|
|||
ISC License |
|||
|
|||
Copyright (c) 2019, Antonio SJ Musumeci <trapexit@spawn.link> |
|||
|
|||
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. |
|||
*/ |
|||
|
|||
#pragma once
|
|||
|
|||
#include "func.hpp"
|
|||
|
|||
class Funcs |
|||
{ |
|||
public: |
|||
FuncAccess access; |
|||
FuncChmod chmod; |
|||
FuncChown chown; |
|||
FuncCreate create; |
|||
FuncGetAttr getattr; |
|||
FuncGetXAttr getxattr; |
|||
FuncLink link; |
|||
FuncListXAttr listxattr; |
|||
FuncMkdir mkdir; |
|||
FuncMknod mknod; |
|||
FuncOpen open; |
|||
FuncReadlink readlink; |
|||
FuncRemoveXAttr removexattr; |
|||
FuncRename rename; |
|||
FuncRmdir rmdir; |
|||
FuncSetXAttr setxattr; |
|||
FuncSymlink symlink; |
|||
FuncTruncate truncate; |
|||
FuncUnlink unlink; |
|||
FuncUtimens utimens; |
|||
}; |
@ -1,95 +0,0 @@ |
|||
/*
|
|||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|||
|
|||
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. |
|||
*/ |
|||
|
|||
#include <string>
|
|||
#include <vector>
|
|||
|
|||
#include "buildvector.hpp"
|
|||
#include "category.hpp"
|
|||
#include "fusefunc.hpp"
|
|||
|
|||
#define FUSEFUNC(X,Y) FuseFunc(FuseFunc::Enum::X,#X,Category::Enum::Y)
|
|||
|
|||
const std::vector<FuseFunc> FuseFunc::_fusefuncs_ = |
|||
buildvector<FuseFunc,true> |
|||
(FUSEFUNC(invalid,invalid)) |
|||
(FUSEFUNC(access,search)) |
|||
(FUSEFUNC(chmod,action)) |
|||
(FUSEFUNC(chown,action)) |
|||
(FUSEFUNC(create,create)) |
|||
(FUSEFUNC(getattr,search)) |
|||
(FUSEFUNC(getxattr,search)) |
|||
(FUSEFUNC(link,action)) |
|||
(FUSEFUNC(listxattr,search)) |
|||
(FUSEFUNC(mkdir,create)) |
|||
(FUSEFUNC(mknod,create)) |
|||
(FUSEFUNC(open,search)) |
|||
(FUSEFUNC(readlink,search)) |
|||
(FUSEFUNC(removexattr,action)) |
|||
(FUSEFUNC(rename,action)) |
|||
(FUSEFUNC(rmdir,action)) |
|||
(FUSEFUNC(setxattr,action)) |
|||
(FUSEFUNC(symlink,create)) |
|||
(FUSEFUNC(truncate,action)) |
|||
(FUSEFUNC(unlink,action)) |
|||
(FUSEFUNC(utimens,action)) |
|||
; |
|||
|
|||
const FuseFunc * const FuseFunc::fusefuncs = &_fusefuncs_[1]; |
|||
|
|||
const FuseFunc &FuseFunc::invalid = FuseFunc::fusefuncs[FuseFunc::Enum::invalid]; |
|||
const FuseFunc &FuseFunc::access = FuseFunc::fusefuncs[FuseFunc::Enum::access]; |
|||
const FuseFunc &FuseFunc::chmod = FuseFunc::fusefuncs[FuseFunc::Enum::chmod]; |
|||
const FuseFunc &FuseFunc::chown = FuseFunc::fusefuncs[FuseFunc::Enum::chown]; |
|||
const FuseFunc &FuseFunc::create = FuseFunc::fusefuncs[FuseFunc::Enum::create]; |
|||
const FuseFunc &FuseFunc::getattr = FuseFunc::fusefuncs[FuseFunc::Enum::getattr]; |
|||
const FuseFunc &FuseFunc::getxattr = FuseFunc::fusefuncs[FuseFunc::Enum::getxattr]; |
|||
const FuseFunc &FuseFunc::link = FuseFunc::fusefuncs[FuseFunc::Enum::link]; |
|||
const FuseFunc &FuseFunc::listxattr = FuseFunc::fusefuncs[FuseFunc::Enum::listxattr]; |
|||
const FuseFunc &FuseFunc::mkdir = FuseFunc::fusefuncs[FuseFunc::Enum::mkdir]; |
|||
const FuseFunc &FuseFunc::mknod = FuseFunc::fusefuncs[FuseFunc::Enum::mknod]; |
|||
const FuseFunc &FuseFunc::open = FuseFunc::fusefuncs[FuseFunc::Enum::open]; |
|||
const FuseFunc &FuseFunc::readlink = FuseFunc::fusefuncs[FuseFunc::Enum::readlink]; |
|||
const FuseFunc &FuseFunc::removexattr = FuseFunc::fusefuncs[FuseFunc::Enum::removexattr]; |
|||
const FuseFunc &FuseFunc::rmdir = FuseFunc::fusefuncs[FuseFunc::Enum::rmdir]; |
|||
const FuseFunc &FuseFunc::setxattr = FuseFunc::fusefuncs[FuseFunc::Enum::setxattr]; |
|||
const FuseFunc &FuseFunc::symlink = FuseFunc::fusefuncs[FuseFunc::Enum::symlink]; |
|||
const FuseFunc &FuseFunc::truncate = FuseFunc::fusefuncs[FuseFunc::Enum::truncate]; |
|||
const FuseFunc &FuseFunc::unlink = FuseFunc::fusefuncs[FuseFunc::Enum::unlink]; |
|||
const FuseFunc &FuseFunc::utimens = FuseFunc::fusefuncs[FuseFunc::Enum::utimens]; |
|||
|
|||
const |
|||
FuseFunc& |
|||
FuseFunc::find(const std::string &str) |
|||
{ |
|||
for(int i = Enum::BEGIN; i != Enum::END; ++i) |
|||
{ |
|||
if(fusefuncs[i] == str) |
|||
return fusefuncs[i]; |
|||
} |
|||
|
|||
return invalid; |
|||
} |
|||
|
|||
const |
|||
FuseFunc& |
|||
FuseFunc::find(const FuseFunc::Enum::Type i) |
|||
{ |
|||
if((i >= FuseFunc::Enum::BEGIN) && (i < FuseFunc::Enum::END)) |
|||
return fusefuncs[i]; |
|||
|
|||
return invalid; |
|||
} |
@ -1,125 +0,0 @@ |
|||
/*
|
|||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|||
|
|||
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. |
|||
*/ |
|||
|
|||
#pragma once
|
|||
|
|||
#include "category.hpp"
|
|||
|
|||
#include <string>
|
|||
#include <vector>
|
|||
|
|||
class FuseFunc |
|||
{ |
|||
public: |
|||
struct Enum |
|||
{ |
|||
enum Type |
|||
{ |
|||
invalid = -1, |
|||
BEGIN = 0, |
|||
access = BEGIN, |
|||
chmod, |
|||
chown, |
|||
create, |
|||
getattr, |
|||
getxattr, |
|||
link, |
|||
listxattr, |
|||
mkdir, |
|||
mknod, |
|||
open, |
|||
readlink, |
|||
removexattr, |
|||
rename, |
|||
rmdir, |
|||
setxattr, |
|||
symlink, |
|||
truncate, |
|||
unlink, |
|||
utimens, |
|||
END |
|||
}; |
|||
}; |
|||
|
|||
private: |
|||
Enum::Type _enum; |
|||
std::string _str; |
|||
Category::Enum::Type _category; |
|||
|
|||
public: |
|||
FuseFunc() |
|||
: _enum(invalid), |
|||
_str(invalid), |
|||
_category(Category::Enum::invalid) |
|||
{ |
|||
} |
|||
|
|||
FuseFunc(const Enum::Type enum_, |
|||
const std::string &str_, |
|||
const Category::Enum::Type category_) |
|||
: _enum(enum_), |
|||
_str(str_), |
|||
_category(category_) |
|||
{ |
|||
} |
|||
|
|||
public: |
|||
operator const Enum::Type() const { return _enum; } |
|||
operator const std::string&() const { return _str; } |
|||
operator const Category::Enum::Type() const { return _category; } |
|||
operator const FuseFunc*() const { return this; } |
|||
|
|||
bool operator==(const std::string &str_) const |
|||
{ return _str == str_; } |
|||
|
|||
bool operator==(const Enum::Type enum_) const |
|||
{ return _enum == enum_; } |
|||
|
|||
bool operator!=(const FuseFunc &r) const |
|||
{ return _enum != r._enum; } |
|||
|
|||
bool operator<(const FuseFunc &r) const |
|||
{ return _enum < r._enum; } |
|||
|
|||
public: |
|||
static const FuseFunc &find(const std::string&); |
|||
static const FuseFunc &find(const Enum::Type); |
|||
|
|||
public: |
|||
static const std::vector<FuseFunc> _fusefuncs_; |
|||
static const FuseFunc * const fusefuncs; |
|||
static const FuseFunc &invalid; |
|||
static const FuseFunc &access; |
|||
static const FuseFunc &chmod; |
|||
static const FuseFunc &chown; |
|||
static const FuseFunc &create; |
|||
static const FuseFunc &getattr; |
|||
static const FuseFunc &getxattr; |
|||
static const FuseFunc &link; |
|||
static const FuseFunc &listxattr; |
|||
static const FuseFunc &mkdir; |
|||
static const FuseFunc &mknod; |
|||
static const FuseFunc &open; |
|||
static const FuseFunc &readlink; |
|||
static const FuseFunc &removexattr; |
|||
static const FuseFunc &rename; |
|||
static const FuseFunc &rmdir; |
|||
static const FuseFunc &setxattr; |
|||
static const FuseFunc &symlink; |
|||
static const FuseFunc &truncate; |
|||
static const FuseFunc &unlink; |
|||
static const FuseFunc &utimens; |
|||
}; |
@ -0,0 +1,35 @@ |
|||
/*
|
|||
ISC License |
|||
|
|||
Copyright (c) 2019, Antonio SJ Musumeci <trapexit@spawn.link> |
|||
|
|||
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. |
|||
*/ |
|||
|
|||
#include <unistd.h>
|
|||
|
|||
namespace hw |
|||
{ |
|||
namespace cpu |
|||
{ |
|||
int |
|||
logical_core_count(void) |
|||
{ |
|||
#if defined _SC_NPROCESSORS_ONLN
|
|||
return ::sysconf(_SC_NPROCESSORS_ONLN); |
|||
#else
|
|||
return 1; |
|||
#endif
|
|||
} |
|||
} |
|||
} |
@ -0,0 +1,27 @@ |
|||
/*
|
|||
ISC License |
|||
|
|||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|||
|
|||
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. |
|||
*/ |
|||
|
|||
#pragma once
|
|||
|
|||
namespace hw |
|||
{ |
|||
namespace cpu |
|||
{ |
|||
int logical_core_count(void); |
|||
} |
|||
} |
@ -0,0 +1,58 @@ |
|||
/*
|
|||
ISC License |
|||
|
|||
Copyright (c) 2019, Antonio SJ Musumeci <trapexit@spawn.link> |
|||
|
|||
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. |
|||
*/ |
|||
|
|||
#include <string>
|
|||
|
|||
#include <inttypes.h>
|
|||
#include <stdint.h>
|
|||
#include <stdio.h>
|
|||
|
|||
namespace str |
|||
{ |
|||
std::string |
|||
to(const bool bool_) |
|||
{ |
|||
return (bool_ ? "true" : "false"); |
|||
} |
|||
|
|||
std::string |
|||
to(const int int_) |
|||
{ |
|||
char buf[24]; |
|||
|
|||
sprintf(buf,"%d",int_); |
|||
|
|||
return buf; |
|||
} |
|||
|
|||
std::string |
|||
to(const uint64_t uint64_) |
|||
{ |
|||
char buf[64]; |
|||
|
|||
sprintf(buf,"%llu",(unsigned long long)uint64_); |
|||
|
|||
return buf; |
|||
} |
|||
|
|||
std::string |
|||
to(const std::string &s_) |
|||
{ |
|||
return s_; |
|||
} |
|||
} |
@ -0,0 +1,31 @@ |
|||
/*
|
|||
ISC License |
|||
|
|||
Copyright (c) 2019, Antonio SJ Musumeci <trapexit@spawn.link> |
|||
|
|||
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. |
|||
*/ |
|||
|
|||
#pragma once
|
|||
|
|||
#include <string>
|
|||
|
|||
#include <stdint.h>
|
|||
|
|||
namespace str |
|||
{ |
|||
std::string to(const bool); |
|||
std::string to(const int); |
|||
std::string to(const uint64_t); |
|||
std::string to(const std::string&); |
|||
} |
@ -0,0 +1,47 @@ |
|||
/*
|
|||
ISC License |
|||
|
|||
Copyright (c) 2019, Antonio SJ Musumeci <trapexit@spawn.link> |
|||
|
|||
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. |
|||
*/ |
|||
|
|||
#pragma once
|
|||
|
|||
#include <string>
|
|||
|
|||
class ToFromString |
|||
{ |
|||
public: |
|||
virtual std::string to_string() const = 0; |
|||
virtual int from_string(const std::string &) = 0; |
|||
}; |
|||
|
|||
namespace std |
|||
{ |
|||
inline |
|||
static |
|||
std::string |
|||
to_string(const ToFromString *o_) |
|||
{ |
|||
return o_->to_string(); |
|||
} |
|||
|
|||
inline |
|||
static |
|||
std::string |
|||
to_string(const ToFromString &o_) |
|||
{ |
|||
return o_.to_string(); |
|||
} |
|||
} |
@ -0,0 +1,131 @@ |
|||
/*
|
|||
ISC License |
|||
|
|||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|||
|
|||
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. |
|||
*/ |
|||
|
|||
#pragma once
|
|||
|
|||
#include "from_string.hpp"
|
|||
#include "to_string.hpp"
|
|||
#include "tofrom_string.hpp"
|
|||
|
|||
#include <errno.h>
|
|||
|
|||
template<typename T> |
|||
class ToFromWrapper : public ToFromString |
|||
{ |
|||
public: |
|||
int |
|||
from_string(const std::string &s_) |
|||
{ |
|||
return str::from(s_,&_data); |
|||
} |
|||
|
|||
std::string |
|||
to_string(void) const |
|||
{ |
|||
return str::to(_data); |
|||
} |
|||
|
|||
public: |
|||
ToFromWrapper<T>() |
|||
{ |
|||
} |
|||
|
|||
ToFromWrapper<T>(const T data_) |
|||
: _data(data_) |
|||
{ |
|||
} |
|||
|
|||
public: |
|||
ToFromWrapper<T>& |
|||
operator=(const T data_) |
|||
{ |
|||
_data = data_; |
|||
return *this; |
|||
} |
|||
|
|||
public: |
|||
operator T() const |
|||
{ |
|||
return _data; |
|||
} |
|||
|
|||
T* |
|||
operator->() |
|||
{ |
|||
return &_data; |
|||
} |
|||
|
|||
public: |
|||
bool |
|||
operator==(const T data_) const |
|||
{ |
|||
return (_data == data_); |
|||
} |
|||
|
|||
private: |
|||
T _data; |
|||
}; |
|||
|
|||
template<typename T> |
|||
class ROToFromWrapper : public ToFromString |
|||
{ |
|||
public: |
|||
int |
|||
from_string(const std::string &s_) |
|||
{ |
|||
return -EINVAL; |
|||
} |
|||
|
|||
std::string |
|||
to_string(void) const |
|||
{ |
|||
return str::to(_data); |
|||
} |
|||
|
|||
public: |
|||
ROToFromWrapper<T>() |
|||
{ |
|||
} |
|||
|
|||
ROToFromWrapper<T>(const T data_) |
|||
: _data(data_) |
|||
{ |
|||
} |
|||
|
|||
public: |
|||
operator T() const |
|||
{ |
|||
return _data; |
|||
} |
|||
|
|||
T* |
|||
operator->() |
|||
{ |
|||
return &_data; |
|||
} |
|||
|
|||
public: |
|||
bool |
|||
operator==(const T data_) const |
|||
{ |
|||
return (_data == data_); |
|||
} |
|||
|
|||
private: |
|||
T _data; |
|||
}; |
Write
Preview
Loading…
Cancel
Save
Reference in new issue