mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-02-15 08:16:08 +00:00
refactor(Core/Common): restyle common lib with astyle (#3461)
This commit is contained in:
@@ -17,18 +17,18 @@
|
||||
namespace ByteConverter
|
||||
{
|
||||
template<size_t T>
|
||||
inline void convert(char *val)
|
||||
inline void convert(char* val)
|
||||
{
|
||||
std::swap(*val, *(val + T - 1));
|
||||
convert<T - 2>(val + 1);
|
||||
convert < T - 2 > (val + 1);
|
||||
}
|
||||
|
||||
template<> inline void convert<0>(char *) { }
|
||||
template<> inline void convert<1>(char *) { } // ignore central byte
|
||||
template<> inline void convert<0>(char*) { }
|
||||
template<> inline void convert<1>(char*) { } // ignore central byte
|
||||
|
||||
template<typename T> inline void apply(T *val)
|
||||
template<typename T> inline void apply(T* val)
|
||||
{
|
||||
convert<sizeof(T)>((char *)(val));
|
||||
convert<sizeof(T)>((char*)(val));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,8 @@ public:
|
||||
/**
|
||||
* Returns a pointer to object of requested type stored with given key or nullptr
|
||||
*/
|
||||
template<class T> T* Get(std::string const & k) const {
|
||||
template<class T> T* Get(std::string const& k) const
|
||||
{
|
||||
static_assert(std::is_base_of<Base, T>::value, "T must derive from Base");
|
||||
if (Container.empty())
|
||||
return nullptr;
|
||||
@@ -36,13 +37,14 @@ public:
|
||||
return dynamic_cast<T*>(it->second.get());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a pointer to object of requested type stored with given key
|
||||
* or default constructs one and returns that one
|
||||
*/
|
||||
template<class T, typename std::enable_if<std::is_default_constructible<T>::value, int>::type = 0>
|
||||
T* GetDefault(std::string const & k) {
|
||||
T * GetDefault(std::string const& k)
|
||||
{
|
||||
static_assert(std::is_base_of<Base, T>::value, "T must derive from Base");
|
||||
if (T* v = Get<T>(k))
|
||||
return v;
|
||||
@@ -50,16 +52,16 @@ public:
|
||||
Container.emplace(k, std::unique_ptr<T>(v));
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Stores a new object that inherits the Base class with the given key
|
||||
*/
|
||||
void Set(std::string const & k, Base* v) { Container[k] = std::unique_ptr<Base>(v); }
|
||||
void Set(std::string const& k, Base* v) { Container[k] = std::unique_ptr<Base>(v); }
|
||||
|
||||
/**
|
||||
* Removes objects with given key and returns true if one was removed, false otherwise
|
||||
*/
|
||||
bool Erase(std::string const & k) { return Container.erase(k) != 0; }
|
||||
bool Erase(std::string const& k) { return Container.erase(k) != 0; }
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, std::unique_ptr<Base>> Container;
|
||||
|
||||
@@ -15,51 +15,51 @@
|
||||
|
||||
class BasicEvent
|
||||
{
|
||||
public:
|
||||
BasicEvent()
|
||||
{
|
||||
to_Abort = false;
|
||||
m_addTime = 0;
|
||||
m_execTime = 0;
|
||||
}
|
||||
virtual ~BasicEvent() { } // override destructor to perform some actions on event removal
|
||||
public:
|
||||
BasicEvent()
|
||||
{
|
||||
to_Abort = false;
|
||||
m_addTime = 0;
|
||||
m_execTime = 0;
|
||||
}
|
||||
virtual ~BasicEvent() { } // override destructor to perform some actions on event removal
|
||||
|
||||
// this method executes when the event is triggered
|
||||
// return false if event does not want to be deleted
|
||||
// e_time is execution time, p_time is update interval
|
||||
virtual bool Execute(uint64 /*e_time*/, uint32 /*p_time*/) { return true; }
|
||||
// this method executes when the event is triggered
|
||||
// return false if event does not want to be deleted
|
||||
// e_time is execution time, p_time is update interval
|
||||
virtual bool Execute(uint64 /*e_time*/, uint32 /*p_time*/) { return true; }
|
||||
|
||||
virtual bool IsDeletable() const { return true; } // this event can be safely deleted
|
||||
virtual bool IsDeletable() const { return true; } // this event can be safely deleted
|
||||
|
||||
virtual void Abort(uint64 /*e_time*/) { } // this method executes when the event is aborted
|
||||
virtual void Abort(uint64 /*e_time*/) { } // this method executes when the event is aborted
|
||||
|
||||
bool to_Abort; // set by externals when the event is aborted, aborted events don't execute
|
||||
// and get Abort call when deleted
|
||||
bool to_Abort; // set by externals when the event is aborted, aborted events don't execute
|
||||
// and get Abort call when deleted
|
||||
|
||||
// these can be used for time offset control
|
||||
uint64 m_addTime; // time when the event was added to queue, filled by event handler
|
||||
uint64 m_execTime; // planned time of next execution, filled by event handler
|
||||
// these can be used for time offset control
|
||||
uint64 m_addTime; // time when the event was added to queue, filled by event handler
|
||||
uint64 m_execTime; // planned time of next execution, filled by event handler
|
||||
};
|
||||
|
||||
typedef std::multimap<uint64, BasicEvent*> EventList;
|
||||
|
||||
class EventProcessor
|
||||
{
|
||||
public:
|
||||
EventProcessor();
|
||||
~EventProcessor();
|
||||
public:
|
||||
EventProcessor();
|
||||
~EventProcessor();
|
||||
|
||||
void Update(uint32 p_time);
|
||||
void KillAllEvents(bool force);
|
||||
void AddEvent(BasicEvent* Event, uint64 e_time, bool set_addtime = true);
|
||||
uint64 CalculateTime(uint64 t_offset) const;
|
||||
void Update(uint32 p_time);
|
||||
void KillAllEvents(bool force);
|
||||
void AddEvent(BasicEvent* Event, uint64 e_time, bool set_addtime = true);
|
||||
uint64 CalculateTime(uint64 t_offset) const;
|
||||
|
||||
// Xinef: calculates next queue tick time
|
||||
uint64 CalculateQueueTime(uint64 delay) const;
|
||||
// Xinef: calculates next queue tick time
|
||||
uint64 CalculateQueueTime(uint64 delay) const;
|
||||
|
||||
protected:
|
||||
uint64 m_time;
|
||||
EventList m_events;
|
||||
bool m_aborting;
|
||||
protected:
|
||||
uint64 m_time;
|
||||
EventList m_events;
|
||||
bool m_aborting;
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
extern int main(int argc, char ** argv);
|
||||
extern int main(int argc, char** argv);
|
||||
extern char serviceLongName[];
|
||||
extern char serviceName[];
|
||||
extern char serviceDescription[];
|
||||
@@ -36,7 +36,7 @@ SERVICE_STATUS serviceStatus;
|
||||
|
||||
SERVICE_STATUS_HANDLE serviceStatusHandle = 0;
|
||||
|
||||
typedef WINADVAPI BOOL (WINAPI *CSD_T)(SC_HANDLE, DWORD, LPCVOID);
|
||||
typedef WINADVAPI BOOL (WINAPI* CSD_T)(SC_HANDLE, DWORD, LPCVOID);
|
||||
|
||||
bool WinServiceInstall()
|
||||
{
|
||||
@@ -45,24 +45,24 @@ bool WinServiceInstall()
|
||||
if (serviceControlManager)
|
||||
{
|
||||
char path[_MAX_PATH + 10];
|
||||
if (GetModuleFileName( 0, path, sizeof(path)/sizeof(path[0]) ) > 0)
|
||||
if (GetModuleFileName( 0, path, sizeof(path) / sizeof(path[0]) ) > 0)
|
||||
{
|
||||
SC_HANDLE service;
|
||||
std::strcat(path, " --service");
|
||||
service = CreateService(serviceControlManager,
|
||||
serviceName, // name of service
|
||||
serviceLongName, // service name to display
|
||||
SERVICE_ALL_ACCESS, // desired access
|
||||
// service type
|
||||
SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS,
|
||||
SERVICE_AUTO_START, // start type
|
||||
SERVICE_ERROR_IGNORE, // error control type
|
||||
path, // service's binary
|
||||
0, // no load ordering group
|
||||
0, // no tag identifier
|
||||
0, // no dependencies
|
||||
0, // LocalSystem account
|
||||
0); // no password
|
||||
serviceName, // name of service
|
||||
serviceLongName, // service name to display
|
||||
SERVICE_ALL_ACCESS, // desired access
|
||||
// service type
|
||||
SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS,
|
||||
SERVICE_AUTO_START, // start type
|
||||
SERVICE_ERROR_IGNORE, // error control type
|
||||
path, // service's binary
|
||||
0, // no load ordering group
|
||||
0, // no tag identifier
|
||||
0, // no dependencies
|
||||
0, // LocalSystem account
|
||||
0); // no password
|
||||
if (service)
|
||||
{
|
||||
HMODULE advapi32 = GetModuleHandle("ADVAPI32.DLL");
|
||||
@@ -95,7 +95,7 @@ bool WinServiceInstall()
|
||||
ZeroMemory(&sfa, sizeof(SERVICE_FAILURE_ACTIONS));
|
||||
sfa.lpsaActions = _action;
|
||||
sfa.cActions = 1;
|
||||
sfa.dwResetPeriod =INFINITE;
|
||||
sfa.dwResetPeriod = INFINITE;
|
||||
ChangeService_Config2(
|
||||
service, // handle to service
|
||||
SERVICE_CONFIG_FAILURE_ACTIONS, // information level
|
||||
@@ -117,7 +117,7 @@ bool WinServiceUninstall()
|
||||
if (serviceControlManager)
|
||||
{
|
||||
SC_HANDLE service = OpenService(serviceControlManager,
|
||||
serviceName, SERVICE_QUERY_STATUS | DELETE);
|
||||
serviceName, SERVICE_QUERY_STATUS | DELETE);
|
||||
if (service)
|
||||
{
|
||||
SERVICE_STATUS serviceStatus2;
|
||||
@@ -173,7 +173,7 @@ void WINAPI ServiceControlHandler(DWORD controlCode)
|
||||
SetServiceStatus(serviceStatusHandle, &serviceStatus);
|
||||
}
|
||||
|
||||
void WINAPI ServiceMain(DWORD argc, char *argv[])
|
||||
void WINAPI ServiceMain(DWORD argc, char* argv[])
|
||||
{
|
||||
// initialise service status
|
||||
serviceStatus.dwServiceType = SERVICE_WIN32;
|
||||
@@ -191,7 +191,7 @@ void WINAPI ServiceMain(DWORD argc, char *argv[])
|
||||
char path[_MAX_PATH + 1];
|
||||
unsigned int i, last_slash = 0;
|
||||
|
||||
GetModuleFileName(0, path, sizeof(path)/sizeof(path[0]));
|
||||
GetModuleFileName(0, path, sizeof(path) / sizeof(path[0]));
|
||||
|
||||
for (i = 0; i < std::strlen(path); i++)
|
||||
{
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
namespace acore
|
||||
{
|
||||
|
||||
/// Handle termination signals
|
||||
class SignalHandler : public ACE_Event_Handler
|
||||
{
|
||||
/// Handle termination signals
|
||||
class SignalHandler : public ACE_Event_Handler
|
||||
{
|
||||
public:
|
||||
int handle_signal(int SigNum, siginfo_t* = NULL, ucontext_t* = NULL)
|
||||
{
|
||||
@@ -22,7 +22,7 @@ class SignalHandler : public ACE_Event_Handler
|
||||
return 0;
|
||||
}
|
||||
virtual void HandleSignal(int /*SigNum*/) { };
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -50,158 +50,158 @@ inline uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
|
||||
|
||||
struct IntervalTimer
|
||||
{
|
||||
public:
|
||||
public:
|
||||
|
||||
IntervalTimer()
|
||||
: _interval(0), _current(0)
|
||||
{
|
||||
}
|
||||
IntervalTimer()
|
||||
: _interval(0), _current(0)
|
||||
{
|
||||
}
|
||||
|
||||
void Update(time_t diff)
|
||||
{
|
||||
_current += diff;
|
||||
if (_current < 0)
|
||||
_current = 0;
|
||||
}
|
||||
void Update(time_t diff)
|
||||
{
|
||||
_current += diff;
|
||||
if (_current < 0)
|
||||
_current = 0;
|
||||
}
|
||||
|
||||
bool Passed()
|
||||
{
|
||||
return _current >= _interval;
|
||||
}
|
||||
bool Passed()
|
||||
{
|
||||
return _current >= _interval;
|
||||
}
|
||||
|
||||
void Reset()
|
||||
{
|
||||
if (_current >= _interval)
|
||||
_current %= _interval;
|
||||
}
|
||||
void Reset()
|
||||
{
|
||||
if (_current >= _interval)
|
||||
_current %= _interval;
|
||||
}
|
||||
|
||||
void SetCurrent(time_t current)
|
||||
{
|
||||
_current = current;
|
||||
}
|
||||
void SetCurrent(time_t current)
|
||||
{
|
||||
_current = current;
|
||||
}
|
||||
|
||||
void SetInterval(time_t interval)
|
||||
{
|
||||
_interval = interval;
|
||||
}
|
||||
void SetInterval(time_t interval)
|
||||
{
|
||||
_interval = interval;
|
||||
}
|
||||
|
||||
time_t GetInterval() const
|
||||
{
|
||||
return _interval;
|
||||
}
|
||||
time_t GetInterval() const
|
||||
{
|
||||
return _interval;
|
||||
}
|
||||
|
||||
time_t GetCurrent() const
|
||||
{
|
||||
return _current;
|
||||
}
|
||||
time_t GetCurrent() const
|
||||
{
|
||||
return _current;
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
time_t _interval;
|
||||
time_t _current;
|
||||
time_t _interval;
|
||||
time_t _current;
|
||||
};
|
||||
|
||||
struct TimeTracker
|
||||
{
|
||||
public:
|
||||
public:
|
||||
|
||||
TimeTracker(time_t expiry)
|
||||
: i_expiryTime(expiry)
|
||||
{
|
||||
}
|
||||
TimeTracker(time_t expiry)
|
||||
: i_expiryTime(expiry)
|
||||
{
|
||||
}
|
||||
|
||||
void Update(time_t diff)
|
||||
{
|
||||
i_expiryTime -= diff;
|
||||
}
|
||||
void Update(time_t diff)
|
||||
{
|
||||
i_expiryTime -= diff;
|
||||
}
|
||||
|
||||
bool Passed() const
|
||||
{
|
||||
return i_expiryTime <= 0;
|
||||
}
|
||||
bool Passed() const
|
||||
{
|
||||
return i_expiryTime <= 0;
|
||||
}
|
||||
|
||||
void Reset(time_t interval)
|
||||
{
|
||||
i_expiryTime = interval;
|
||||
}
|
||||
void Reset(time_t interval)
|
||||
{
|
||||
i_expiryTime = interval;
|
||||
}
|
||||
|
||||
time_t GetExpiry() const
|
||||
{
|
||||
return i_expiryTime;
|
||||
}
|
||||
time_t GetExpiry() const
|
||||
{
|
||||
return i_expiryTime;
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
time_t i_expiryTime;
|
||||
time_t i_expiryTime;
|
||||
};
|
||||
|
||||
struct TimeTrackerSmall
|
||||
{
|
||||
public:
|
||||
public:
|
||||
|
||||
TimeTrackerSmall(uint32 expiry = 0)
|
||||
: i_expiryTime(expiry)
|
||||
{
|
||||
}
|
||||
TimeTrackerSmall(uint32 expiry = 0)
|
||||
: i_expiryTime(expiry)
|
||||
{
|
||||
}
|
||||
|
||||
void Update(int32 diff)
|
||||
{
|
||||
i_expiryTime -= diff;
|
||||
}
|
||||
void Update(int32 diff)
|
||||
{
|
||||
i_expiryTime -= diff;
|
||||
}
|
||||
|
||||
bool Passed() const
|
||||
{
|
||||
return i_expiryTime <= 0;
|
||||
}
|
||||
bool Passed() const
|
||||
{
|
||||
return i_expiryTime <= 0;
|
||||
}
|
||||
|
||||
void Reset(uint32 interval)
|
||||
{
|
||||
i_expiryTime = interval;
|
||||
}
|
||||
void Reset(uint32 interval)
|
||||
{
|
||||
i_expiryTime = interval;
|
||||
}
|
||||
|
||||
int32 GetExpiry() const
|
||||
{
|
||||
return i_expiryTime;
|
||||
}
|
||||
int32 GetExpiry() const
|
||||
{
|
||||
return i_expiryTime;
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
int32 i_expiryTime;
|
||||
int32 i_expiryTime;
|
||||
};
|
||||
|
||||
struct PeriodicTimer
|
||||
{
|
||||
public:
|
||||
public:
|
||||
|
||||
PeriodicTimer(int32 period, int32 start_time)
|
||||
: i_period(period), i_expireTime(start_time)
|
||||
{
|
||||
}
|
||||
PeriodicTimer(int32 period, int32 start_time)
|
||||
: i_period(period), i_expireTime(start_time)
|
||||
{
|
||||
}
|
||||
|
||||
bool Update(const uint32 diff)
|
||||
{
|
||||
if ((i_expireTime -= diff) > 0)
|
||||
return false;
|
||||
bool Update(const uint32 diff)
|
||||
{
|
||||
if ((i_expireTime -= diff) > 0)
|
||||
return false;
|
||||
|
||||
i_expireTime += i_period > int32(diff) ? i_period : diff;
|
||||
return true;
|
||||
}
|
||||
i_expireTime += i_period > int32(diff) ? i_period : diff;
|
||||
return true;
|
||||
}
|
||||
|
||||
void SetPeriodic(int32 period, int32 start_time)
|
||||
{
|
||||
i_expireTime = start_time;
|
||||
i_period = period;
|
||||
}
|
||||
void SetPeriodic(int32 period, int32 start_time)
|
||||
{
|
||||
i_expireTime = start_time;
|
||||
i_period = period;
|
||||
}
|
||||
|
||||
// Tracker interface
|
||||
void TUpdate(int32 diff) { i_expireTime -= diff; }
|
||||
bool TPassed() const { return i_expireTime <= 0; }
|
||||
void TReset(int32 diff, int32 period) { i_expireTime += period > diff ? period : diff; }
|
||||
// Tracker interface
|
||||
void TUpdate(int32 diff) { i_expireTime -= diff; }
|
||||
bool TPassed() const { return i_expireTime <= 0; }
|
||||
void TReset(int32 diff, int32 period) { i_expireTime += period > diff ? period : diff; }
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
int32 i_period;
|
||||
int32 i_expireTime;
|
||||
int32 i_period;
|
||||
int32 i_expireTime;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -68,7 +68,7 @@ SFMTEngine& SFMTEngine::Instance()
|
||||
return engine;
|
||||
}
|
||||
|
||||
Tokenizer::Tokenizer(const std::string &src, const char sep, uint32 vectorReserve)
|
||||
Tokenizer::Tokenizer(const std::string& src, const char sep, uint32 vectorReserve)
|
||||
{
|
||||
m_str = new char[src.length() + 1];
|
||||
memcpy(m_str, src.c_str(), src.length() + 1);
|
||||
@@ -141,7 +141,7 @@ time_t GetLocalHourTimestamp(time_t time, uint8 hour, bool onlyAfterTime)
|
||||
return hourLocal;
|
||||
}
|
||||
|
||||
void stripLineInvisibleChars(std::string &str)
|
||||
void stripLineInvisibleChars(std::string& str)
|
||||
{
|
||||
static std::string const invChars = " \t\7\n";
|
||||
|
||||
@@ -150,7 +150,7 @@ void stripLineInvisibleChars(std::string &str)
|
||||
bool space = false;
|
||||
for (size_t pos = 0; pos < str.size(); ++pos)
|
||||
{
|
||||
if (invChars.find(str[pos])!=std::string::npos)
|
||||
if (invChars.find(str[pos]) != std::string::npos)
|
||||
{
|
||||
if (!space)
|
||||
{
|
||||
@@ -160,7 +160,7 @@ void stripLineInvisibleChars(std::string &str)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (wpos!=pos)
|
||||
if (wpos != pos)
|
||||
str[wpos++] = str[pos];
|
||||
else
|
||||
++wpos;
|
||||
@@ -170,7 +170,7 @@ void stripLineInvisibleChars(std::string &str)
|
||||
|
||||
if (wpos < str.size())
|
||||
str.erase(wpos, str.size());
|
||||
if (str.find("|TInterface")!=std::string::npos)
|
||||
if (str.find("|TInterface") != std::string::npos)
|
||||
str.clear();
|
||||
|
||||
}
|
||||
@@ -194,8 +194,8 @@ std::string secsToTimeString(uint64 timeInSecs, bool shortText)
|
||||
|
||||
std::string str = ss.str();
|
||||
|
||||
if (!shortText && !str.empty() && str[str.size()-1] == ' ')
|
||||
str.resize(str.size()-1);
|
||||
if (!shortText && !str.empty() && str[str.size() - 1] == ' ')
|
||||
str.resize(str.size() - 1);
|
||||
|
||||
return str;
|
||||
}
|
||||
@@ -205,8 +205,8 @@ int32 MoneyStringToMoney(const std::string& moneyString)
|
||||
int32 money = 0;
|
||||
|
||||
if (!(std::count(moneyString.begin(), moneyString.end(), 'g') == 1 ||
|
||||
std::count(moneyString.begin(), moneyString.end(), 's') == 1 ||
|
||||
std::count(moneyString.begin(), moneyString.end(), 'c') == 1))
|
||||
std::count(moneyString.begin(), moneyString.end(), 's') == 1 ||
|
||||
std::count(moneyString.begin(), moneyString.end(), 'c') == 1))
|
||||
return 0; // Bad format
|
||||
|
||||
Tokenizer tokens(moneyString, ' ');
|
||||
@@ -241,22 +241,31 @@ uint32 TimeStringToSecs(const std::string& timestring)
|
||||
{
|
||||
if (isdigit(*itr))
|
||||
{
|
||||
buffer*=10;
|
||||
buffer+= (*itr)-'0';
|
||||
buffer *= 10;
|
||||
buffer += (*itr) - '0';
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (*itr)
|
||||
{
|
||||
case 'd': multiplier = DAY; break;
|
||||
case 'h': multiplier = HOUR; break;
|
||||
case 'm': multiplier = MINUTE; break;
|
||||
case 's': multiplier = 1; break;
|
||||
default : return 0; //bad format
|
||||
case 'd':
|
||||
multiplier = DAY;
|
||||
break;
|
||||
case 'h':
|
||||
multiplier = HOUR;
|
||||
break;
|
||||
case 'm':
|
||||
multiplier = MINUTE;
|
||||
break;
|
||||
case 's':
|
||||
multiplier = 1;
|
||||
break;
|
||||
default :
|
||||
return 0; //bad format
|
||||
}
|
||||
buffer*=multiplier;
|
||||
secs+=buffer;
|
||||
buffer=0;
|
||||
buffer *= multiplier;
|
||||
secs += buffer;
|
||||
buffer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,7 +283,7 @@ std::string TimeToTimestampStr(time_t t)
|
||||
// MM minutes (2 digits 00-59)
|
||||
// SS seconds (2 digits 00-59)
|
||||
char buf[20];
|
||||
int ret = snprintf(buf, 20, "%04d-%02d-%02d_%02d-%02d-%02d", aTm.tm_year+1900, aTm.tm_mon+1, aTm.tm_mday, aTm.tm_hour, aTm.tm_min, aTm.tm_sec);
|
||||
int ret = snprintf(buf, 20, "%04d-%02d-%02d_%02d-%02d-%02d", aTm.tm_year + 1900, aTm.tm_mon + 1, aTm.tm_mday, aTm.tm_hour, aTm.tm_min, aTm.tm_sec);
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
@@ -349,7 +358,7 @@ size_t utf8length(std::string& utf8str)
|
||||
{
|
||||
try
|
||||
{
|
||||
return utf8::distance(utf8str.c_str(), utf8str.c_str()+utf8str.size());
|
||||
return utf8::distance(utf8str.c_str(), utf8str.c_str() + utf8str.size());
|
||||
}
|
||||
catch(std::exception const&)
|
||||
{
|
||||
@@ -362,16 +371,16 @@ void utf8truncate(std::string& utf8str, size_t len)
|
||||
{
|
||||
try
|
||||
{
|
||||
size_t wlen = utf8::distance(utf8str.c_str(), utf8str.c_str()+utf8str.size());
|
||||
size_t wlen = utf8::distance(utf8str.c_str(), utf8str.c_str() + utf8str.size());
|
||||
if (wlen <= len)
|
||||
return;
|
||||
|
||||
std::wstring wstr;
|
||||
wstr.resize(wlen);
|
||||
utf8::utf8to16(utf8str.c_str(), utf8str.c_str()+utf8str.size(), &wstr[0]);
|
||||
utf8::utf8to16(utf8str.c_str(), utf8str.c_str() + utf8str.size(), &wstr[0]);
|
||||
wstr.resize(len);
|
||||
char* oend = utf8::utf16to8(wstr.c_str(), wstr.c_str()+wstr.size(), &utf8str[0]);
|
||||
utf8str.resize(oend-(&utf8str[0])); // remove unused tail
|
||||
char* oend = utf8::utf16to8(wstr.c_str(), wstr.c_str() + wstr.size(), &utf8str[0]);
|
||||
utf8str.resize(oend - (&utf8str[0])); // remove unused tail
|
||||
}
|
||||
catch(std::exception const&)
|
||||
{
|
||||
@@ -384,7 +393,7 @@ bool Utf8toWStr(char const* utf8str, size_t csize, wchar_t* wstr, size_t& wsize)
|
||||
try
|
||||
{
|
||||
acore::CheckedBufferOutputIterator<wchar_t> out(wstr, wsize);
|
||||
out = utf8::utf8to16(utf8str, utf8str+csize, out);
|
||||
out = utf8::utf8to16(utf8str, utf8str + csize, out);
|
||||
wsize -= out.remaining(); // remaining unused space
|
||||
wstr[wsize] = L'\0';
|
||||
}
|
||||
@@ -418,7 +427,7 @@ bool Utf8toWStr(const std::string& utf8str, std::wstring& wstr)
|
||||
wstr.clear();
|
||||
try
|
||||
{
|
||||
utf8::utf8to16(utf8str.c_str(), utf8str.c_str()+utf8str.size(), std::back_inserter(wstr));
|
||||
utf8::utf8to16(utf8str.c_str(), utf8str.c_str() + utf8str.size(), std::back_inserter(wstr));
|
||||
}
|
||||
catch(std::exception const&)
|
||||
{
|
||||
@@ -434,12 +443,12 @@ bool WStrToUtf8(wchar_t* wstr, size_t size, std::string& utf8str)
|
||||
try
|
||||
{
|
||||
std::string utf8str2;
|
||||
utf8str2.resize(size*4); // allocate for most long case
|
||||
utf8str2.resize(size * 4); // allocate for most long case
|
||||
|
||||
if (size)
|
||||
{
|
||||
char* oend = utf8::utf16to8(wstr, wstr+size, &utf8str2[0]);
|
||||
utf8str2.resize(oend-(&utf8str2[0])); // remove unused tail
|
||||
char* oend = utf8::utf16to8(wstr, wstr + size, &utf8str2[0]);
|
||||
utf8str2.resize(oend - (&utf8str2[0])); // remove unused tail
|
||||
}
|
||||
utf8str = utf8str2;
|
||||
}
|
||||
@@ -457,12 +466,12 @@ bool WStrToUtf8(std::wstring const& wstr, std::string& utf8str)
|
||||
try
|
||||
{
|
||||
std::string utf8str2;
|
||||
utf8str2.resize(wstr.size()*4); // allocate for most long case
|
||||
utf8str2.resize(wstr.size() * 4); // allocate for most long case
|
||||
|
||||
if (wstr.size())
|
||||
{
|
||||
char* oend = utf8::utf16to8(wstr.c_str(), wstr.c_str()+wstr.size(), &utf8str2[0]);
|
||||
utf8str2.resize(oend-(&utf8str2[0])); // remove unused tail
|
||||
char* oend = utf8::utf16to8(wstr.c_str(), wstr.c_str() + wstr.size(), &utf8str2[0]);
|
||||
utf8str2.resize(oend - (&utf8str2[0])); // remove unused tail
|
||||
}
|
||||
utf8str = utf8str2;
|
||||
}
|
||||
@@ -512,13 +521,14 @@ std::wstring GetMainPartOfName(std::wstring const& wname, uint32 declension)
|
||||
static std::wstring const j_End = { wchar_t(0x0439), wchar_t(0x0000) };
|
||||
|
||||
static std::array<std::array<std::wstring const*, 7>, 6> const dropEnds = {{
|
||||
{ &a_End, &o_End, &ya_End, &ie_End, &soft_End, &j_End, nullptr },
|
||||
{ &a_End, &ya_End, &yeru_End, &i_End, nullptr, nullptr, nullptr },
|
||||
{ &ie_End, &u_End, &yu_End, &i_End, nullptr, nullptr, nullptr },
|
||||
{ &u_End, &yu_End, &o_End, &ie_End, &soft_End, &ya_End, &a_End },
|
||||
{ &oj_End, &io_j_End, &ie_j_End, &o_m_End, &io_m_End, &ie_m_End, &yu_End },
|
||||
{ &ie_End, &i_End, nullptr, nullptr, nullptr, nullptr, nullptr }
|
||||
}};
|
||||
{ &a_End, &o_End, &ya_End, &ie_End, &soft_End, &j_End, nullptr },
|
||||
{ &a_End, &ya_End, &yeru_End, &i_End, nullptr, nullptr, nullptr },
|
||||
{ &ie_End, &u_End, &yu_End, &i_End, nullptr, nullptr, nullptr },
|
||||
{ &u_End, &yu_End, &o_End, &ie_End, &soft_End, &ya_End, &a_End },
|
||||
{ &oj_End, &io_j_End, &ie_j_End, &o_m_End, &io_m_End, &ie_m_End, &yu_End },
|
||||
{ &ie_End, &i_End, nullptr, nullptr, nullptr, nullptr, nullptr }
|
||||
}
|
||||
};
|
||||
|
||||
std::size_t const thisLen = wname.length();
|
||||
std::array<std::wstring const*, 7> const& endings = dropEnds[declension];
|
||||
@@ -529,8 +539,8 @@ std::wstring GetMainPartOfName(std::wstring const& wname, uint32 declension)
|
||||
if (!(endLen <= thisLen))
|
||||
continue;
|
||||
|
||||
if (wname.substr(thisLen-endLen, thisLen) == ending)
|
||||
return wname.substr(0, thisLen-endLen);
|
||||
if (wname.substr(thisLen - endLen, thisLen) == ending)
|
||||
return wname.substr(0, thisLen - endLen);
|
||||
}
|
||||
|
||||
return wname;
|
||||
@@ -584,7 +594,7 @@ bool Utf8FitTo(const std::string& str, std::wstring const& search)
|
||||
return true;
|
||||
}
|
||||
|
||||
void utf8printf(FILE* out, const char *str, ...)
|
||||
void utf8printf(FILE* out, const char* str, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, str);
|
||||
@@ -592,7 +602,7 @@ void utf8printf(FILE* out, const char *str, ...)
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void vutf8printf(FILE* out, const char *str, va_list* ap)
|
||||
void vutf8printf(FILE* out, const char* str, va_list* ap)
|
||||
{
|
||||
#if AC_PLATFORM == AC_PLATFORM_WINDOWS
|
||||
char temp_buf[32 * 1024];
|
||||
@@ -601,9 +611,9 @@ void vutf8printf(FILE* out, const char *str, va_list* ap)
|
||||
size_t temp_len = vsnprintf(temp_buf, 32 * 1024, str, *ap);
|
||||
//vsnprintf returns -1 if the buffer is too small
|
||||
if (temp_len == size_t(-1))
|
||||
temp_len = 32*1024-1;
|
||||
temp_len = 32 * 1024 - 1;
|
||||
|
||||
size_t wtemp_len = 32*1024-1;
|
||||
size_t wtemp_len = 32 * 1024 - 1;
|
||||
Utf8toWStr(temp_buf, temp_len, wtemp_buf, wtemp_len);
|
||||
|
||||
CharToOemBuffW(&wtemp_buf[0], &temp_buf[0], uint32(wtemp_len + 1));
|
||||
@@ -683,5 +693,5 @@ bool StringToBool(std::string const& str)
|
||||
bool StringContainsStringI(std::string const& haystack, std::string const& needle)
|
||||
{
|
||||
return haystack.end() !=
|
||||
std::search(haystack.begin(), haystack.end(), needle.begin(), needle.end(), [](char c1, char c2) { return std::toupper(c1) == std::toupper(c2); });
|
||||
std::search(haystack.begin(), haystack.end(), needle.begin(), needle.end(), [](char c1, char c2) { return std::toupper(c1) == std::toupper(c2); });
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ template<typename T, class S> struct Finder
|
||||
T S::* idMember_;
|
||||
|
||||
Finder(T val, T S::* idMember) : val_(val), idMember_(idMember) {}
|
||||
bool operator()(const std::pair<int, S> &obj) { return obj.second.*idMember_ == val_; }
|
||||
bool operator()(const std::pair<int, S>& obj) { return obj.second.*idMember_ == val_; }
|
||||
};
|
||||
|
||||
class Tokenizer
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
typedef StorageType::const_reference const_reference;
|
||||
|
||||
public:
|
||||
Tokenizer(const std::string &src, char const sep, uint32 vectorReserve = 0);
|
||||
Tokenizer(const std::string& src, char const sep, uint32 vectorReserve = 0);
|
||||
~Tokenizer() { delete[] m_str; }
|
||||
|
||||
const_iterator begin() const { return m_storage.begin(); }
|
||||
@@ -61,7 +61,7 @@ time_t LocalTimeToUTCTime(time_t time);
|
||||
time_t GetLocalHourTimestamp(time_t time, uint8 hour, bool onlyAfterTime = true);
|
||||
tm TimeBreakdown(time_t t);
|
||||
|
||||
void stripLineInvisibleChars(std::string &src);
|
||||
void stripLineInvisibleChars(std::string& src);
|
||||
|
||||
int32 MoneyStringToMoney(const std::string& moneyString);
|
||||
|
||||
@@ -117,13 +117,13 @@ inline T CalculatePct(T base, U pct)
|
||||
}
|
||||
|
||||
template <class T, class U>
|
||||
inline T AddPct(T &base, U pct)
|
||||
inline T AddPct(T& base, U pct)
|
||||
{
|
||||
return base += CalculatePct(base, pct);
|
||||
}
|
||||
|
||||
template <class T, class U>
|
||||
inline T ApplyPct(T &base, U pct)
|
||||
inline T ApplyPct(T& base, U pct)
|
||||
{
|
||||
return base = CalculatePct(base, pct);
|
||||
}
|
||||
@@ -215,12 +215,12 @@ inline bool isEastAsianCharacter(wchar_t wchar)
|
||||
|
||||
inline bool isNumeric(wchar_t wchar)
|
||||
{
|
||||
return (wchar >= L'0' && wchar <=L'9');
|
||||
return (wchar >= L'0' && wchar <= L'9');
|
||||
}
|
||||
|
||||
inline bool isNumeric(char c)
|
||||
{
|
||||
return (c >= '0' && c <='9');
|
||||
return (c >= '0' && c <= '9');
|
||||
}
|
||||
|
||||
inline bool isNumeric(char const* str)
|
||||
@@ -237,7 +237,7 @@ inline bool isNumericOrSpace(wchar_t wchar)
|
||||
return isNumeric(wchar) || wchar == L' ';
|
||||
}
|
||||
|
||||
inline bool isBasicLatinString(const std::wstring &wstr, bool numericOrSpace)
|
||||
inline bool isBasicLatinString(const std::wstring& wstr, bool numericOrSpace)
|
||||
{
|
||||
for (size_t i = 0; i < wstr.size(); ++i)
|
||||
if (!isBasicLatinCharacter(wstr[i]) && (!numericOrSpace || !isNumericOrSpace(wstr[i])))
|
||||
@@ -245,7 +245,7 @@ inline bool isBasicLatinString(const std::wstring &wstr, bool numericOrSpace)
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool isExtendedLatinString(const std::wstring &wstr, bool numericOrSpace)
|
||||
inline bool isExtendedLatinString(const std::wstring& wstr, bool numericOrSpace)
|
||||
{
|
||||
for (size_t i = 0; i < wstr.size(); ++i)
|
||||
if (!isExtendedLatinCharacter(wstr[i]) && (!numericOrSpace || !isNumericOrSpace(wstr[i])))
|
||||
@@ -253,7 +253,7 @@ inline bool isExtendedLatinString(const std::wstring &wstr, bool numericOrSpace)
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool isCyrillicString(const std::wstring &wstr, bool numericOrSpace)
|
||||
inline bool isCyrillicString(const std::wstring& wstr, bool numericOrSpace)
|
||||
{
|
||||
for (size_t i = 0; i < wstr.size(); ++i)
|
||||
if (!isCyrillicCharacter(wstr[i]) && (!numericOrSpace || !isNumericOrSpace(wstr[i])))
|
||||
@@ -261,7 +261,7 @@ inline bool isCyrillicString(const std::wstring &wstr, bool numericOrSpace)
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool isEastAsianString(const std::wstring &wstr, bool numericOrSpace)
|
||||
inline bool isEastAsianString(const std::wstring& wstr, bool numericOrSpace)
|
||||
{
|
||||
for (size_t i = 0; i < wstr.size(); ++i)
|
||||
if (!isEastAsianCharacter(wstr[i]) && (!numericOrSpace || !isNumericOrSpace(wstr[i])))
|
||||
@@ -272,20 +272,20 @@ inline bool isEastAsianString(const std::wstring &wstr, bool numericOrSpace)
|
||||
inline wchar_t wcharToUpper(wchar_t wchar)
|
||||
{
|
||||
if (wchar >= L'a' && wchar <= L'z') // LATIN SMALL LETTER A - LATIN SMALL LETTER Z
|
||||
return wchar_t(uint16(wchar)-0x0020);
|
||||
return wchar_t(uint16(wchar) - 0x0020);
|
||||
if (wchar == 0x00DF) // LATIN SMALL LETTER SHARP S
|
||||
return wchar_t(0x1E9E);
|
||||
if (wchar >= 0x00E0 && wchar <= 0x00F6) // LATIN SMALL LETTER A WITH GRAVE - LATIN SMALL LETTER O WITH DIAERESIS
|
||||
return wchar_t(uint16(wchar)-0x0020);
|
||||
return wchar_t(uint16(wchar) - 0x0020);
|
||||
if (wchar >= 0x00F8 && wchar <= 0x00FE) // LATIN SMALL LETTER O WITH STROKE - LATIN SMALL LETTER THORN
|
||||
return wchar_t(uint16(wchar)-0x0020);
|
||||
return wchar_t(uint16(wchar) - 0x0020);
|
||||
if (wchar >= 0x0101 && wchar <= 0x012F) // LATIN SMALL LETTER A WITH MACRON - LATIN SMALL LETTER I WITH OGONEK (only %2=1)
|
||||
{
|
||||
if (wchar % 2 == 1)
|
||||
return wchar_t(uint16(wchar)-0x0001);
|
||||
return wchar_t(uint16(wchar) - 0x0001);
|
||||
}
|
||||
if (wchar >= 0x0430 && wchar <= 0x044F) // CYRILLIC SMALL LETTER A - CYRILLIC SMALL LETTER YA
|
||||
return wchar_t(uint16(wchar)-0x0020);
|
||||
return wchar_t(uint16(wchar) - 0x0020);
|
||||
if (wchar == 0x0451) // CYRILLIC SMALL LETTER IO
|
||||
return wchar_t(0x0401);
|
||||
|
||||
@@ -300,22 +300,22 @@ inline wchar_t wcharToUpperOnlyLatin(wchar_t wchar)
|
||||
inline wchar_t wcharToLower(wchar_t wchar)
|
||||
{
|
||||
if (wchar >= L'A' && wchar <= L'Z') // LATIN CAPITAL LETTER A - LATIN CAPITAL LETTER Z
|
||||
return wchar_t(uint16(wchar)+0x0020);
|
||||
return wchar_t(uint16(wchar) + 0x0020);
|
||||
if (wchar >= 0x00C0 && wchar <= 0x00D6) // LATIN CAPITAL LETTER A WITH GRAVE - LATIN CAPITAL LETTER O WITH DIAERESIS
|
||||
return wchar_t(uint16(wchar)+0x0020);
|
||||
return wchar_t(uint16(wchar) + 0x0020);
|
||||
if (wchar >= 0x00D8 && wchar <= 0x00DE) // LATIN CAPITAL LETTER O WITH STROKE - LATIN CAPITAL LETTER THORN
|
||||
return wchar_t(uint16(wchar)+0x0020);
|
||||
return wchar_t(uint16(wchar) + 0x0020);
|
||||
if (wchar >= 0x0100 && wchar <= 0x012E) // LATIN CAPITAL LETTER A WITH MACRON - LATIN CAPITAL LETTER I WITH OGONEK (only %2=0)
|
||||
{
|
||||
if (wchar % 2 == 0)
|
||||
return wchar_t(uint16(wchar)+0x0001);
|
||||
return wchar_t(uint16(wchar) + 0x0001);
|
||||
}
|
||||
if (wchar == 0x1E9E) // LATIN CAPITAL LETTER SHARP S
|
||||
return wchar_t(0x00DF);
|
||||
if (wchar == 0x0401) // CYRILLIC CAPITAL LETTER IO
|
||||
return wchar_t(0x0451);
|
||||
if (wchar >= 0x0410 && wchar <= 0x042F) // CYRILLIC CAPITAL LETTER A - CYRILLIC CAPITAL LETTER YA
|
||||
return wchar_t(uint16(wchar)+0x0020);
|
||||
return wchar_t(uint16(wchar) + 0x0020);
|
||||
|
||||
return wchar;
|
||||
}
|
||||
@@ -328,8 +328,8 @@ std::wstring GetMainPartOfName(std::wstring const& wname, uint32 declension);
|
||||
bool utf8ToConsole(const std::string& utf8str, std::string& conStr);
|
||||
bool consoleToUtf8(const std::string& conStr, std::string& utf8str);
|
||||
bool Utf8FitTo(const std::string& str, std::wstring const& search);
|
||||
void utf8printf(FILE* out, const char *str, ...);
|
||||
void vutf8printf(FILE* out, const char *str, va_list* ap);
|
||||
void utf8printf(FILE* out, const char* str, ...);
|
||||
void vutf8printf(FILE* out, const char* str, va_list* ap);
|
||||
bool Utf8ToUpperOnlyLatin(std::string& utf8String);
|
||||
|
||||
bool IsIPAddress(char const* ipaddress);
|
||||
@@ -364,31 +364,31 @@ template <typename T>
|
||||
class HookList
|
||||
{
|
||||
typedef typename std::list<T>::iterator ListIterator;
|
||||
private:
|
||||
typename std::list<T> m_list;
|
||||
public:
|
||||
HookList<T> & operator+=(T t)
|
||||
{
|
||||
m_list.push_back(t);
|
||||
return *this;
|
||||
}
|
||||
HookList<T> & operator-=(T t)
|
||||
{
|
||||
m_list.remove(t);
|
||||
return *this;
|
||||
}
|
||||
size_t size()
|
||||
{
|
||||
return m_list.size();
|
||||
}
|
||||
ListIterator begin()
|
||||
{
|
||||
return m_list.begin();
|
||||
}
|
||||
ListIterator end()
|
||||
{
|
||||
return m_list.end();
|
||||
}
|
||||
private:
|
||||
typename std::list<T> m_list;
|
||||
public:
|
||||
HookList<T>& operator+=(T t)
|
||||
{
|
||||
m_list.push_back(t);
|
||||
return *this;
|
||||
}
|
||||
HookList<T>& operator-=(T t)
|
||||
{
|
||||
m_list.remove(t);
|
||||
return *this;
|
||||
}
|
||||
size_t size()
|
||||
{
|
||||
return m_list.size();
|
||||
}
|
||||
ListIterator begin()
|
||||
{
|
||||
return m_list.begin();
|
||||
}
|
||||
ListIterator end()
|
||||
{
|
||||
return m_list.end();
|
||||
}
|
||||
};
|
||||
|
||||
class flag96
|
||||
@@ -436,11 +436,11 @@ public:
|
||||
inline bool operator==(flag96 const& right) const
|
||||
{
|
||||
return
|
||||
(
|
||||
part[0] == right.part[0] &&
|
||||
part[1] == right.part[1] &&
|
||||
part[2] == right.part[2]
|
||||
);
|
||||
(
|
||||
part[0] == right.part[0] &&
|
||||
part[1] == right.part[1] &&
|
||||
part[2] == right.part[2]
|
||||
);
|
||||
}
|
||||
|
||||
inline bool operator!=(flag96 const& right) const
|
||||
@@ -456,10 +456,10 @@ public:
|
||||
return *this;
|
||||
}
|
||||
/* requried as of C++ 11 */
|
||||
#if __cplusplus >= 201103L
|
||||
#if __cplusplus >= 201103L
|
||||
flag96(const flag96&) = default;
|
||||
flag96(flag96&&) = default;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
inline flag96 operator&(flag96 const& right) const
|
||||
{
|
||||
@@ -577,343 +577,343 @@ class EventMap
|
||||
{
|
||||
typedef std::multimap<uint32, uint32> EventStore;
|
||||
|
||||
public:
|
||||
EventMap() : _time(0), _phase(0) { }
|
||||
public:
|
||||
EventMap() : _time(0), _phase(0) { }
|
||||
|
||||
/**
|
||||
* @name Reset
|
||||
* @brief Removes all scheduled events and resets time and phase.
|
||||
*/
|
||||
void Reset()
|
||||
{
|
||||
_eventMap.clear();
|
||||
_time = 0;
|
||||
/**
|
||||
* @name Reset
|
||||
* @brief Removes all scheduled events and resets time and phase.
|
||||
*/
|
||||
void Reset()
|
||||
{
|
||||
_eventMap.clear();
|
||||
_time = 0;
|
||||
_phase = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @name Update
|
||||
* @brief Updates the timer of the event map.
|
||||
* @param time Value to be added to time.
|
||||
*/
|
||||
void Update(uint32 time)
|
||||
{
|
||||
_time += time;
|
||||
}
|
||||
|
||||
/**
|
||||
* @name GetTimer
|
||||
* @return Current timer value.
|
||||
*/
|
||||
uint32 GetTimer() const
|
||||
{
|
||||
return _time;
|
||||
}
|
||||
|
||||
void SetTimer(uint32 time)
|
||||
{
|
||||
_time = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* @name GetPhaseMask
|
||||
* @return Active phases as mask.
|
||||
*/
|
||||
uint8 GetPhaseMask() const
|
||||
{
|
||||
return _phase;
|
||||
}
|
||||
|
||||
/**
|
||||
* @name Empty
|
||||
* @return True, if there are no events scheduled.
|
||||
*/
|
||||
bool Empty() const
|
||||
{
|
||||
return _eventMap.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* @name SetPhase
|
||||
* @brief Sets the phase of the map (absolute).
|
||||
* @param phase Phase which should be set. Values: 1 - 8. 0 resets phase.
|
||||
*/
|
||||
void SetPhase(uint8 phase)
|
||||
{
|
||||
if (!phase)
|
||||
_phase = 0;
|
||||
}
|
||||
else if (phase <= 8)
|
||||
_phase = (1 << (phase - 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @name Update
|
||||
* @brief Updates the timer of the event map.
|
||||
* @param time Value to be added to time.
|
||||
*/
|
||||
void Update(uint32 time)
|
||||
{
|
||||
_time += time;
|
||||
}
|
||||
/**
|
||||
* @name AddPhase
|
||||
* @brief Activates the given phase (bitwise).
|
||||
* @param phase Phase which should be activated. Values: 1 - 8
|
||||
*/
|
||||
void AddPhase(uint8 phase)
|
||||
{
|
||||
if (phase && phase <= 8)
|
||||
_phase |= (1 << (phase - 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @name GetTimer
|
||||
* @return Current timer value.
|
||||
*/
|
||||
uint32 GetTimer() const
|
||||
{
|
||||
return _time;
|
||||
}
|
||||
/**
|
||||
* @name RemovePhase
|
||||
* @brief Deactivates the given phase (bitwise).
|
||||
* @param phase Phase which should be deactivated. Values: 1 - 8.
|
||||
*/
|
||||
void RemovePhase(uint8 phase)
|
||||
{
|
||||
if (phase && phase <= 8)
|
||||
_phase &= ~(1 << (phase - 1));
|
||||
}
|
||||
|
||||
void SetTimer(uint32 time)
|
||||
{
|
||||
_time = time;
|
||||
}
|
||||
/**
|
||||
* @name ScheduleEvent
|
||||
* @brief Creates new event entry in map.
|
||||
* @param eventId The id of the new event.
|
||||
* @param time The time in milliseconds until the event occurs.
|
||||
* @param group The group which the event is associated to. Has to be between 1 and 8. 0 means it has no group.
|
||||
* @param phase The phase in which the event can occur. Has to be between 1 and 8. 0 means it can occur in all phases.
|
||||
*/
|
||||
void ScheduleEvent(uint32 eventId, uint32 time, uint32 group = 0, uint32 phase = 0)
|
||||
{
|
||||
if (group && group <= 8)
|
||||
eventId |= (1 << (group + 15));
|
||||
|
||||
/**
|
||||
* @name GetPhaseMask
|
||||
* @return Active phases as mask.
|
||||
*/
|
||||
uint8 GetPhaseMask() const
|
||||
{
|
||||
return _phase;
|
||||
}
|
||||
if (phase && phase <= 8)
|
||||
eventId |= (1 << (phase + 23));
|
||||
|
||||
/**
|
||||
* @name Empty
|
||||
* @return True, if there are no events scheduled.
|
||||
*/
|
||||
bool Empty() const
|
||||
{
|
||||
return _eventMap.empty();
|
||||
}
|
||||
_eventMap.insert(EventStore::value_type(_time + time, eventId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @name SetPhase
|
||||
* @brief Sets the phase of the map (absolute).
|
||||
* @param phase Phase which should be set. Values: 1 - 8. 0 resets phase.
|
||||
*/
|
||||
void SetPhase(uint8 phase)
|
||||
{
|
||||
if (!phase)
|
||||
_phase = 0;
|
||||
else if (phase <= 8)
|
||||
_phase = (1 << (phase - 1));
|
||||
}
|
||||
/**
|
||||
* @name RescheduleEvent
|
||||
* @brief Cancels the given event and reschedules it.
|
||||
* @param eventId The id of the event.
|
||||
* @param time The time in milliseconds until the event occurs.
|
||||
* @param group The group which the event is associated to. Has to be between 1 and 8. 0 means it has no group.
|
||||
* @param phase The phase in which the event can occur. Has to be between 1 and 8. 0 means it can occur in all phases.
|
||||
*/
|
||||
void RescheduleEvent(uint32 eventId, uint32 time, uint32 groupId = 0, uint32 phase = 0)
|
||||
{
|
||||
CancelEvent(eventId);
|
||||
ScheduleEvent(eventId, time, groupId, phase);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name AddPhase
|
||||
* @brief Activates the given phase (bitwise).
|
||||
* @param phase Phase which should be activated. Values: 1 - 8
|
||||
*/
|
||||
void AddPhase(uint8 phase)
|
||||
{
|
||||
if (phase && phase <= 8)
|
||||
_phase |= (1 << (phase - 1));
|
||||
}
|
||||
/**
|
||||
* @name RescheduleEvent
|
||||
* @brief Cancels the given event and reschedules it.
|
||||
* @param eventId The id of the event.
|
||||
* @param time The time in milliseconds until the event occurs.
|
||||
* @param group The group which the event is associated to. Has to be between 1 and 8. 0 means it has no group.
|
||||
* @param phase The phase in which the event can occur. Has to be between 1 and 8. 0 means it can occur in all phases.
|
||||
*/
|
||||
void RepeatEvent(uint32 time)
|
||||
{
|
||||
if (Empty())
|
||||
return;
|
||||
|
||||
/**
|
||||
* @name RemovePhase
|
||||
* @brief Deactivates the given phase (bitwise).
|
||||
* @param phase Phase which should be deactivated. Values: 1 - 8.
|
||||
*/
|
||||
void RemovePhase(uint8 phase)
|
||||
{
|
||||
if (phase && phase <= 8)
|
||||
_phase &= ~(1 << (phase - 1));
|
||||
}
|
||||
uint32 eventId = _eventMap.begin()->second;
|
||||
_eventMap.erase(_eventMap.begin());
|
||||
ScheduleEvent(eventId, time);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name ScheduleEvent
|
||||
* @brief Creates new event entry in map.
|
||||
* @param eventId The id of the new event.
|
||||
* @param time The time in milliseconds until the event occurs.
|
||||
* @param group The group which the event is associated to. Has to be between 1 and 8. 0 means it has no group.
|
||||
* @param phase The phase in which the event can occur. Has to be between 1 and 8. 0 means it can occur in all phases.
|
||||
*/
|
||||
void ScheduleEvent(uint32 eventId, uint32 time, uint32 group = 0, uint32 phase = 0)
|
||||
{
|
||||
if (group && group <= 8)
|
||||
eventId |= (1 << (group + 15));
|
||||
|
||||
if (phase && phase <= 8)
|
||||
eventId |= (1 << (phase + 23));
|
||||
|
||||
_eventMap.insert(EventStore::value_type(_time + time, eventId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @name RescheduleEvent
|
||||
* @brief Cancels the given event and reschedules it.
|
||||
* @param eventId The id of the event.
|
||||
* @param time The time in milliseconds until the event occurs.
|
||||
* @param group The group which the event is associated to. Has to be between 1 and 8. 0 means it has no group.
|
||||
* @param phase The phase in which the event can occur. Has to be between 1 and 8. 0 means it can occur in all phases.
|
||||
*/
|
||||
void RescheduleEvent(uint32 eventId, uint32 time, uint32 groupId = 0, uint32 phase = 0)
|
||||
{
|
||||
CancelEvent(eventId);
|
||||
ScheduleEvent(eventId, time, groupId, phase);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name RescheduleEvent
|
||||
* @brief Cancels the given event and reschedules it.
|
||||
* @param eventId The id of the event.
|
||||
* @param time The time in milliseconds until the event occurs.
|
||||
* @param group The group which the event is associated to. Has to be between 1 and 8. 0 means it has no group.
|
||||
* @param phase The phase in which the event can occur. Has to be between 1 and 8. 0 means it can occur in all phases.
|
||||
*/
|
||||
void RepeatEvent(uint32 time)
|
||||
{
|
||||
if (Empty())
|
||||
return;
|
||||
|
||||
uint32 eventId = _eventMap.begin()->second;
|
||||
/**
|
||||
* @name PopEvent
|
||||
* @brief Remove the first event in the map.
|
||||
*/
|
||||
void PopEvent()
|
||||
{
|
||||
if (!Empty())
|
||||
_eventMap.erase(_eventMap.begin());
|
||||
ScheduleEvent(eventId, time);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @name PopEvent
|
||||
* @brief Remove the first event in the map.
|
||||
*/
|
||||
void PopEvent()
|
||||
/**
|
||||
* @name ExecuteEvent
|
||||
* @brief Returns the next event to execute and removes it from map.
|
||||
* @return Id of the event to execute.
|
||||
*/
|
||||
uint32 ExecuteEvent()
|
||||
{
|
||||
while (!Empty())
|
||||
{
|
||||
if (!Empty())
|
||||
_eventMap.erase(_eventMap.begin());
|
||||
}
|
||||
EventStore::iterator itr = _eventMap.begin();
|
||||
|
||||
/**
|
||||
* @name ExecuteEvent
|
||||
* @brief Returns the next event to execute and removes it from map.
|
||||
* @return Id of the event to execute.
|
||||
*/
|
||||
uint32 ExecuteEvent()
|
||||
{
|
||||
while (!Empty())
|
||||
{
|
||||
EventStore::iterator itr = _eventMap.begin();
|
||||
|
||||
if (itr->first > _time)
|
||||
return 0;
|
||||
else if (_phase && (itr->second & 0xFF000000) && !((itr->second >> 24) & _phase))
|
||||
_eventMap.erase(itr);
|
||||
else
|
||||
{
|
||||
uint32 eventId = (itr->second & 0x0000FFFF);
|
||||
_eventMap.erase(itr);
|
||||
return eventId;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @name GetEvent
|
||||
* @brief Returns the next event to execute.
|
||||
* @return Id of the event to execute.
|
||||
*/
|
||||
uint32 GetEvent()
|
||||
{
|
||||
while (!Empty())
|
||||
{
|
||||
EventStore::iterator itr = _eventMap.begin();
|
||||
|
||||
if (itr->first > _time)
|
||||
return 0;
|
||||
else if (_phase && (itr->second & 0xFF000000) && !(itr->second & (_phase << 24)))
|
||||
_eventMap.erase(itr);
|
||||
else
|
||||
return (itr->second & 0x0000FFFF);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @name DelayEvents
|
||||
* @brief Delays all events in the map. If delay is greater than or equal internal timer, delay will be 0.
|
||||
* @param delay Amount of delay.
|
||||
*/
|
||||
void DelayEvents(uint32 delay)
|
||||
{
|
||||
_time = delay < _time ? _time - delay : 0;
|
||||
}
|
||||
|
||||
void DelayEventsToMax(uint32 delay, uint32 group)
|
||||
{
|
||||
for (EventStore::iterator itr = _eventMap.begin(); itr != _eventMap.end();)
|
||||
{
|
||||
if (itr->first < _time+delay && (group == 0 || ((1 << (group + 15)) & itr->second)))
|
||||
{
|
||||
ScheduleEvent(itr->second, delay);
|
||||
_eventMap.erase(itr);
|
||||
itr = _eventMap.begin();
|
||||
}
|
||||
else
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @name DelayEvents
|
||||
* @brief Delay all events of the same group.
|
||||
* @param delay Amount of delay.
|
||||
* @param group Group of the events.
|
||||
*/
|
||||
void DelayEvents(uint32 delay, uint32 group)
|
||||
{
|
||||
if (group > 8 || Empty())
|
||||
return;
|
||||
|
||||
EventStore delayed;
|
||||
|
||||
for (EventStore::iterator itr = _eventMap.begin(); itr != _eventMap.end();)
|
||||
{
|
||||
if (!group || (itr->second & (1 << (group + 15))))
|
||||
{
|
||||
delayed.insert(EventStore::value_type(itr->first + delay, itr->second));
|
||||
_eventMap.erase(itr++);
|
||||
}
|
||||
else
|
||||
++itr;
|
||||
}
|
||||
|
||||
_eventMap.insert(delayed.begin(), delayed.end());
|
||||
}
|
||||
|
||||
/**
|
||||
* @name CancelEvent
|
||||
* @brief Cancels all events of the specified id.
|
||||
* @param eventId Event id to cancel.
|
||||
*/
|
||||
void CancelEvent(uint32 eventId)
|
||||
{
|
||||
if (Empty())
|
||||
return;
|
||||
|
||||
for (EventStore::iterator itr = _eventMap.begin(); itr != _eventMap.end();)
|
||||
{
|
||||
if (eventId == (itr->second & 0x0000FFFF))
|
||||
_eventMap.erase(itr++);
|
||||
else
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @name CancelEventGroup
|
||||
* @brief Cancel events belonging to specified group.
|
||||
* @param group Group to cancel.
|
||||
*/
|
||||
void CancelEventGroup(uint32 group)
|
||||
{
|
||||
if (!group || group > 8 || Empty())
|
||||
return;
|
||||
|
||||
uint32 groupMask = (1 << (group + 15));
|
||||
for (EventStore::iterator itr = _eventMap.begin(); itr != _eventMap.end();)
|
||||
{
|
||||
if (itr->second & groupMask)
|
||||
{
|
||||
_eventMap.erase(itr);
|
||||
itr = _eventMap.begin();
|
||||
}
|
||||
else
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @name GetNextEventTime
|
||||
* @brief Returns closest occurence of specified event.
|
||||
* @param eventId Wanted event id.
|
||||
* @return Time of found event.
|
||||
*/
|
||||
uint32 GetNextEventTime(uint32 eventId) const
|
||||
{
|
||||
if (Empty())
|
||||
if (itr->first > _time)
|
||||
return 0;
|
||||
else if (_phase && (itr->second & 0xFF000000) && !((itr->second >> 24) & _phase))
|
||||
_eventMap.erase(itr);
|
||||
else
|
||||
{
|
||||
uint32 eventId = (itr->second & 0x0000FFFF);
|
||||
_eventMap.erase(itr);
|
||||
return eventId;
|
||||
}
|
||||
}
|
||||
|
||||
for (EventStore::const_iterator itr = _eventMap.begin(); itr != _eventMap.end(); ++itr)
|
||||
if (eventId == (itr->second & 0x0000FFFF))
|
||||
return itr->first;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @name GetEvent
|
||||
* @brief Returns the next event to execute.
|
||||
* @return Id of the event to execute.
|
||||
*/
|
||||
uint32 GetEvent()
|
||||
{
|
||||
while (!Empty())
|
||||
{
|
||||
EventStore::iterator itr = _eventMap.begin();
|
||||
|
||||
if (itr->first > _time)
|
||||
return 0;
|
||||
else if (_phase && (itr->second & 0xFF000000) && !(itr->second & (_phase << 24)))
|
||||
_eventMap.erase(itr);
|
||||
else
|
||||
return (itr->second & 0x0000FFFF);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @name DelayEvents
|
||||
* @brief Delays all events in the map. If delay is greater than or equal internal timer, delay will be 0.
|
||||
* @param delay Amount of delay.
|
||||
*/
|
||||
void DelayEvents(uint32 delay)
|
||||
{
|
||||
_time = delay < _time ? _time - delay : 0;
|
||||
}
|
||||
|
||||
void DelayEventsToMax(uint32 delay, uint32 group)
|
||||
{
|
||||
for (EventStore::iterator itr = _eventMap.begin(); itr != _eventMap.end();)
|
||||
{
|
||||
if (itr->first < _time + delay && (group == 0 || ((1 << (group + 15)) & itr->second)))
|
||||
{
|
||||
ScheduleEvent(itr->second, delay);
|
||||
_eventMap.erase(itr);
|
||||
itr = _eventMap.begin();
|
||||
}
|
||||
else
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @name DelayEvents
|
||||
* @brief Delay all events of the same group.
|
||||
* @param delay Amount of delay.
|
||||
* @param group Group of the events.
|
||||
*/
|
||||
void DelayEvents(uint32 delay, uint32 group)
|
||||
{
|
||||
if (group > 8 || Empty())
|
||||
return;
|
||||
|
||||
EventStore delayed;
|
||||
|
||||
for (EventStore::iterator itr = _eventMap.begin(); itr != _eventMap.end();)
|
||||
{
|
||||
if (!group || (itr->second & (1 << (group + 15))))
|
||||
{
|
||||
delayed.insert(EventStore::value_type(itr->first + delay, itr->second));
|
||||
_eventMap.erase(itr++);
|
||||
}
|
||||
else
|
||||
++itr;
|
||||
}
|
||||
|
||||
_eventMap.insert(delayed.begin(), delayed.end());
|
||||
}
|
||||
|
||||
/**
|
||||
* @name CancelEvent
|
||||
* @brief Cancels all events of the specified id.
|
||||
* @param eventId Event id to cancel.
|
||||
*/
|
||||
void CancelEvent(uint32 eventId)
|
||||
{
|
||||
if (Empty())
|
||||
return;
|
||||
|
||||
for (EventStore::iterator itr = _eventMap.begin(); itr != _eventMap.end();)
|
||||
{
|
||||
if (eventId == (itr->second & 0x0000FFFF))
|
||||
_eventMap.erase(itr++);
|
||||
else
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @name CancelEventGroup
|
||||
* @brief Cancel events belonging to specified group.
|
||||
* @param group Group to cancel.
|
||||
*/
|
||||
void CancelEventGroup(uint32 group)
|
||||
{
|
||||
if (!group || group > 8 || Empty())
|
||||
return;
|
||||
|
||||
uint32 groupMask = (1 << (group + 15));
|
||||
for (EventStore::iterator itr = _eventMap.begin(); itr != _eventMap.end();)
|
||||
{
|
||||
if (itr->second & groupMask)
|
||||
{
|
||||
_eventMap.erase(itr);
|
||||
itr = _eventMap.begin();
|
||||
}
|
||||
else
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @name GetNextEventTime
|
||||
* @brief Returns closest occurence of specified event.
|
||||
* @param eventId Wanted event id.
|
||||
* @return Time of found event.
|
||||
*/
|
||||
uint32 GetNextEventTime(uint32 eventId) const
|
||||
{
|
||||
if (Empty())
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @name GetNextEventTime
|
||||
* @return Time of next event.
|
||||
*/
|
||||
uint32 GetNextEventTime() const
|
||||
{
|
||||
return Empty() ? 0 : _eventMap.begin()->first;
|
||||
}
|
||||
for (EventStore::const_iterator itr = _eventMap.begin(); itr != _eventMap.end(); ++itr)
|
||||
if (eventId == (itr->second & 0x0000FFFF))
|
||||
return itr->first;
|
||||
|
||||
/**
|
||||
* @name IsInPhase
|
||||
* @brief Returns wether event map is in specified phase or not.
|
||||
* @param phase Wanted phase.
|
||||
* @return True, if phase of event map contains specified phase.
|
||||
*/
|
||||
bool IsInPhase(uint8 phase)
|
||||
{
|
||||
return phase <= 8 && (!phase || _phase & (1 << (phase - 1)));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private:
|
||||
uint32 _time;
|
||||
uint32 _phase;
|
||||
/**
|
||||
* @name GetNextEventTime
|
||||
* @return Time of next event.
|
||||
*/
|
||||
uint32 GetNextEventTime() const
|
||||
{
|
||||
return Empty() ? 0 : _eventMap.begin()->first;
|
||||
}
|
||||
|
||||
EventStore _eventMap;
|
||||
/**
|
||||
* @name IsInPhase
|
||||
* @brief Returns wether event map is in specified phase or not.
|
||||
* @param phase Wanted phase.
|
||||
* @return True, if phase of event map contains specified phase.
|
||||
*/
|
||||
bool IsInPhase(uint8 phase)
|
||||
{
|
||||
return phase <= 8 && (!phase || _phase & (1 << (phase - 1)));
|
||||
}
|
||||
|
||||
private:
|
||||
uint32 _time;
|
||||
uint32 _phase;
|
||||
|
||||
EventStore _eventMap;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user