mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-22 17:18:39 +00:00
Code modernization: subfolders (#6283)
* Code modernization: subfolders Modernize various code on subfolders client, network, script, threading, unittests, util * empty function * default constructor/destructor * for range-based loops * use emplace_back instead of push_back * C++ STL header style * Make connection.cpp readable in a pointed place + typo
This commit is contained in:
parent
7528986e44
commit
88b436e6a9
49 changed files with 398 additions and 518 deletions
|
@ -23,7 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "base64.h"
|
||||
#include "sha1.h"
|
||||
#include "srp.h"
|
||||
#include "string.h"
|
||||
#include "util/string.h"
|
||||
#include "debug.h"
|
||||
|
||||
// Get an sha-1 hash of the player's name combined with
|
||||
|
|
|
@ -40,8 +40,9 @@ static inline bool is_base64(unsigned char c) {
|
|||
|
||||
bool base64_is_valid(std::string const& s)
|
||||
{
|
||||
for(size_t i=0; i<s.size(); i++)
|
||||
if(!is_base64(s[i])) return false;
|
||||
for (char i : s)
|
||||
if (!is_base64(i))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ template<typename Key, typename Value>
|
|||
class MutexedMap
|
||||
{
|
||||
public:
|
||||
MutexedMap() {}
|
||||
MutexedMap() = default;
|
||||
|
||||
void set(const Key &name, const Value &value)
|
||||
{
|
||||
|
@ -128,7 +128,8 @@ public:
|
|||
template<typename Key, typename U, typename Caller, typename CallerData>
|
||||
friend class RequestQueue;
|
||||
|
||||
MutexedQueue() {}
|
||||
MutexedQueue() = default;
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
MutexAutoLock lock(m_mutex);
|
||||
|
@ -153,9 +154,9 @@ public:
|
|||
T t = m_queue.front();
|
||||
m_queue.pop_front();
|
||||
return t;
|
||||
} else {
|
||||
return T();
|
||||
}
|
||||
|
||||
return T();
|
||||
}
|
||||
|
||||
T pop_front(u32 wait_time_max_ms)
|
||||
|
@ -166,9 +167,9 @@ public:
|
|||
T t = m_queue.front();
|
||||
m_queue.pop_front();
|
||||
return t;
|
||||
} else {
|
||||
throw ItemNotFoundException("MutexedQueue: queue is empty");
|
||||
}
|
||||
|
||||
throw ItemNotFoundException("MutexedQueue: queue is empty");
|
||||
}
|
||||
|
||||
T pop_frontNoEx()
|
||||
|
@ -190,9 +191,9 @@ public:
|
|||
T t = m_queue.back();
|
||||
m_queue.pop_back();
|
||||
return t;
|
||||
} else {
|
||||
throw ItemNotFoundException("MutexedQueue: queue is empty");
|
||||
}
|
||||
|
||||
throw ItemNotFoundException("MutexedQueue: queue is empty");
|
||||
}
|
||||
|
||||
/* this version of pop_back returns a empty element of T on timeout.
|
||||
|
@ -206,9 +207,9 @@ public:
|
|||
T t = m_queue.back();
|
||||
m_queue.pop_back();
|
||||
return t;
|
||||
} else {
|
||||
return T();
|
||||
}
|
||||
|
||||
return T();
|
||||
}
|
||||
|
||||
T pop_backNoEx()
|
||||
|
|
|
@ -23,7 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "../constants.h" // BS, MAP_BLOCKSIZE
|
||||
#include "../noise.h" // PseudoRandom, PcgRandom
|
||||
#include "../threading/mutex_auto_lock.h"
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
|
||||
|
||||
// myrand
|
||||
|
|
|
@ -81,7 +81,7 @@ struct PointedThing
|
|||
f32 distanceSq = 0;
|
||||
|
||||
//! Constructor for POINTEDTHING_NOTHING
|
||||
PointedThing() {};
|
||||
PointedThing() = default;
|
||||
//! Constructor for POINTEDTHING_NODE
|
||||
PointedThing(const v3s16 &under, const v3s16 &above,
|
||||
const v3s16 &real_under, const v3f &point, const v3s16 &normal,
|
||||
|
|
|
@ -156,8 +156,8 @@ std::string serializeWideString(const std::wstring &plain)
|
|||
writeU16((u8 *)buf, plain.size());
|
||||
s.append(buf, 2);
|
||||
|
||||
for (u32 i = 0; i < plain.size(); i++) {
|
||||
writeU16((u8 *)buf, plain[i]);
|
||||
for (wchar_t i : plain) {
|
||||
writeU16((u8 *)buf, i);
|
||||
s.append(buf, 2);
|
||||
}
|
||||
return s;
|
||||
|
@ -246,8 +246,7 @@ std::string serializeJsonString(const std::string &plain)
|
|||
std::ostringstream os(std::ios::binary);
|
||||
os << "\"";
|
||||
|
||||
for (size_t i = 0; i < plain.size(); i++) {
|
||||
char c = plain[i];
|
||||
for (char c : plain) {
|
||||
switch (c) {
|
||||
case '"':
|
||||
os << "\\\"";
|
||||
|
@ -308,7 +307,9 @@ std::string deSerializeJsonString(std::istream &is)
|
|||
|
||||
if (c == '"') {
|
||||
return os.str();
|
||||
} else if (c == '\\') {
|
||||
}
|
||||
|
||||
if (c == '\\') {
|
||||
c2 = is.get();
|
||||
if (is.eof())
|
||||
throw SerializationError("JSON string ended prematurely");
|
||||
|
@ -390,17 +391,18 @@ std::string deSerializeJsonStringIfNeeded(std::istream &is)
|
|||
// Found end of word
|
||||
is.unget();
|
||||
break;
|
||||
} else {
|
||||
tmp_os << c;
|
||||
}
|
||||
|
||||
tmp_os << c;
|
||||
}
|
||||
expect_initial_quote = false;
|
||||
}
|
||||
if (is_json) {
|
||||
std::istringstream tmp_is(tmp_os.str(), std::ios::binary);
|
||||
return deSerializeJsonString(tmp_is);
|
||||
} else
|
||||
return tmp_os.str();
|
||||
}
|
||||
|
||||
return tmp_os.str();
|
||||
}
|
||||
|
||||
////
|
||||
|
|
|
@ -37,7 +37,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include <endian.h>
|
||||
#endif
|
||||
#endif
|
||||
#include <string.h> // for memcpy
|
||||
#include <cstring> // for memcpy
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
|
|
@ -24,10 +24,10 @@ SOFTWARE.
|
|||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
#include "sha1.h"
|
||||
|
||||
|
@ -96,7 +96,7 @@ void SHA1::process()
|
|||
+(bytes[t*4 + 2] << 8)
|
||||
+ bytes[t*4 + 3];
|
||||
for(; t< 80; t++ ) W[t] = lrot( W[t-3]^W[t-8]^W[t-14]^W[t-16], 1 );
|
||||
|
||||
|
||||
/* main loop */
|
||||
Uint32 temp;
|
||||
for( t = 0; t < 80; t++ )
|
||||
|
@ -154,7 +154,7 @@ void SHA1::addBytes( const char* data, int num )
|
|||
num -= toCopy;
|
||||
data += toCopy;
|
||||
unprocessedBytes += toCopy;
|
||||
|
||||
|
||||
// there is a full block
|
||||
if( unprocessedBytes == 64 ) process();
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ unsigned char* SHA1::getDigest()
|
|||
Uint32 totalBitsH = size >> 29;
|
||||
// add 0x80 to the message
|
||||
addBytes( "\x80", 1 );
|
||||
|
||||
|
||||
unsigned char footer[64] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
|
|
|
@ -31,13 +31,14 @@
|
|||
#include <windows.h>
|
||||
#include <wincrypt.h>
|
||||
#else
|
||||
#include <time.h>
|
||||
#include <ctime>
|
||||
|
||||
#endif
|
||||
// clang-format on
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
|
||||
#include <config.h>
|
||||
|
||||
|
|
|
@ -78,8 +78,8 @@ public:
|
|||
template<typename Key, typename T, typename Caller, typename CallerData>
|
||||
class GetRequest {
|
||||
public:
|
||||
GetRequest() {}
|
||||
~GetRequest() {}
|
||||
GetRequest() = default;
|
||||
~GetRequest() = default;
|
||||
|
||||
GetRequest(const Key &a_key): key(a_key)
|
||||
{
|
||||
|
@ -189,7 +189,7 @@ class UpdateThread : public Thread
|
|||
{
|
||||
public:
|
||||
UpdateThread(const std::string &name) : Thread(name + "Update") {}
|
||||
~UpdateThread() {}
|
||||
~UpdateThread() = default;
|
||||
|
||||
void deferUpdate() { m_update_sem.post(); }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue