diff options
Diffstat (limited to 'src/mmo/extract.hpp')
-rw-r--r-- | src/mmo/extract.hpp | 68 |
1 files changed, 39 insertions, 29 deletions
diff --git a/src/mmo/extract.hpp b/src/mmo/extract.hpp index 622281b..355e2da 100644 --- a/src/mmo/extract.hpp +++ b/src/mmo/extract.hpp @@ -1,5 +1,4 @@ -#ifndef TMWA_MMO_EXTRACT_HPP -#define TMWA_MMO_EXTRACT_HPP +#pragma once // extract.hpp - a simple, hierarchical, tokenizer // // Copyright © 2012-2013 Ben Longbons <b.r.longbons@gmail.com> @@ -19,14 +18,27 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. -# include "../sanity.hpp" +#include "fwd.hpp" -# include <algorithm> +#include <cerrno> +#include <cstdlib> -# include "../strings/xstring.hpp" +#include <algorithm> +#include <vector> -# include "mmo.hpp" -# include "utils.hpp" +#include "../ints/wrap.hpp" + +#include "../strings/xstring.hpp" + +#include "../generic/enum.hpp" + +#include "utils.hpp" + + +namespace tmwa +{ +template<class T> +bool do_extract(XString str, T t); template<class T, typename=typename std::enable_if<std::is_integral<T>::value && !std::is_same<T, char>::value && !std::is_same<T, bool>::value>::type> bool extract(XString str, T *iv) @@ -94,6 +106,12 @@ bool extract(XString str, VString<N> *out) return true; } +inline +bool extract(XString str, LString exact) +{ + return str == exact; +} + template<class T> class LStripper { @@ -192,31 +210,23 @@ bool extract(XString str, VRecord<split, T> rec) && extract(str.xislice_t(s + 1), rec); } -bool extract(XString str, struct global_reg *var); +bool extract(XString str, GlobalReg *var); -bool extract(XString str, struct item *it); +bool extract(XString str, Item *it); -inline -bool extract(XString str, MapName *m) -{ - XString::iterator it = std::find(str.begin(), str.end(), '.'); - str = str.xislice_h(it); - VString<15> tmp; - bool rv = extract(str, &tmp); - *m = tmp; - return rv; -} +bool extract(XString str, MapName *m); -inline -bool extract(XString str, CharName *out) +bool extract(XString str, CharName *out); + +template<class T> +bool do_extract(XString str, T t) { - VString<23> tmp; - if (extract(str, &tmp)) - { - *out = CharName(tmp); - return true; - } - return false; + return extract(str, t); } -#endif // TMWA_MMO_EXTRACT_HPP +template<class R> +bool extract(XString str, Wrapped<R> *w) +{ + return extract(str, &w->_value); +} +} // namespace tmwa |