1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

vcmi: remove unused functions now

This commit is contained in:
Konstantin 2023-04-17 00:24:11 +03:00
parent 7a5775a9f9
commit 54eb550eb9
10 changed files with 79 additions and 100 deletions

View File

@ -96,7 +96,18 @@ TGoalVec GatherTroops::getAllPossibleSubgoals()
auto creature = VLC->creatures()->getByIndex(objid);
if(t->subID == creature->getFaction()) //TODO: how to force AI to build unupgraded creatures? :O
{
auto creatures = vstd::tryAt(t->town->creatures, creature->getLevel() - 1);
auto tryFindCreature = [&]() -> std::optional<std::vector<CreatureID>>
{
if(vstd::isValidIndex(t->town->creatures, creature->getLevel() - 1))
{
auto itr = t->town->creatures.begin();
std::advance(itr, creature->getLevel() - 1);
return make_optional(*itr);
}
return std::nullopt;
};
auto creatures = tryFindCreature();
if(!creatures)
continue;

View File

@ -145,14 +145,13 @@ static_assert(sizeof(bool) == 1, "Bool needs to be 1 byte in size.");
#endif
#include <boost/algorithm/string.hpp>
#include <boost/any.hpp>
#include <boost/current_function.hpp>
#include <boost/crc.hpp>
#include <boost/current_function.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/posix_time/posix_time_io.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/format.hpp>
#include <boost/functional/hash.hpp>
#include <boost/lexical_cast.hpp>
@ -160,14 +159,11 @@ static_assert(sizeof(bool) == 1, "Bool needs to be 1 byte in size.");
#include <boost/locale/generator.hpp>
#endif
#include <boost/logic/tribool.hpp>
#include <boost/optional.hpp>
#include <boost/optional/optional_io.hpp>
#include <boost/multi_array.hpp>
#include <boost/range/adaptor/filtered.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/thread.hpp>
#include <boost/variant.hpp>
#include <boost/multi_array.hpp>
#ifndef M_PI
# define M_PI 3.14159265358979323846
@ -577,28 +573,6 @@ namespace vstd
return i >= 0 && i < c.size();
}
template<typename Container, typename Index>
std::optional<typename Container::value_type> tryAt(const Container & c, Index i)
{
if(isValidIndex(c, i))
{
auto itr = c.begin();
std::advance(itr, i);
return *itr;
}
return std::nullopt;
}
template<typename Container, typename Pred>
static std::optional<typename Container::const_reference> tryFindIf(const Container & r, const Pred & t)
{
auto pos = range::find_if(r, t);
if(pos == boost::end(r))
return std::nullopt;
else
return *pos;
}
template <typename Container>
typename Container::const_reference atOrDefault(const Container &r, size_t index, const typename Container::const_reference &defaultValue)
{

View File

@ -103,7 +103,7 @@ std::shared_ptr<BattleInterface> CPlayerInterface::battleInt;
enum EMoveState {STOP_MOVE, WAITING_MOVE, CONTINUE_MOVE, DURING_MOVE};
CondSh<EMoveState> stillMoveHero(STOP_MOVE); //used during hero movement
struct HeroObjectRetriever : boost::static_visitor<const CGHeroInstance *>
struct HeroObjectRetriever
{
const CGHeroInstance * operator()(const ConstTransitivePtr<CGHeroInstance> &h) const
{

View File

@ -70,8 +70,8 @@ namespace LogicalExpressionDetail
};
/// Visitor to test result (true/false) of the expression
template <typename ContainedClass>
class TestVisitor : public boost::static_visitor<bool>
template<typename ContainedClass>
class TestVisitor
{
typedef ExpressionBase<ContainedClass> Base;
@ -116,8 +116,8 @@ namespace LogicalExpressionDetail
template <typename ContainedClass>
class FalsifiabilityVisitor;
template <typename ContainedClass>
class PossibilityVisitor : public boost::static_visitor<bool>
template<typename ContainedClass>
class PossibilityVisitor
{
typedef ExpressionBase<ContainedClass> Base;
@ -235,8 +235,8 @@ namespace LogicalExpressionDetail
/// visitor that is trying to generates candidates that must be fulfilled
/// to complete this expression
template <typename ContainedClass>
class CandidatesVisitor : public boost::static_visitor<std::vector<ContainedClass> >
template<typename ContainedClass>
class CandidatesVisitor
{
typedef ExpressionBase<ContainedClass> Base;
typedef std::vector<typename Base::Value> TValueList;
@ -285,8 +285,8 @@ namespace LogicalExpressionDetail
};
/// Simple foreach visitor
template <typename ContainedClass>
class ForEachVisitor : public boost::static_visitor<typename ExpressionBase<ContainedClass>::Variant>
template<typename ContainedClass>
class ForEachVisitor
{
typedef ExpressionBase<ContainedClass> Base;
@ -312,8 +312,8 @@ namespace LogicalExpressionDetail
};
/// Minimizing visitor that removes all redundant elements from variant (e.g. AllOf inside another AllOf can be merged safely)
template <typename ContainedClass>
class MinimizingVisitor : public boost::static_visitor<typename ExpressionBase<ContainedClass>::Variant>
template<typename ContainedClass>
class MinimizingVisitor
{
typedef ExpressionBase<ContainedClass> Base;
@ -397,8 +397,8 @@ namespace LogicalExpressionDetail
};
/// Serializes expression in JSON format. Part of map format.
template <typename ContainedClass>
class Writer : public boost::static_visitor<JsonNode>
template<typename ContainedClass>
class Writer
{
typedef ExpressionBase<ContainedClass> Base;
@ -442,8 +442,8 @@ namespace LogicalExpressionDetail
std::string DLL_LINKAGE getTextForOperator(const std::string & operation);
/// Prints expression in human-readable format
template <typename ContainedClass>
class Printer : public boost::static_visitor<std::string>
template<typename ContainedClass>
class Printer
{
typedef ExpressionBase<ContainedClass> Base;

View File

@ -930,7 +930,7 @@ struct DLL_LINKAGE BulkSmartRebalanceStacks : CGarrisonOperationPack
}
};
struct GetEngagedHeroIds: boost::static_visitor<std::optional<ObjectInstanceID>>
struct GetEngagedHeroIds
{
std::optional<ObjectInstanceID> operator()(const ConstTransitivePtr<CGHeroInstance> & h) const
{

View File

@ -1532,7 +1532,7 @@ const CStackInstance * StackLocation::getStack()
return &army->getStack(slot);
}
struct ObjectRetriever : boost::static_visitor<const CArmedInstance *>
struct ObjectRetriever
{
const CArmedInstance * operator()(const ConstTransitivePtr<CGHeroInstance> &h) const
{
@ -1543,8 +1543,8 @@ struct ObjectRetriever : boost::static_visitor<const CArmedInstance *>
return s->armyObj;
}
};
template <typename T>
struct GetBase : boost::static_visitor<T*>
template<typename T>
struct GetBase
{
template <typename TArg>
T * operator()(TArg &arg) const

View File

@ -506,10 +506,10 @@ public:
this->read((void*)data.c_str(),length);
}
template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
void load(std::variant<BOOST_VARIANT_ENUM_PARAMS(T)> &data)
template<typename T0, typename... TN>
void load(std::variant<T0, TN...> & data)
{
typedef std::variant<BOOST_VARIANT_ENUM_PARAMS(T)> TVariant;
using TVariant = std::variant<T0, TN...>;
VariantLoaderHelper<TVariant, BinaryDeserializer> loader(*this);

View File

@ -36,8 +36,8 @@ public:
/// VCMI Classes: recursively serialize them via ClassName::serialize( BinarySerializer &, int version) call
class DLL_LINKAGE BinarySerializer : public CSaverBase
{
template <typename Handler>
struct VariantVisitorSaver : boost::static_visitor<>
template<typename Handler>
struct VariantVisitorSaver
{
Handler &h;
VariantVisitorSaver(Handler &H):h(H)
@ -330,8 +330,8 @@ public:
save(i->second);
}
}
template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
void save(const std::variant<BOOST_VARIANT_ENUM_PARAMS(T)> &data)
template<typename T0, typename... TN>
void save(const std::variant<T0, TN...> & data)
{
si32 which = data.index();
save(which);

View File

@ -156,7 +156,7 @@ namespace ERMConverter
}
};
struct LVL2IexpToVar : boost::static_visitor<Variable>
struct LVL2IexpToVar
{
LVL2IexpToVar() = default;
@ -174,11 +174,11 @@ namespace ERMConverter
}
};
struct LVL1IexpToVar : boost::static_visitor<Variable>
struct LVL1IexpToVar
{
LVL1IexpToVar() = default;
Variable operator()(int const & constant) const
Variable operator()(const int & constant) const
{
return Variable("", constant);
}
@ -189,11 +189,8 @@ namespace ERMConverter
}
};
struct Condition : public boost::static_visitor<std::string>
struct Condition
{
Condition()
{}
std::string operator()(const TComparison & cmp) const
{
Variable lhs = std::visit(LVL1IexpToVar(), cmp.lhs);
@ -207,7 +204,7 @@ namespace ERMConverter
fmt % lhs.str() % sign->second % rhs.str();
return fmt.str();
}
std::string operator()(int const & flag) const
std::string operator()(const int & flag) const
{
return boost::to_string(boost::format("F['%d']") % flag);
}
@ -222,7 +219,7 @@ namespace ERMConverter
std::string semiCmpSign = "";
};
struct Converter : public boost::static_visitor<>
struct Converter
{
mutable std::ostream * out;
Converter(std::ostream * out_)
@ -246,11 +243,8 @@ namespace ERMConverter
}
};
struct GetBodyOption : public boost::static_visitor<std::string>
struct GetBodyOption
{
GetBodyOption()
{}
virtual std::string operator()(const TVarConcatString & cmp) const
{
throw EScriptExecError("String concatenation not allowed in this receiver");
@ -285,7 +279,7 @@ namespace ERMConverter
}
};
struct BodyOption : public boost::static_visitor<ParamIO>
struct BodyOption
{
ParamIO operator()(const TVarConcatString & cmp) const
{
@ -1151,23 +1145,23 @@ namespace ERMConverter
endLine();
}
void operator()(spirit::unused_type const &) const
void operator()(const spirit::unused_type &) const
{
}
};
struct TLiteralEval : public boost::static_visitor<std::string>
struct TLiteralEval
{
std::string operator()(char const & val)
std::string operator()(const char & val)
{
return "{\"'\",'"+ std::to_string(val) +"'}";
}
std::string operator()(double const & val)
std::string operator()(const double & val)
{
return std::to_string(val);
}
std::string operator()(int const & val)
std::string operator()(const int & val)
{
return std::to_string(val);
}
@ -1187,18 +1181,18 @@ namespace ERMConverter
{
(*out) << "{}";
}
void operator()(VNode const & opt) const;
void operator()(const VNode & opt) const;
void operator()(VSymbol const & opt) const
void operator()(const VSymbol & opt) const
{
(*out) << "\"" << opt.text << "\"";
}
void operator()(TLiteral const & opt) const
void operator()(const TLiteral & opt) const
{
TLiteralEval tmp;
(*out) << std::visit(tmp, opt);
}
void operator()(ERM::Tcommand const & opt) const
void operator()(ERM const ::Tcommand & opt) const
{
//this is how FP works, evaluation == producing side effects
//TODO: can we evaluate to smth more useful?
@ -1208,7 +1202,7 @@ namespace ERMConverter
}
};
void VOptionEval::operator()(VNode const& opt) const
void VOptionEval::operator()(const VNode & opt) const
{
VNode tmpn(opt);
@ -1228,7 +1222,7 @@ namespace ERMConverter
: Converter(out_)
{}
void operator()(TVExp const & cmd) const
void operator()(const TVExp & cmd) const
{
put("VERM:E");
@ -1240,7 +1234,7 @@ namespace ERMConverter
endLine();
}
void operator()(TERMline const & cmd) const
void operator()(const TERMline & cmd) const
{
std::visit(Command(out), cmd);
}
@ -1367,7 +1361,7 @@ namespace ERMConverter
}
}
struct ScriptScanner : boost::static_visitor<>
struct ScriptScanner
{
ERMInterpreter * interpreter;
LinePointer lp;
@ -1375,11 +1369,11 @@ struct ScriptScanner : boost::static_visitor<>
ScriptScanner(ERMInterpreter * interpr, const LinePointer & _lp) : interpreter(interpr), lp(_lp)
{}
void operator()(TVExp const& cmd) const
void operator()(const TVExp & cmd) const
{
//
}
void operator()(TERMline const& cmd) const
void operator()(const TERMline & cmd) const
{
if(cmd.which() == 0) //TCommand
{
@ -1712,34 +1706,34 @@ namespace VERMInterpreter
return ret;
}
VOption OptionConverterVisitor::operator()( ERM::TVExp const& cmd ) const
VOption OptionConverterVisitor::operator()(ERM const ::TVExp & cmd) const
{
return VNode(cmd);
}
VOption OptionConverterVisitor::operator()( ERM::TSymbol const& cmd ) const
VOption OptionConverterVisitor::operator()(ERM const ::TSymbol & cmd) const
{
if(cmd.symModifier.empty())
return VSymbol(cmd.sym);
else
return VNode(cmd);
}
VOption OptionConverterVisitor::operator()( char const& cmd ) const
VOption OptionConverterVisitor::operator()(const char & cmd) const
{
return TLiteral(cmd);
}
VOption OptionConverterVisitor::operator()( double const& cmd ) const
VOption OptionConverterVisitor::operator()(const double & cmd) const
{
return TLiteral(cmd);
}
VOption OptionConverterVisitor::operator()(int const& cmd) const
VOption OptionConverterVisitor::operator()(const int & cmd) const
{
return TLiteral(cmd);
}
VOption OptionConverterVisitor::operator()(ERM::Tcommand const& cmd) const
VOption OptionConverterVisitor::operator()(ERM const ::Tcommand & cmd) const
{
return cmd;
}
VOption OptionConverterVisitor::operator()( ERM::TStringConstant const& cmd ) const
VOption OptionConverterVisitor::operator()(ERM const ::TStringConstant & cmd) const
{
return TLiteral(cmd.str);
}

View File

@ -278,15 +278,15 @@ namespace VERMInterpreter
VermTreeIterator cdr();
};
struct OptionConverterVisitor : boost::static_visitor<VOption>
struct OptionConverterVisitor
{
VOption operator()(ERM::TVExp const& cmd) const;
VOption operator()(ERM::TSymbol const& cmd) const;
VOption operator()(char const& cmd) const;
VOption operator()(double const& cmd) const;
VOption operator()(int const& cmd) const;
VOption operator()(ERM::Tcommand const& cmd) const;
VOption operator()(ERM::TStringConstant const& cmd) const;
VOption operator()(ERM const ::TVExp & cmd) const;
VOption operator()(ERM const ::TSymbol & cmd) const;
VOption operator()(const char & cmd) const;
VOption operator()(const double & cmd) const;
VOption operator()(const int & cmd) const;
VOption operator()(ERM const ::Tcommand & cmd) const;
VOption operator()(ERM const ::TStringConstant & cmd) const;
};
struct VNode