diff --git a/library/ColorText.cpp b/library/ColorText.cpp index 7f417e0a8..d528cb4c7 100644 --- a/library/ColorText.cpp +++ b/library/ColorText.cpp @@ -52,6 +52,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include +using namespace std; using namespace DFHack; #include "tinythread.h" diff --git a/library/RemoteServer.cpp b/library/RemoteServer.cpp index c934754b0..734b80702 100644 --- a/library/RemoteServer.cpp +++ b/library/RemoteServer.cpp @@ -61,6 +61,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "json/json.h" +using namespace std; using namespace DFHack; using dfproto::CoreTextNotification; diff --git a/library/VTableInterpose.cpp b/library/VTableInterpose.cpp index 520d91061..75ee62f01 100644 --- a/library/VTableInterpose.cpp +++ b/library/VTableInterpose.cpp @@ -36,6 +36,7 @@ distribution. #include "MiscUtils.h" +using namespace std; using namespace DFHack; /* diff --git a/library/include/MiscUtils.h b/library/include/MiscUtils.h index 56506f7bd..b6bada0ff 100644 --- a/library/include/MiscUtils.h +++ b/library/include/MiscUtils.h @@ -24,6 +24,7 @@ distribution. #pragma once #include "Export.h" +#include #include #include #include @@ -33,10 +34,6 @@ distribution. #include #include -using std::ostream; -using std::stringstream; -using std::endl; - #if defined(_MSC_VER) #define DFHACK_FUNCTION_SIG __FUNCSIG__ #elif defined(__GNUC__) @@ -83,9 +80,9 @@ using std::make_unique; } template -void print_bits ( T val, ostream& out ) +void print_bits ( T val, std::ostream& out ) { - stringstream strs; + std::stringstream strs; T n_bits = sizeof ( val ) * CHAR_BIT; int cnt; for ( unsigned i = 0; i < n_bits; ++i ) @@ -93,24 +90,24 @@ void print_bits ( T val, ostream& out ) cnt = i/10; strs << cnt << " "; } - strs << endl; + strs << std::endl; for ( unsigned i = 0; i < n_bits; ++i ) { cnt = i%10; strs << cnt << " "; } - strs << endl; + strs << std::endl; for ( unsigned i = 0; i < n_bits; ++i ) { strs << "--"; } - strs << endl; + strs << std::endl; for ( unsigned i = 0; i < n_bits; ++i ) { strs<< !!( val & 1 ) << " "; val >>= 1; } - strs << endl; + strs << std::endl; out << strs.str(); } @@ -389,6 +386,30 @@ DFHACK_EXPORT std::string toUpper(const std::string &str); DFHACK_EXPORT std::string toLower(const std::string &str); DFHACK_EXPORT std::string to_search_normalized(const std::string &str); +static inline std::string int_to_string(const int n) +{ + std::ostringstream ss; + ss << n; + return ss.str(); +} + +// trim from start +static inline std::string <rim(std::string &s) { + s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](char x){ return !std::isspace(x); })); + return s; +} + +// trim from end +static inline std::string &rtrim(std::string &s) { + s.erase(std::find_if(s.rbegin(), s.rend(), [](char x){ return !std::isspace(x); }).base(), s.end()); + return s; +} + +// trim from both ends +static inline std::string &trim(std::string &s) { + return ltrim(rtrim(s)); +} + enum word_wrap_whitespace_mode { WSMODE_KEEP_ALL, WSMODE_COLLAPSE_ALL, diff --git a/plugins/autobutcher.cpp b/plugins/autobutcher.cpp index 32c8b8764..81ec0c5df 100644 --- a/plugins/autobutcher.cpp +++ b/plugins/autobutcher.cpp @@ -24,6 +24,7 @@ #include "modules/Units.h" #include "modules/World.h" +using std::endl; using std::string; using std::unordered_map; using std::unordered_set; @@ -808,7 +809,7 @@ static void autobutcher_cycle(color_ostream &out) { for (auto w : watched_races) { int slaughter_count = w.second->ProcessUnits(); if (slaughter_count) { - stringstream ss; + std::stringstream ss; ss << slaughter_count; string announce = Units::getRaceNamePluralById(w.first) + " marked for slaughter: " + ss.str(); DEBUG(cycle,out).print("%s\n", announce.c_str()); diff --git a/plugins/autoclothing.cpp b/plugins/autoclothing.cpp index 83eb0398a..1535b5eb8 100644 --- a/plugins/autoclothing.cpp +++ b/plugins/autoclothing.cpp @@ -23,6 +23,8 @@ #include "df/creature_raw.h" #include "df/world.h" +using std::endl; + using namespace DFHack; using namespace DFHack::Items; using namespace DFHack::Units; @@ -80,7 +82,7 @@ struct ClothingRequirement std::string Serialize() { - stringstream stream; + std::stringstream stream; stream << ENUM_KEY_STR(job_type, jobType) << " "; stream << ENUM_KEY_STR(item_type,itemType) << " "; stream << item_subtype << " "; @@ -91,7 +93,7 @@ struct ClothingRequirement void Deserialize(std::string s) { - stringstream stream(s); + std::stringstream stream(s); std::string loadedJob; stream >> loadedJob; FOR_ENUM_ITEMS(job_type, job) @@ -138,7 +140,7 @@ struct ClothingRequirement std::string ToReadableLabel() { - stringstream stream; + std::stringstream stream; stream << bitfield_to_string(material_category) << " "; std::string adjective = ""; std::string name = ""; diff --git a/plugins/autonestbox.cpp b/plugins/autonestbox.cpp index dd052f234..8b1ee5244 100644 --- a/plugins/autonestbox.cpp +++ b/plugins/autonestbox.cpp @@ -200,7 +200,7 @@ static command_result df_autonestbox(color_ostream &out, vector ¶met autonestbox_cycle(out); } else { - out << "autonestbox is " << (is_enabled ? "" : "not ") << "running" << endl; + out << "autonestbox is " << (is_enabled ? "" : "not ") << "running" << std::endl; } return CR_OK; } @@ -377,11 +377,11 @@ static size_t assign_nestboxes(color_ostream &out) { did_complain = false; old_count = freeEgglayers; if (!did_complain) { - stringstream ss; + std::stringstream ss; ss << freeEgglayers; string announce = "Not enough free nestbox zones found! You need " + ss.str() + " more."; Gui::showAnnouncement(announce, 6, true); - out << announce << endl; + out << announce << std::endl; did_complain = true; } } @@ -396,12 +396,12 @@ static void autonestbox_cycle(color_ostream &out) { size_t processed = assign_nestboxes(out); if (processed > 0) { - stringstream ss; + std::stringstream ss; ss << processed << " nestboxes were assigned."; string announce = ss.str(); DEBUG(cycle,out).print("%s\n", announce.c_str()); Gui::showAnnouncement(announce, 2, false); - out << announce << endl; + out << announce << std::endl; // can complain again // (might lead to spamming the same message twice, but catches the case // where for example 2 new egglayers hatched right after 2 zones were created and assigned) diff --git a/plugins/createitem.cpp b/plugins/createitem.cpp index 09c6d8e20..57dbf7244 100644 --- a/plugins/createitem.cpp +++ b/plugins/createitem.cpp @@ -256,7 +256,7 @@ command_result df_createitem (color_ostream &out, vector & parameters) if (parameters.size() == 3) { - stringstream ss(parameters[2]); + std::stringstream ss(parameters[2]); ss >> count; if (count < 1) { diff --git a/plugins/fix-unit-occupancy.cpp b/plugins/fix-unit-occupancy.cpp index 973c185a8..4b2db0f12 100644 --- a/plugins/fix-unit-occupancy.cpp +++ b/plugins/fix-unit-occupancy.cpp @@ -14,6 +14,7 @@ #include "df/unit.h" #include "df/world.h" +using std::endl; using namespace DFHack; DFHACK_PLUGIN("fix-unit-occupancy"); diff --git a/plugins/generated-creature-renamer.cpp b/plugins/generated-creature-renamer.cpp index f6e9e41b6..92c11cfaf 100644 --- a/plugins/generated-creature-renamer.cpp +++ b/plugins/generated-creature-renamer.cpp @@ -13,6 +13,7 @@ //#include "df/world.h" using namespace DFHack; +using std::endl; DFHACK_PLUGIN("generated-creature-renamer"); REQUIRE_GLOBAL(world); diff --git a/plugins/uicommon.h b/plugins/uicommon.h index dc57c9374..e7a586585 100644 --- a/plugins/uicommon.h +++ b/plugins/uicommon.h @@ -157,13 +157,6 @@ static inline void OutputToggleString(int &x, int &y, const char *text, df::inte OutputToggleString(x, y, text, DFHack::Screen::getKeyDisplay(hotkey).c_str(), state, newline, left_margin, color, hotkey_color, map); } -inline string int_to_string(const int n) -{ - std::ostringstream ss; - ss << n; - return ss.str(); -} - static inline void set_to_limit(int &value, const int maximum, const int min = 0) { if (value < min) @@ -172,23 +165,6 @@ static inline void set_to_limit(int &value, const int maximum, const int min = 0 value = maximum; } -// trim from start -static inline std::string <rim(std::string &s) { - s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](char x){ return !std::isspace(x); })); - return s; -} - -// trim from end -static inline std::string &rtrim(std::string &s) { - s.erase(std::find_if(s.rbegin(), s.rend(), [](char x){ return !std::isspace(x); }).base(), s.end()); - return s; -} - -// trim from both ends -static inline std::string &trim(std::string &s) { - return ltrim(rtrim(s)); -} - inline void paint_text(const UIColor color, const int &x, const int &y, const std::string &text, const UIColor background = 0) { Screen::paintString(Screen::Pen(' ', color, background), x, y, text);