aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/container.h88
-rw-r--r--src/util/numeric.cpp2
-rw-r--r--src/util/numeric.h3
-rw-r--r--src/util/string.h16
-rw-r--r--src/util/thread.h16
-rw-r--r--src/util/timetaker.cpp11
-rw-r--r--src/util/timetaker.h7
7 files changed, 89 insertions, 54 deletions
diff --git a/src/util/container.h b/src/util/container.h
index 775372649..9bb388f0e 100644
--- a/src/util/container.h
+++ b/src/util/container.h
@@ -24,6 +24,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <jmutex.h>
#include <jmutexautolock.h>
#include "../porting.h" // For sleep_ms
+#include <list>
+#include <vector>
/*
Queue with unique values with fast checking of value existence
@@ -43,11 +45,11 @@ public:
bool push_back(Value value)
{
// Check if already exists
- if(m_map.find(value) != NULL)
+ if(m_map.find(value) != m_map.end())
return false;
// Add
- m_map.insert(value, 0);
+ m_map[value] = 0;
m_list.push_back(value);
return true;
@@ -55,22 +57,21 @@ public:
Value pop_front()
{
- typename core::list<Value>::Iterator i = m_list.begin();
+ typename std::list<Value>::iterator i = m_list.begin();
Value value = *i;
- m_map.remove(value);
+ m_map.erase(value);
m_list.erase(i);
return value;
}
u32 size()
{
- assert(m_list.size() == m_map.size());
- return m_list.size();
+ return m_map.size();
}
private:
- core::map<Value, u8> m_map;
- core::list<Value> m_list;
+ std::map<Value, u8> m_map;
+ std::list<Value> m_list;
};
#if 1
@@ -95,31 +96,31 @@ public:
{
JMutexAutoLock lock(m_mutex);
- typename core::map<Key, Value>::Node *n;
+ typename std::map<Key, Value>::iterator n;
n = m_values.find(name);
- if(n == NULL)
+ if(n == m_values.end())
return false;
if(result != NULL)
- *result = n->getValue();
+ *result = n->second;
return true;
}
- core::list<Value> getValues()
+ std::list<Value> getValues()
{
- core::list<Value> result;
- for(typename core::map<Key, Value>::Iterator
- i = m_values.getIterator();
- i.atEnd() == false; i++){
- result.push_back(i.getNode()->getValue());
+ std::list<Value> result;
+ for(typename std::map<Key, Value>::iterator
+ i = m_values.begin();
+ i != m_values.end(); ++i){
+ result.push_back(i->second);
}
return result;
}
private:
- core::map<Key, Value> m_values;
+ std::map<Key, Value> m_values;
JMutex m_mutex;
};
#endif
@@ -163,10 +164,10 @@ public:
u32 getId(const T &value)
{
JMutexAutoLock lock(m_mutex);
- typename core::map<T, u32>::Node *n;
+ typename std::map<T, u32>::iterator n;
n = m_value_to_id.find(value);
- if(n != NULL)
- return n->getValue();
+ if(n != m_value_to_id.end())
+ return n->second;
m_id_to_value.push_back(value);
u32 new_id = m_id_to_value.size();
m_value_to_id.insert(value, new_id);
@@ -176,8 +177,8 @@ public:
private:
JMutex m_mutex;
// Values are stored here at id-1 position (id 1 = [0])
- core::array<T> m_id_to_value;
- core::map<T, u32> m_value_to_id;
+ std::vector<T> m_id_to_value;
+ std::map<T, u32> m_value_to_id;
};
/*
@@ -187,39 +188,52 @@ template<typename T>
class Queue
{
public:
+ Queue():
+ m_list_size(0)
+ {}
+
void push_back(T t)
{
m_list.push_back(t);
+ ++m_list_size;
}
T pop_front()
{
- if(m_list.size() == 0)
+ if(m_list.empty())
throw ItemNotFoundException("Queue: queue is empty");
- typename core::list<T>::Iterator begin = m_list.begin();
+ typename std::list<T>::iterator begin = m_list.begin();
T t = *begin;
m_list.erase(begin);
+ --m_list_size;
return t;
}
T pop_back()
{
- if(m_list.size() == 0)
+ if(m_list.empty())
throw ItemNotFoundException("Queue: queue is empty");
- typename core::list<T>::Iterator last = m_list.getLast();
+ typename std::list<T>::iterator last = m_list.back();
T t = *last;
m_list.erase(last);
+ --m_list_size;
return t;
}
u32 size()
{
- return m_list.size();
+ return m_list_size;
+ }
+
+ bool empty()
+ {
+ return m_list.empty();
}
protected:
- core::list<T> m_list;
+ std::list<T> m_list;
+ u32 m_list_size;
};
/*
@@ -234,10 +248,10 @@ public:
{
m_mutex.Init();
}
- u32 size()
+ bool empty()
{
JMutexAutoLock lock(m_mutex);
- return m_list.size();
+ return m_list.empty();
}
void push_back(T t)
{
@@ -253,9 +267,9 @@ public:
{
JMutexAutoLock lock(m_mutex);
- if(m_list.size() > 0)
+ if(!m_list.empty())
{
- typename core::list<T>::Iterator begin = m_list.begin();
+ typename std::list<T>::iterator begin = m_list.begin();
T t = *begin;
m_list.erase(begin);
return t;
@@ -279,9 +293,9 @@ public:
{
JMutexAutoLock lock(m_mutex);
- if(m_list.size() > 0)
+ if(!m_list.empty())
{
- typename core::list<T>::Iterator last = m_list.getLast();
+ typename std::list<T>::iterator last = m_list.back();
T t = *last;
m_list.erase(last);
return t;
@@ -302,14 +316,14 @@ public:
return m_mutex;
}
- core::list<T> & getList()
+ std::list<T> & getList()
{
return m_list;
}
protected:
JMutex m_mutex;
- core::list<T> m_list;
+ std::list<T> m_list;
};
#endif
diff --git a/src/util/numeric.cpp b/src/util/numeric.cpp
index a79454628..ed83df7d7 100644
--- a/src/util/numeric.cpp
+++ b/src/util/numeric.cpp
@@ -24,7 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <iostream>
// Calculate the borders of a "d-radius" cube
-void getFacePositions(core::list<v3s16> &list, u16 d)
+void getFacePositions(std::list<v3s16> &list, u16 d)
{
if(d == 0)
{
diff --git a/src/util/numeric.h b/src/util/numeric.h
index 450a98e40..e66af2376 100644
--- a/src/util/numeric.h
+++ b/src/util/numeric.h
@@ -25,9 +25,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "../irr_v3d.h"
#include "../irr_aabb3d.h"
#include <irrList.h>
+#include <list>
// Calculate the borders of a "d-radius" cube
-void getFacePositions(core::list<v3s16> &list, u16 d);
+void getFacePositions(std::list<v3s16> &list, u16 d);
class IndentationRaiser
{
diff --git a/src/util/string.h b/src/util/string.h
index 2f0264bd4..6c48adeb3 100644
--- a/src/util/string.h
+++ b/src/util/string.h
@@ -286,6 +286,22 @@ inline std::string wrap_rows(const std::string &from, u32 rowlen)
return to;
}
+/*
+ Removes all \\ from a string that had been escaped (FormSpec strings)
+*/
+inline std::string unescape_string(std::string &s)
+{
+ std::string res;
+
+ for (size_t i = 0; i <= s.length(); i++) {
+ if (s[i] == '\\')
+ i++;
+ res += s[i];
+ }
+
+ return res;
+}
+
std::string translatePassword(std::string playername, std::wstring password);
size_t curl_write_data(char *ptr, size_t size, size_t nmemb, void *userdata);
u32 readFlagString(std::string str, FlagDesc *flagdesc);
diff --git a/src/util/thread.h b/src/util/thread.h
index 949bb4204..6b2cf5b6c 100644
--- a/src/util/thread.h
+++ b/src/util/thread.h
@@ -120,7 +120,7 @@ class GetResult
public:
Key key;
T item;
- core::list<CallerInfo<Caller, CallerData> > callers;
+ std::list<CallerInfo<Caller, CallerData> > callers;
};
template<typename Key, typename T, typename Caller, typename CallerData>
@@ -152,16 +152,16 @@ public:
Key key;
ResultQueue<Key, T, Caller, CallerData> *dest;
- core::list<CallerInfo<Caller, CallerData> > callers;
+ std::list<CallerInfo<Caller, CallerData> > callers;
};
template<typename Key, typename T, typename Caller, typename CallerData>
class RequestQueue
{
public:
- u32 size()
+ bool empty()
{
- return m_queue.size();
+ return m_queue.empty();
}
void add(Key key, Caller caller, CallerData callerdata,
@@ -172,17 +172,17 @@ public:
/*
If the caller is already on the list, only update CallerData
*/
- for(typename core::list< GetRequest<Key, T, Caller, CallerData> >::Iterator
+ for(typename std::list< GetRequest<Key, T, Caller, CallerData> >::iterator
i = m_queue.getList().begin();
- i != m_queue.getList().end(); i++)
+ i != m_queue.getList().end(); ++i)
{
GetRequest<Key, T, Caller, CallerData> &request = *i;
if(request.key == key)
{
- for(typename core::list< CallerInfo<Caller, CallerData> >::Iterator
+ for(typename std::list< CallerInfo<Caller, CallerData> >::iterator
i = request.callers.begin();
- i != request.callers.end(); i++)
+ i != request.callers.end(); ++i)
{
CallerInfo<Caller, CallerData> &ca = *i;
if(ca.caller == caller)
diff --git a/src/util/timetaker.cpp b/src/util/timetaker.cpp
index 910fea822..720a9e1a9 100644
--- a/src/util/timetaker.cpp
+++ b/src/util/timetaker.cpp
@@ -23,19 +23,20 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "../log.h"
#include <ostream>
-TimeTaker::TimeTaker(const char *name, u32 *result)
+TimeTaker::TimeTaker(const char *name, u32 *result, TimePrecision prec)
{
m_name = name;
m_result = result;
m_running = true;
- m_time1 = getTimeMs();
+ m_precision = prec;
+ m_time1 = getTime(prec);
}
u32 TimeTaker::stop(bool quiet)
{
if(m_running)
{
- u32 time2 = getTimeMs();
+ u32 time2 = getTime(m_precision);
u32 dtime = time2 - m_time1;
if(m_result != NULL)
{
@@ -52,9 +53,9 @@ u32 TimeTaker::stop(bool quiet)
return 0;
}
-u32 TimeTaker::getTime()
+u32 TimeTaker::getTimerTime()
{
- u32 time2 = getTimeMs();
+ u32 time2 = getTime(m_precision);
u32 dtime = time2 - m_time1;
return dtime;
}
diff --git a/src/util/timetaker.h b/src/util/timetaker.h
index 0b9d9ca04..5512c205f 100644
--- a/src/util/timetaker.h
+++ b/src/util/timetaker.h
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define UTIL_TIMETAKER_HEADER
#include "../irrlichttypes.h"
+#include "../gettime.h"
/*
TimeTaker
@@ -29,7 +30,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
class TimeTaker
{
public:
- TimeTaker(const char *name, u32 *result=NULL);
+ TimeTaker(const char *name, u32 *result=NULL,
+ TimePrecision=PRECISION_MILLI);
~TimeTaker()
{
@@ -38,12 +40,13 @@ public:
u32 stop(bool quiet=false);
- u32 getTime();
+ u32 getTimerTime();
private:
const char *m_name;
u32 m_time1;
bool m_running;
+ TimePrecision m_precision;
u32 *m_result;
};