From b2f0d495cd85188e0f9f2d4d363655da40e6e5e6 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Thu, 22 Jan 2015 12:25:18 -0800 Subject: Have I mentioned that I hate ADL? --- src/char/char.cpp | 6 ++--- src/char/int_party.cpp | 2 +- src/char/int_storage.cpp | 2 +- src/char/inter.cpp | 2 +- src/high/extract_mmo.cpp | 10 ++++---- src/high/extract_mmo.hpp | 10 ++++---- src/io/extract.cpp | 20 +++++++-------- src/io/extract.hpp | 54 +++++++++++++++++++++------------------- src/login/login.cpp | 2 +- src/map/mapflag.cpp | 2 +- src/map/mapflag.hpp | 2 +- src/map/mob.cpp | 8 +++--- src/map/script-fun.cpp | 1 + src/mmo/config_parse.cpp | 1 + src/mmo/extract_enums.cpp | 2 +- src/mmo/extract_enums.hpp | 24 +++++++++--------- src/mmo/human_time_diff.cpp | 2 +- src/mmo/human_time_diff.hpp | 2 +- src/mmo/human_time_diff_test.cpp | 2 ++ src/mmo/ids.cpp | 4 +-- src/mmo/ids.hpp | 6 ++--- src/mmo/version.cpp | 2 +- src/mmo/version.hpp | 2 +- src/net/ip.cpp | 4 +-- src/net/ip.hpp | 4 +-- src/net/ip_test.cpp | 1 + 26 files changed, 92 insertions(+), 85 deletions(-) diff --git a/src/char/char.cpp b/src/char/char.cpp index 57788ee..0bee093 100644 --- a/src/char/char.cpp +++ b/src/char/char.cpp @@ -409,7 +409,7 @@ AString mmo_char_tostr(struct CharPair *cp) } static -bool extract(XString str, Point *p) +bool impl_extract(XString str, Point *p) { return extract(str, record<','>(&p->map_, &p->x, &p->y)); } @@ -422,7 +422,7 @@ struct skill_loader }; static -bool extract(XString str, struct skill_loader *s) +bool impl_extract(XString str, struct skill_loader *s) { uint32_t flags_and_level; if (!extract(str, @@ -437,7 +437,7 @@ bool extract(XString str, struct skill_loader *s) // Function to set the character from the line (at read of characters file) //------------------------------------------------------------------------- static -bool extract(XString str, CharPair *cp) +bool impl_extract(XString str, CharPair *cp) { CharKey *k = &cp->key; CharData *p = cp->data.get(); diff --git a/src/char/int_party.cpp b/src/char/int_party.cpp index 731669a..a16bc20 100644 --- a/src/char/int_party.cpp +++ b/src/char/int_party.cpp @@ -93,7 +93,7 @@ AString inter_party_tostr(PartyPair p) } static -bool extract(XString str, PartyPair *pp) +bool impl_extract(XString str, PartyPair *pp) { PartyPair& p = *pp; diff --git a/src/char/int_storage.cpp b/src/char/int_storage.cpp index c02f037..0c76678 100644 --- a/src/char/int_storage.cpp +++ b/src/char/int_storage.cpp @@ -95,7 +95,7 @@ AString storage_tostr(Storage *p) // 文字列を倉庫データに変換 static -bool extract(XString str, Storage *p) +bool impl_extract(XString str, Storage *p) { std::vector storage_items; if (!extract(str, diff --git a/src/char/inter.cpp b/src/char/inter.cpp index c081825..4b10dbc 100644 --- a/src/char/inter.cpp +++ b/src/char/inter.cpp @@ -85,7 +85,7 @@ AString inter_accreg_tostr(struct accreg *reg) // アカウント変数を文字列から変換 static -bool extract(XString str, struct accreg *reg) +bool impl_extract(XString str, struct accreg *reg) { std::vector vars; if (!extract(str, diff --git a/src/high/extract_mmo.cpp b/src/high/extract_mmo.cpp index a674656..dae6a3b 100644 --- a/src/high/extract_mmo.cpp +++ b/src/high/extract_mmo.cpp @@ -32,13 +32,13 @@ // TODO also pass an io::LineSpan around. namespace tmwa { -bool extract(XString str, GlobalReg *var) +bool impl_extract(XString str, GlobalReg *var) { return extract(str, record<','>(&var->str, &var->value)); } -bool extract(XString str, Item *it) +bool impl_extract(XString str, Item *it) { XString ignored; XString corruption_hack_amount; @@ -66,7 +66,7 @@ bool extract(XString str, Item *it) return rv; } -bool extract(XString str, MapName *m) +bool impl_extract(XString str, MapName *m) { XString::iterator it = std::find(str.begin(), str.end(), '.'); str = str.xislice_h(it); @@ -76,7 +76,7 @@ bool extract(XString str, MapName *m) return rv; } -bool extract(XString str, CharName *out) +bool impl_extract(XString str, CharName *out) { VString<23> tmp; if (extract(str, &tmp)) @@ -87,7 +87,7 @@ bool extract(XString str, CharName *out) return false; } -bool extract(XString str, NpcEvent *ev) +bool impl_extract(XString str, NpcEvent *ev) { XString mid; return extract(str, record<':'>(&ev->npc, &mid, &ev->label)) && !mid; diff --git a/src/high/extract_mmo.hpp b/src/high/extract_mmo.hpp index 0c18090..5fcd06f 100644 --- a/src/high/extract_mmo.hpp +++ b/src/high/extract_mmo.hpp @@ -23,10 +23,10 @@ namespace tmwa { -bool extract(XString str, GlobalReg *var); -bool extract(XString str, Item *it); -bool extract(XString str, MapName *m); -bool extract(XString str, CharName *out); +bool impl_extract(XString str, GlobalReg *var); +bool impl_extract(XString str, Item *it); +bool impl_extract(XString str, MapName *m); +bool impl_extract(XString str, CharName *out); -bool extract(XString str, NpcEvent *ev); +bool impl_extract(XString str, NpcEvent *ev); } // namespace tmwa diff --git a/src/io/extract.cpp b/src/io/extract.cpp index 55d3980..fce4dab 100644 --- a/src/io/extract.cpp +++ b/src/io/extract.cpp @@ -30,25 +30,25 @@ // TODO also pass an io::LineSpan around. namespace tmwa { -bool extract(XString str, XString *rv) +bool impl_extract(XString str, XString *rv) { *rv = str; return true; } -bool extract(XString str, RString *rv) +bool impl_extract(XString str, RString *rv) { *rv = str; return true; } -bool extract(XString str, AString *rv) +bool impl_extract(XString str, AString *rv) { *rv = str; return true; } -bool extract(XString str, std::chrono::nanoseconds *ns) +bool impl_extract(XString str, std::chrono::nanoseconds *ns) { std::chrono::nanoseconds::rep rep; if (extract(str, &rep)) @@ -73,7 +73,7 @@ bool extract(XString str, std::chrono::nanoseconds *ns) } return false; } -bool extract(XString str, std::chrono::microseconds *us) +bool impl_extract(XString str, std::chrono::microseconds *us) { std::chrono::microseconds::rep rep; if (extract(str, &rep)) @@ -98,7 +98,7 @@ bool extract(XString str, std::chrono::microseconds *us) } return false; } -bool extract(XString str, std::chrono::milliseconds *ms) +bool impl_extract(XString str, std::chrono::milliseconds *ms) { std::chrono::milliseconds::rep rep; if (extract(str, &rep)) @@ -123,7 +123,7 @@ bool extract(XString str, std::chrono::milliseconds *ms) } return false; } -bool extract(XString str, std::chrono::seconds *s) +bool impl_extract(XString str, std::chrono::seconds *s) { std::chrono::seconds::rep rep; if (extract(str, &rep)) @@ -148,7 +148,7 @@ bool extract(XString str, std::chrono::seconds *s) } return false; } -bool extract(XString str, std::chrono::minutes *min) +bool impl_extract(XString str, std::chrono::minutes *min) { std::chrono::minutes::rep rep; if (extract(str, &rep)) @@ -173,7 +173,7 @@ bool extract(XString str, std::chrono::minutes *min) } return false; } -bool extract(XString str, std::chrono::hours *h) +bool impl_extract(XString str, std::chrono::hours *h) { std::chrono::hours::rep rep; if (extract(str, &rep)) @@ -198,7 +198,7 @@ bool extract(XString str, std::chrono::hours *h) } return false; } -bool extract(XString str, std::chrono::duration> *d) +bool impl_extract(XString str, std::chrono::duration> *d) { std::chrono::duration>::rep rep; if (extract(str, &rep)) diff --git a/src/io/extract.hpp b/src/io/extract.hpp index 174243e..897f50e 100644 --- a/src/io/extract.hpp +++ b/src/io/extract.hpp @@ -39,10 +39,10 @@ namespace tmwa { template -bool do_extract(XString str, T t); +bool extract(XString str, T t); template::value && !std::is_same::value && !std::is_same::value>::type> -bool extract(XString str, T *iv) +bool impl_extract(XString str, T *iv) { if (!str || str.size() > 20) return false; @@ -75,7 +75,7 @@ bool extract(XString str, T *iv) } inline -bool extract(XString str, TimeT *tv) +bool impl_extract(XString str, TimeT *tv) { return extract(str, &tv->value); } @@ -93,12 +93,12 @@ bool extract_as_int(XString str, T *iv) return true; } -bool extract(XString str, XString *rv); -bool extract(XString str, RString *rv); -bool extract(XString str, AString *rv); +bool impl_extract(XString str, XString *rv); +bool impl_extract(XString str, RString *rv); +bool impl_extract(XString str, AString *rv); template -bool extract(XString str, VString *out) +bool impl_extract(XString str, VString *out) { if (str.size() > N) return false; @@ -107,7 +107,7 @@ bool extract(XString str, VString *out) } inline -bool extract(XString str, LString exact) +bool impl_extract(XString str, LString exact) { return str == exact; } @@ -126,7 +126,7 @@ LStripper lstripping(T v) } template -bool extract(XString str, LStripper out) +bool impl_extract(XString str, LStripper out) { return extract(str.lstrip(), out.impl); } @@ -163,13 +163,13 @@ Record record(T... t) } template -bool extract(XString str, Record) +bool impl_extract(XString str, Record) { return !str; } template -bool extract(XString str, Record rec) +bool impl_extract(XString str, Record rec) { XString::iterator s = std::find(str.begin(), str.end(), split); XString::iterator s2 = s; @@ -198,7 +198,7 @@ VRecord vrec(std::vector *arr) } template -bool extract(XString str, VRecord rec) +bool impl_extract(XString str, VRecord rec) { if (!str) return true; @@ -210,23 +210,25 @@ bool extract(XString str, VRecord rec) && extract(str.xislice_t(s + 1), rec); } -template -bool do_extract(XString str, T t) -{ - return extract(str, t); -} - template -bool extract(XString str, Wrapped *w) +bool impl_extract(XString str, Wrapped *w) { return extract(str, &w->_value); } -bool extract(XString str, std::chrono::nanoseconds *ns); -bool extract(XString str, std::chrono::microseconds *us); -bool extract(XString str, std::chrono::milliseconds *ms); -bool extract(XString str, std::chrono::seconds *s); -bool extract(XString str, std::chrono::minutes *min); -bool extract(XString str, std::chrono::hours *h); -bool extract(XString str, std::chrono::duration> *d); +bool impl_extract(XString str, std::chrono::nanoseconds *ns); +bool impl_extract(XString str, std::chrono::microseconds *us); +bool impl_extract(XString str, std::chrono::milliseconds *ms); +bool impl_extract(XString str, std::chrono::seconds *s); +bool impl_extract(XString str, std::chrono::minutes *min); +bool impl_extract(XString str, std::chrono::hours *h); +bool impl_extract(XString str, std::chrono::duration> *d); + +// this must come after all non-`namespace tmwa` `impl_extract`s. +// In particular, the ones for `*int*` and `std::chrono::*` +template +bool extract(XString str, T t) +{ + return impl_extract(str, t); +} } // namespace tmwa diff --git a/src/login/login.cpp b/src/login/login.cpp index d58de14..fb90cbe 100644 --- a/src/login/login.cpp +++ b/src/login/login.cpp @@ -479,7 +479,7 @@ AString mmo_auth_tostr(const AuthData *p) } static -bool extract(XString line, AuthData *ad) +bool impl_extract(XString line, AuthData *ad) { TimeT unused_connect_until_time; std::vector vars; diff --git a/src/map/mapflag.cpp b/src/map/mapflag.cpp index 91dfe8d..d5e78d8 100644 --- a/src/map/mapflag.cpp +++ b/src/map/mapflag.cpp @@ -40,7 +40,7 @@ void MapFlags::set(MapFlag mf, bool val) flags &=~ static_cast(mf); } -bool extract(XString str, MapFlag *mf) +bool impl_extract(XString str, MapFlag *mf) { const struct { diff --git a/src/map/mapflag.hpp b/src/map/mapflag.hpp index d964405..5818697 100644 --- a/src/map/mapflag.hpp +++ b/src/map/mapflag.hpp @@ -75,7 +75,7 @@ public: void set(MapFlag, bool); }; -bool extract(XString str, MapFlag *mf); +bool impl_extract(XString str, MapFlag *mf); MapFlag map_flag_from_int(int shift); } // namespace tmwa diff --git a/src/map/mob.cpp b/src/map/mob.cpp index b01a4ff..c690ad0 100644 --- a/src/map/mob.cpp +++ b/src/map/mob.cpp @@ -3428,7 +3428,7 @@ int mob_makedummymobdb(Species mob_class) } static -bool extract(XString str, LevelElement *le) +bool impl_extract(XString str, LevelElement *le) { int tmp; if (extract(str, &tmp)) @@ -3583,7 +3583,7 @@ bool mob_readdb(ZString filename) } static -bool extract(XString str, MobSkillCondition *msc) +bool impl_extract(XString str, MobSkillCondition *msc) { const struct { @@ -3607,7 +3607,7 @@ bool extract(XString str, MobSkillCondition *msc) } static -bool extract(XString str, MobSkillState *mss) +bool impl_extract(XString str, MobSkillState *mss) { const struct { @@ -3630,7 +3630,7 @@ bool extract(XString str, MobSkillState *mss) } static -bool extract(XString str, MobSkillTarget *mst) +bool impl_extract(XString str, MobSkillTarget *mst) { const struct { diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp index cc28cd2..12f8679 100644 --- a/src/map/script-fun.cpp +++ b/src/map/script-fun.cpp @@ -30,6 +30,7 @@ #include "../generic/random.hpp" #include "../io/cxxstdio.hpp" +#include "../io/extract.hpp" #include "../net/timer.hpp" diff --git a/src/mmo/config_parse.cpp b/src/mmo/config_parse.cpp index 8362810..b47ee79 100644 --- a/src/mmo/config_parse.cpp +++ b/src/mmo/config_parse.cpp @@ -24,6 +24,7 @@ #include "../strings/zstring.hpp" #include "../io/cxxstdio.hpp" +#include "../io/extract.hpp" #include "../io/line.hpp" #include "version.hpp" diff --git a/src/mmo/extract_enums.cpp b/src/mmo/extract_enums.cpp index ecf6940..efafa39 100644 --- a/src/mmo/extract_enums.cpp +++ b/src/mmo/extract_enums.cpp @@ -23,7 +23,7 @@ namespace tmwa { -bool extract(XString str, DIR *d) +bool impl_extract(XString str, DIR *d) { unsigned di; if (extract(str, &di) && di < 8) diff --git a/src/mmo/extract_enums.hpp b/src/mmo/extract_enums.hpp index 96e5df7..1aab17e 100644 --- a/src/mmo/extract_enums.hpp +++ b/src/mmo/extract_enums.hpp @@ -38,15 +38,15 @@ enum class Opt2 : uint16_t; enum class Opt0 : uint16_t; inline -bool extract(XString str, EPOS *iv) { return extract_as_int(str, iv); } +bool impl_extract(XString str, EPOS *iv) { return extract_as_int(str, iv); } inline -bool extract(XString str, MobMode *iv) { return extract_as_int(str, iv); } +bool impl_extract(XString str, MobMode *iv) { return extract_as_int(str, iv); } inline -bool extract(XString str, Opt1 *iv) { return extract_as_int(str, iv); } +bool impl_extract(XString str, Opt1 *iv) { return extract_as_int(str, iv); } inline -bool extract(XString str, Opt2 *iv) { return extract_as_int(str, iv); } +bool impl_extract(XString str, Opt2 *iv) { return extract_as_int(str, iv); } inline -bool extract(XString str, Opt0 *iv) { return extract_as_int(str, iv); } +bool impl_extract(XString str, Opt0 *iv) { return extract_as_int(str, iv); } } enum class ItemLook : uint16_t; @@ -57,17 +57,17 @@ enum class SkillID : uint16_t; enum class StatusChange : uint16_t; inline -bool extract(XString str, ItemLook *iv) { return extract_as_int(str, iv); } +bool impl_extract(XString str, ItemLook *iv) { return extract_as_int(str, iv); } inline -bool extract(XString str, ItemType *iv) { return extract_as_int(str, iv); } +bool impl_extract(XString str, ItemType *iv) { return extract_as_int(str, iv); } inline -bool extract(XString str, Race *iv) { return extract_as_int(str, iv); } +bool impl_extract(XString str, Race *iv) { return extract_as_int(str, iv); } inline -bool extract(XString str, SEX *iv) { return extract_as_int(str, iv); } +bool impl_extract(XString str, SEX *iv) { return extract_as_int(str, iv); } inline -bool extract(XString str, SkillID *iv) { return extract_as_int(str, iv); } +bool impl_extract(XString str, SkillID *iv) { return extract_as_int(str, iv); } inline -bool extract(XString str, StatusChange *iv) { return extract_as_int(str, iv); } +bool impl_extract(XString str, StatusChange *iv) { return extract_as_int(str, iv); } -bool extract(XString, DIR *); +bool impl_extract(XString, DIR *); } // namespace tmwa diff --git a/src/mmo/human_time_diff.cpp b/src/mmo/human_time_diff.cpp index e434773..aaa7928 100644 --- a/src/mmo/human_time_diff.cpp +++ b/src/mmo/human_time_diff.cpp @@ -25,7 +25,7 @@ namespace tmwa { -bool extract(XString str, HumanTimeDiff *iv) +bool impl_extract(XString str, HumanTimeDiff *iv) { // str is a sequence of [-+]?[0-9]+([ay]|m|[jd]|h|mn|s) // there are NO spaces here diff --git a/src/mmo/human_time_diff.hpp b/src/mmo/human_time_diff.hpp index 40352d0..92b3288 100644 --- a/src/mmo/human_time_diff.hpp +++ b/src/mmo/human_time_diff.hpp @@ -42,5 +42,5 @@ struct HumanTimeDiff return !bool(*this); } }; -bool extract(XString str, HumanTimeDiff *iv); +bool impl_extract(XString str, HumanTimeDiff *iv); } // namespace tmwa diff --git a/src/mmo/human_time_diff_test.cpp b/src/mmo/human_time_diff_test.cpp index c18599d..08a75bf 100644 --- a/src/mmo/human_time_diff_test.cpp +++ b/src/mmo/human_time_diff_test.cpp @@ -20,6 +20,8 @@ #include +#include "../io/extract.hpp" + #include "../poison.hpp" diff --git a/src/mmo/ids.cpp b/src/mmo/ids.cpp index 9c013ba..65c470b 100644 --- a/src/mmo/ids.cpp +++ b/src/mmo/ids.cpp @@ -25,7 +25,7 @@ namespace tmwa { -bool extract(XString str, Species *w) +bool impl_extract(XString str, Species *w) { // lots of data files use this if (str == "-1"_s) @@ -35,7 +35,7 @@ bool extract(XString str, Species *w) } return extract(str, &w->_value); } -bool extract(XString str, GmLevel *lvl) +bool impl_extract(XString str, GmLevel *lvl) { return extract(str, &lvl->bits); } diff --git a/src/mmo/ids.hpp b/src/mmo/ids.hpp index 389f9e9..c1482ef 100644 --- a/src/mmo/ids.hpp +++ b/src/mmo/ids.hpp @@ -30,7 +30,7 @@ class Species : public Wrapped { public: explicit operator bool() cons constexpr Species NEGATIVE_SPECIES = Species(); -bool extract(XString str, Species *w); +bool impl_extract(XString str, Species *w); class AccountId : public Wrapped { public: constexpr AccountId() : Wrapped() {} protected: constexpr explicit AccountId(uint32_t a) : Wrapped(a) {} }; @@ -41,12 +41,12 @@ class ItemNameId : public Wrapped { public: constexpr ItemNameId() : W class BlockId : public Wrapped { public: constexpr BlockId() : Wrapped() {} protected: constexpr explicit BlockId(uint32_t a) : Wrapped(a) {} }; -bool extract(XString str, GmLevel *lvl); +bool impl_extract(XString str, GmLevel *lvl); class GmLevel { uint32_t bits; - friend bool extract(XString str, GmLevel *lvl); + friend bool impl_extract(XString str, GmLevel *lvl); constexpr explicit GmLevel(uint32_t b) : bits(b) {} constexpr explicit diff --git a/src/mmo/version.cpp b/src/mmo/version.cpp index aec4e73..93ea794 100644 --- a/src/mmo/version.cpp +++ b/src/mmo/version.cpp @@ -66,7 +66,7 @@ Version CURRENT_MAP_SERVER_VERSION = LString CURRENT_VERSION_STRING = VERSION_STRING; -bool extract(XString str, Version *vers) +bool impl_extract(XString str, Version *vers) { *vers = {}; // TODO should I try to extract dev and vend also? diff --git a/src/mmo/version.hpp b/src/mmo/version.hpp index 1eed223..a09953f 100644 --- a/src/mmo/version.hpp +++ b/src/mmo/version.hpp @@ -87,7 +87,7 @@ extern Version CURRENT_MAP_SERVER_VERSION; extern LString CURRENT_VERSION_STRING; -bool extract(XString str, Version *vers); +bool impl_extract(XString str, Version *vers); extern LString VERSION_INFO_HEADER; extern LString VERSION_INFO_COMMIT; diff --git a/src/net/ip.cpp b/src/net/ip.cpp index 4ec022b..3dc242d 100644 --- a/src/net/ip.cpp +++ b/src/net/ip.cpp @@ -29,7 +29,7 @@ namespace tmwa { -bool extract(XString str, IP4Address *rv) +bool impl_extract(XString str, IP4Address *rv) { if (str.endswith('.')) return false; @@ -42,7 +42,7 @@ bool extract(XString str, IP4Address *rv) return false; } -bool extract(XString str, IP4Mask *rv) +bool impl_extract(XString str, IP4Mask *rv) { IP4Address a, m; unsigned b; diff --git a/src/net/ip.hpp b/src/net/ip.hpp index ab45c56..82d9430 100644 --- a/src/net/ip.hpp +++ b/src/net/ip.hpp @@ -158,7 +158,7 @@ IP4Address IP4_BROADCAST({255, 255, 255, 255}); VString<15> convert_for_printf(IP4Address a); VString<31> convert_for_printf(IP4Mask m); -bool extract(XString str, IP4Address *iv); +bool impl_extract(XString str, IP4Address *iv); -bool extract(XString str, IP4Mask *iv); +bool impl_extract(XString str, IP4Mask *iv); } // namespace tmwa diff --git a/src/net/ip_test.cpp b/src/net/ip_test.cpp index 419dc03..2b9bcad 100644 --- a/src/net/ip_test.cpp +++ b/src/net/ip_test.cpp @@ -24,6 +24,7 @@ #include "../strings/literal.hpp" #include "../io/cxxstdio.hpp" +#include "../io/extract.hpp" #include "../poison.hpp" -- cgit v1.2.3-60-g2f50