cache[d] = std::vector<v3s16>();
std::vector<v3s16> &c = cache[d];
if (d == 0) {
- c.push_back(v3s16(0,0,0));
+ c.emplace_back(0,0,0);
return c;
}
if (d == 1) {
// This is an optimized sequence of coordinates.
- c.push_back(v3s16( 0, 1, 0)); // Top
- c.push_back(v3s16( 0, 0, 1)); // Back
- c.push_back(v3s16(-1, 0, 0)); // Left
- c.push_back(v3s16( 1, 0, 0)); // Right
- c.push_back(v3s16( 0, 0,-1)); // Front
- c.push_back(v3s16( 0,-1, 0)); // Bottom
+ c.emplace_back(0, 1, 0); // Top
+ c.emplace_back(0, 0, 1); // Back
+ c.emplace_back(-1, 0, 0); // Left
+ c.emplace_back(1, 0, 0); // Right
+ c.emplace_back(0, 0,-1); // Front
+ c.emplace_back(0,-1, 0); // Bottom
// 6
- c.push_back(v3s16(-1, 0, 1)); // Back left
- c.push_back(v3s16( 1, 0, 1)); // Back right
- c.push_back(v3s16(-1, 0,-1)); // Front left
- c.push_back(v3s16( 1, 0,-1)); // Front right
- c.push_back(v3s16(-1,-1, 0)); // Bottom left
- c.push_back(v3s16( 1,-1, 0)); // Bottom right
- c.push_back(v3s16( 0,-1, 1)); // Bottom back
- c.push_back(v3s16( 0,-1,-1)); // Bottom front
- c.push_back(v3s16(-1, 1, 0)); // Top left
- c.push_back(v3s16( 1, 1, 0)); // Top right
- c.push_back(v3s16( 0, 1, 1)); // Top back
- c.push_back(v3s16( 0, 1,-1)); // Top front
+ c.emplace_back(-1, 0, 1); // Back left
+ c.emplace_back(1, 0, 1); // Back right
+ c.emplace_back(-1, 0,-1); // Front left
+ c.emplace_back(1, 0,-1); // Front right
+ c.emplace_back(-1,-1, 0); // Bottom left
+ c.emplace_back(1,-1, 0); // Bottom right
+ c.emplace_back(0,-1, 1); // Bottom back
+ c.emplace_back(0,-1,-1); // Bottom front
+ c.emplace_back(-1, 1, 0); // Top left
+ c.emplace_back(1, 1, 0); // Top right
+ c.emplace_back(0, 1, 1); // Top back
+ c.emplace_back(0, 1,-1); // Top front
// 18
- c.push_back(v3s16(-1, 1, 1)); // Top back-left
- c.push_back(v3s16( 1, 1, 1)); // Top back-right
- c.push_back(v3s16(-1, 1,-1)); // Top front-left
- c.push_back(v3s16( 1, 1,-1)); // Top front-right
- c.push_back(v3s16(-1,-1, 1)); // Bottom back-left
- c.push_back(v3s16( 1,-1, 1)); // Bottom back-right
- c.push_back(v3s16(-1,-1,-1)); // Bottom front-left
- c.push_back(v3s16( 1,-1,-1)); // Bottom front-right
+ c.emplace_back(-1, 1, 1); // Top back-left
+ c.emplace_back(1, 1, 1); // Top back-right
+ c.emplace_back(-1, 1,-1); // Top front-left
+ c.emplace_back(1, 1,-1); // Top front-right
+ c.emplace_back(-1,-1, 1); // Bottom back-left
+ c.emplace_back(1,-1, 1); // Bottom back-right
+ c.emplace_back(-1,-1,-1); // Bottom front-left
+ c.emplace_back(1,-1,-1); // Bottom front-right
// 26
return c;
}
for (s16 y = 0; y <= d - 1; y++) {
// Left and right side, including borders
for (s16 z =- d; z <= d; z++) {
- c.push_back(v3s16( d, y, z));
- c.push_back(v3s16(-d, y, z));
+ c.emplace_back(d, y, z);
+ c.emplace_back(-d, y, z);
if (y != 0) {
- c.push_back(v3s16( d, -y, z));
- c.push_back(v3s16(-d, -y, z));
+ c.emplace_back(d, -y, z);
+ c.emplace_back(-d, -y, z);
}
}
// Back and front side, excluding borders
for (s16 x = -d + 1; x <= d - 1; x++) {
- c.push_back(v3s16(x, y, d));
- c.push_back(v3s16(x, y, -d));
+ c.emplace_back(x, y, d);
+ c.emplace_back(x, y, -d);
if (y != 0) {
- c.push_back(v3s16(x, -y, d));
- c.push_back(v3s16(x, -y, -d));
+ c.emplace_back(x, -y, d);
+ c.emplace_back(x, -y, -d);
}
}
}
// -d < x < d, y = +-d, -d < z < d
for (s16 x = -d; x <= d; x++)
for (s16 z = -d; z <= d; z++) {
- c.push_back(v3s16(x, -d, z));
- c.push_back(v3s16(x, d, z));
+ c.emplace_back(x, -d, z);
+ c.emplace_back(x, d, z);
}
return c;
}
#include "filesys.h"
#include "util/string.h"
#include <iostream>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
+#include <cstdio>
+#include <cstring>
+#include <cerrno>
#include <fstream>
#include "log.h"
#include "config.h"
If so, try stat().
*/
if(isdir == -1) {
- struct stat statbuf;
+ struct stat statbuf{};
if (stat((pathstring + "/" + node.name).c_str(), &statbuf))
continue;
isdir = ((statbuf.st_mode & S_IFDIR) == S_IFDIR);
bool CreateDir(const std::string &path)
{
int r = mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
- if(r == 0)
- {
+ if (r == 0) {
return true;
}
- else
- {
- // If already exists, return true
- if(errno == EEXIST)
- return true;
- return false;
- }
+
+ // If already exists, return true
+ if (errno == EEXIST)
+ return true;
+ return false;
+
}
bool PathExists(const std::string &path)
{
- struct stat st;
+ struct stat st{};
return (stat(path.c_str(),&st) == 0);
}
bool IsDir(const std::string &path)
{
- struct stat statbuf;
+ struct stat statbuf{};
if(stat(path.c_str(), &statbuf))
return false; // Actually error; but certainly not a directory
return ((statbuf.st_mode & S_IFDIR) == S_IFDIR);
bool DeleteSingleFileOrEmptyDirectory(const std::string &path)
{
- if(IsDir(path)){
+ if (IsDir(path)) {
bool did = (rmdir(path.c_str()) == 0);
- if(!did)
- errorstream<<"rmdir errno: "<<errno<<": "<<strerror(errno)
- <<std::endl;
- return did;
- } else {
- bool did = (unlink(path.c_str()) == 0);
- if(!did)
- errorstream<<"unlink errno: "<<errno<<": "<<strerror(errno)
- <<std::endl;
+ if (!did)
+ errorstream << "rmdir errno: " << errno << ": " << strerror(errno)
+ << std::endl;
return did;
}
+
+ bool did = (unlink(path.c_str()) == 0);
+ if (!did)
+ errorstream << "unlink errno: " << errno << ": " << strerror(errno)
+ << std::endl;
+ return did;
}
std::string TempPath()
void GetRecursiveSubPaths(const std::string &path, std::vector<std::string> &dst)
{
std::vector<DirListNode> content = GetDirListing(path);
- for(unsigned int i=0; i<content.size(); i++){
- const DirListNode &n = content[i];
+ for (const auto &n : content) {
std::string fullpath = path + DIR_DELIM + n.name;
dst.push_back(fullpath);
if (n.dir) {
{
infostream<<"Removing content of \""<<path<<"\""<<std::endl;
std::vector<DirListNode> list = GetDirListing(path);
- for(unsigned int i=0; i<list.size(); i++)
- {
- if(trim(list[i].name) == "." || trim(list[i].name) == "..")
+ for (const DirListNode &dln : list) {
+ if(trim(dln.name) == "." || trim(dln.name) == "..")
continue;
- std::string childpath = path + DIR_DELIM + list[i].name;
+ std::string childpath = path + DIR_DELIM + dln.name;
bool r = RecursiveDelete(childpath);
- if(r == false)
- {
- errorstream<<"Removing \""<<childpath<<"\" failed"<<std::endl;
+ if(!r) {
+ errorstream << "Removing \"" << childpath << "\" failed" << std::endl;
return false;
}
}
bool retval = true;
std::vector<DirListNode> content = fs::GetDirListing(source);
- for(unsigned int i=0; i < content.size(); i++){
- std::string sourcechild = source + DIR_DELIM + content[i].name;
- std::string targetchild = target + DIR_DELIM + content[i].name;
- if(content[i].dir){
+ for (const auto &dln : content) {
+ std::string sourcechild = source + DIR_DELIM + dln.name;
+ std::string targetchild = target + DIR_DELIM + dln.name;
+ if(dln.dir){
if(!fs::CopyDir(sourcechild, targetchild)){
retval = false;
}
}
return retval;
}
- else {
- return false;
- }
+
+ return false;
}
bool PathStartsWith(const std::string &path, const std::string &prefix)