summaryrefslogtreecommitdiff
path: root/src/craftdef.h
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2017-08-17 23:02:50 +0200
committerGitHub <noreply@github.com>2017-08-17 23:02:50 +0200
commit13e995b811e80dc48c0769274d3dca3a2221b843 (patch)
treeb75e58314fa98b57d23fefd92547f298ea419e5f /src/craftdef.h
parent921151d97a2fb2238ab514324fb95e2732248b96 (diff)
downloadminetest-13e995b811e80dc48c0769274d3dca3a2221b843.tar.gz
minetest-13e995b811e80dc48c0769274d3dca3a2221b843.tar.bz2
minetest-13e995b811e80dc48c0769274d3dca3a2221b843.zip
Modernize src/c* src/d* and src/e* files (#6263)
* Modernize src/c* src/d* and src/e* files * default operator * redundant init * delete default constructors on CraftDefinition childs (never used) * fix some missing init values * const ref fix reported by clang-tidy * ranged-based for loops * simple conditions & returns * empty stl function instead of size * emplace_back stl function instead of push_back + construct temp obj * auto for some iterators * code style fixes * c++ stl headers instead of C stl headers (stdio.h -> cstdio)
Diffstat (limited to 'src/craftdef.h')
-rw-r--r--src/craftdef.h67
1 files changed, 26 insertions, 41 deletions
diff --git a/src/craftdef.h b/src/craftdef.h
index 781ca0d17..46ee2164e 100644
--- a/src/craftdef.h
+++ b/src/craftdef.h
@@ -73,7 +73,7 @@ struct CraftInput
unsigned int width = 0;
std::vector<ItemStack> items;
- CraftInput() {}
+ CraftInput() = default;
CraftInput(CraftMethod method_, unsigned int width_,
const std::vector<ItemStack> &items_):
@@ -93,7 +93,7 @@ struct CraftOutput
// Used for cooking (cook time) and fuel (burn time), seconds
float time = 0.0f;
- CraftOutput() {}
+ CraftOutput() = default;
CraftOutput(const std::string &item_, float time_):
item(item_), time(time_)
@@ -119,9 +119,7 @@ struct CraftReplacements
// List of replacements
std::vector<std::pair<std::string, std::string> > pairs;
- CraftReplacements():
- pairs()
- {}
+ CraftReplacements() = default;
CraftReplacements(const std::vector<std::pair<std::string, std::string> > &pairs_):
pairs(pairs_)
{}
@@ -134,8 +132,8 @@ struct CraftReplacements
class CraftDefinition
{
public:
- CraftDefinition(){}
- virtual ~CraftDefinition(){}
+ CraftDefinition() = default;
+ virtual ~CraftDefinition() = default;
// Returns type of crafting definition
virtual std::string getName() const=0;
@@ -169,7 +167,7 @@ public:
class CraftDefinitionShaped: public CraftDefinition
{
public:
- CraftDefinitionShaped() {}
+ CraftDefinitionShaped() = delete;
CraftDefinitionShaped(
const std::string &output_,
@@ -179,7 +177,7 @@ public:
output(output_), width(width_), recipe(recipe_),
replacements(replacements_)
{}
- virtual ~CraftDefinitionShaped(){}
+ virtual ~CraftDefinitionShaped() = default;
virtual std::string getName() const;
virtual bool check(const CraftInput &input, IGameDef *gamedef) const;
@@ -218,17 +216,14 @@ private:
class CraftDefinitionShapeless: public CraftDefinition
{
public:
- CraftDefinitionShapeless():
- output(""), recipe(), hash_inited(false), replacements()
- {}
+ CraftDefinitionShapeless() = delete;
CraftDefinitionShapeless(
const std::string &output_,
const std::vector<std::string> &recipe_,
const CraftReplacements &replacements_):
- output(output_), recipe(recipe_),
- hash_inited(false), replacements(replacements_)
+ output(output_), recipe(recipe_), replacements(replacements_)
{}
- virtual ~CraftDefinitionShapeless(){}
+ virtual ~CraftDefinitionShapeless() = default;
virtual std::string getName() const;
virtual bool check(const CraftInput &input, IGameDef *gamedef) const;
@@ -252,7 +247,7 @@ private:
// Recipe list (item names)
std::vector<std::string> recipe_names;
// bool indicating if initHash has been called already
- bool hash_inited;
+ bool hash_inited = false;
// Replacement items for decrementInput()
CraftReplacements replacements;
};
@@ -266,13 +261,11 @@ private:
class CraftDefinitionToolRepair: public CraftDefinition
{
public:
- CraftDefinitionToolRepair():
- additional_wear(0)
- {}
+ CraftDefinitionToolRepair() = delete;
CraftDefinitionToolRepair(float additional_wear_):
additional_wear(additional_wear_)
{}
- virtual ~CraftDefinitionToolRepair(){}
+ virtual ~CraftDefinitionToolRepair() = default;
virtual std::string getName() const;
virtual bool check(const CraftInput &input, IGameDef *gamedef) const;
@@ -294,7 +287,7 @@ private:
// 1 = new tool is completely broken
// 0 = simply add remaining uses of both input tools
// -1 = new tool is completely pristine
- float additional_wear;
+ float additional_wear = 0.0f;
};
/*
@@ -304,18 +297,15 @@ private:
class CraftDefinitionCooking: public CraftDefinition
{
public:
- CraftDefinitionCooking():
- output(""), recipe(""), hash_inited(false), cooktime()
- {}
+ CraftDefinitionCooking() = delete;
CraftDefinitionCooking(
const std::string &output_,
const std::string &recipe_,
float cooktime_,
const CraftReplacements &replacements_):
- output(output_), recipe(recipe_), hash_inited(false),
- cooktime(cooktime_), replacements(replacements_)
+ output(output_), recipe(recipe_), cooktime(cooktime_), replacements(replacements_)
{}
- virtual ~CraftDefinitionCooking(){}
+ virtual ~CraftDefinitionCooking() = default;
virtual std::string getName() const;
virtual bool check(const CraftInput &input, IGameDef *gamedef) const;
@@ -339,7 +329,7 @@ private:
// Recipe item name
std::string recipe_name;
// bool indicating if initHash has been called already
- bool hash_inited;
+ bool hash_inited = false;
// Time in seconds
float cooktime;
// Replacement items for decrementInput()
@@ -353,18 +343,13 @@ private:
class CraftDefinitionFuel: public CraftDefinition
{
public:
- CraftDefinitionFuel():
- recipe(""), hash_inited(false), burntime()
- {}
+ CraftDefinitionFuel() = delete;
CraftDefinitionFuel(const std::string &recipe_,
float burntime_,
const CraftReplacements &replacements_):
- recipe(recipe_),
- hash_inited(false),
- burntime(burntime_),
- replacements(replacements_)
+ recipe(recipe_), burntime(burntime_), replacements(replacements_)
{}
- virtual ~CraftDefinitionFuel(){}
+ virtual ~CraftDefinitionFuel() = default;
virtual std::string getName() const;
virtual bool check(const CraftInput &input, IGameDef *gamedef) const;
@@ -386,7 +371,7 @@ private:
// Recipe item name
std::string recipe_name;
// bool indicating if initHash has been called already
- bool hash_inited;
+ bool hash_inited = false;
// Time in seconds
float burntime;
// Replacement items for decrementInput()
@@ -399,8 +384,8 @@ private:
class ICraftDefManager
{
public:
- ICraftDefManager(){}
- virtual ~ICraftDefManager(){}
+ ICraftDefManager() = default;
+ virtual ~ICraftDefManager() = default;
// The main crafting function
virtual bool getCraftResult(CraftInput &input, CraftOutput &output,
@@ -416,8 +401,8 @@ public:
class IWritableCraftDefManager : public ICraftDefManager
{
public:
- IWritableCraftDefManager(){}
- virtual ~IWritableCraftDefManager(){}
+ IWritableCraftDefManager() = default;
+ virtual ~IWritableCraftDefManager() = default;
// The main crafting function
virtual bool getCraftResult(CraftInput &input, CraftOutput &output,