From 3de176cc587c4e0601c3c3f5a049e30db6bd2c17 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Wed, 22 Dec 2010 16:30:23 +0200 Subject: crafting system! --- src/utility.h | 53 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 9 deletions(-) (limited to 'src/utility.h') diff --git a/src/utility.h b/src/utility.h index 484b5828b..4e2e132e9 100644 --- a/src/utility.h +++ b/src/utility.h @@ -595,25 +595,28 @@ inline float wrapDegrees(float f) return f; } -inline std::string lowercase(std::string s) +inline std::string lowercase(const std::string &s) { + std::string s2; for(size_t i=0; i= 'A' && s[i] <= 'Z') - s[i] -= 'A' - 'a'; + char c = s[i]; + if(c >= 'A' && c <= 'Z') + c -= 'A' - 'a'; + s2 += c; } - return s; + return s2; } -inline bool is_yes(std::string s) +inline bool is_yes(const std::string &s) { - s = lowercase(trim(s)); - if(s == "y" || s == "yes" || s == "true") + std::string s2 = lowercase(trim(s)); + if(s2 == "y" || s2 == "yes" || s2 == "true") return true; return false; } -inline s32 stoi(std::string s, s32 min, s32 max) +inline s32 stoi(const std::string &s, s32 min, s32 max) { s32 i = atoi(s.c_str()); if(i < min) @@ -1067,7 +1070,39 @@ private: }; /* - A thread-safe queue + FIFO queue +*/ +template +class Queue +{ +public: + void push_back(T t) + { + m_list.push_back(t); + } + + T pop_front() + { + if(m_list.size() == 0) + throw ItemNotFoundException("MutexedQueue: queue is empty"); + + typename core::list::Iterator begin = m_list.begin(); + T t = *begin; + m_list.erase(begin); + return t; + } + + u32 size() + { + return m_list.size(); + } + +protected: + core::list m_list; +}; + +/* + Thread-safe FIFO queue */ template -- cgit v1.2.3