mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-15 00:05:02 +02:00
vcmi: use std::variant
This commit is contained in:
@ -185,7 +185,7 @@ namespace ERMConverter
|
||||
|
||||
Variable operator()(const TVarExp & var) const
|
||||
{
|
||||
return boost::apply_visitor(LVL2IexpToVar(), var);
|
||||
return std::visit(LVL2IexpToVar(), var);
|
||||
}
|
||||
};
|
||||
|
||||
@ -196,8 +196,8 @@ namespace ERMConverter
|
||||
|
||||
std::string operator()(const TComparison & cmp) const
|
||||
{
|
||||
Variable lhs = boost::apply_visitor(LVL1IexpToVar(), cmp.lhs);
|
||||
Variable rhs = boost::apply_visitor(LVL1IexpToVar(), cmp.rhs);
|
||||
Variable lhs = std::visit(LVL1IexpToVar(), cmp.lhs);
|
||||
Variable rhs = std::visit(LVL1IexpToVar(), cmp.rhs);
|
||||
|
||||
auto sign = CMP_OPERATION.find(cmp.compSign);
|
||||
if(sign == std::end(CMP_OPERATION))
|
||||
@ -314,7 +314,7 @@ namespace ERMConverter
|
||||
ret.isInput = false;
|
||||
ret.semi = true;
|
||||
ret.semiCmpSign = cmp.compSign;
|
||||
ret.name = (boost::apply_visitor(LVL1IexpToVar(), cmp.rhs)).str();
|
||||
ret.name = (std::visit(LVL1IexpToVar(), cmp.rhs)).str();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -327,7 +327,7 @@ namespace ERMConverter
|
||||
{
|
||||
ParamIO ret;
|
||||
ret.isInput = true;
|
||||
ret.name = (boost::apply_visitor(LVL1IexpToVar(), cmp)).str();;
|
||||
ret.name = (std::visit(LVL1IexpToVar(), cmp)).str();;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -336,7 +336,7 @@ namespace ERMConverter
|
||||
ParamIO ret;
|
||||
ret.isInput = false;
|
||||
|
||||
ret.name = (boost::apply_visitor(LVL2IexpToVar(), cmp.var)).str();
|
||||
ret.name = (std::visit(LVL2IexpToVar(), cmp.var)).str();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -399,7 +399,7 @@ namespace ERMConverter
|
||||
if(trig.params.is_initialized())
|
||||
{
|
||||
for(auto & p : trig.params.get())
|
||||
optionParams.push_back(boost::apply_visitor(BodyOption(), p));
|
||||
optionParams.push_back(std::visit(BodyOption(), p));
|
||||
}
|
||||
|
||||
int idx = 1;
|
||||
@ -511,7 +511,7 @@ namespace ERMConverter
|
||||
|
||||
FU(std::ostream * out_, const ERM::TIexp & tid)
|
||||
: Receiver(out_),
|
||||
v(boost::apply_visitor(LVL1IexpToVar(), tid))
|
||||
v(std::visit(LVL1IexpToVar(), tid))
|
||||
{
|
||||
}
|
||||
|
||||
@ -558,7 +558,7 @@ namespace ERMConverter
|
||||
|
||||
MC(std::ostream * out_, const ERM::TIexp & tid)
|
||||
: Receiver(out_),
|
||||
v(boost::apply_visitor(LVL1IexpToVar(), tid))
|
||||
v(std::visit(LVL1IexpToVar(), tid))
|
||||
{
|
||||
}
|
||||
|
||||
@ -580,7 +580,7 @@ namespace ERMConverter
|
||||
{
|
||||
for(auto & p : option.params.get())
|
||||
{
|
||||
std::string macroName = boost::apply_visitor(MC_S(), p);
|
||||
std::string macroName = std::visit(MC_S(), p);
|
||||
|
||||
boost::format callFormat;
|
||||
|
||||
@ -616,7 +616,7 @@ namespace ERMConverter
|
||||
|
||||
std::string operator()(const TIexp & cmp) const override
|
||||
{
|
||||
auto v = boost::apply_visitor(LVL1IexpToVar(), cmp);
|
||||
auto v = std::visit(LVL1IexpToVar(), cmp);
|
||||
return v.str();
|
||||
}
|
||||
std::string operator()(const TStringConstant & cmp) const override
|
||||
@ -636,7 +636,7 @@ namespace ERMConverter
|
||||
|
||||
std::string operator()(const TIexp & cmp) const override
|
||||
{
|
||||
Variable p = boost::apply_visitor(LVL1IexpToVar(), cmp);
|
||||
Variable p = std::visit(LVL1IexpToVar(), cmp);
|
||||
|
||||
if(p.index <= 0)
|
||||
throw EScriptExecError("VR:H requires flag index");
|
||||
@ -661,7 +661,7 @@ namespace ERMConverter
|
||||
|
||||
std::string operator()(const TIexp & cmp) const override
|
||||
{
|
||||
Variable p = boost::apply_visitor(LVL1IexpToVar(), cmp);
|
||||
Variable p = std::visit(LVL1IexpToVar(), cmp);
|
||||
|
||||
return p.str();
|
||||
}
|
||||
@ -673,7 +673,7 @@ namespace ERMConverter
|
||||
|
||||
VR(std::ostream * out_, const ERM::TIexp & tid)
|
||||
: Receiver(out_),
|
||||
v(boost::apply_visitor(LVL1IexpToVar(), tid))
|
||||
v(std::visit(LVL1IexpToVar(), tid))
|
||||
{
|
||||
}
|
||||
|
||||
@ -681,7 +681,7 @@ namespace ERMConverter
|
||||
|
||||
void operator()(const TVRLogic & trig) const override
|
||||
{
|
||||
Variable rhs = boost::apply_visitor(LVL1IexpToVar(), trig.var);
|
||||
Variable rhs = std::visit(LVL1IexpToVar(), trig.var);
|
||||
|
||||
std::string opcode;
|
||||
|
||||
@ -705,7 +705,7 @@ namespace ERMConverter
|
||||
|
||||
void operator()(const TVRArithmetic & trig) const override
|
||||
{
|
||||
Variable rhs = boost::apply_visitor(LVL1IexpToVar(), trig.rhs);
|
||||
Variable rhs = std::visit(LVL1IexpToVar(), trig.rhs);
|
||||
|
||||
std::string opcode;
|
||||
|
||||
@ -746,7 +746,7 @@ namespace ERMConverter
|
||||
if(trig.params.is_initialized())
|
||||
{
|
||||
for(auto & p : trig.params.get())
|
||||
optionParams.push_back(boost::apply_visitor(BodyOption(), p));
|
||||
optionParams.push_back(std::visit(BodyOption(), p));
|
||||
}
|
||||
|
||||
auto index = v.index;
|
||||
@ -768,7 +768,7 @@ namespace ERMConverter
|
||||
if(!trig.params.is_initialized() || trig.params.get().size() != 1)
|
||||
throw EScriptExecError("VR:H option takes exactly 1 parameter!");
|
||||
|
||||
std::string opt = boost::apply_visitor(VR_H(), trig.params.get()[0]);
|
||||
std::string opt = std::visit(VR_H(), trig.params.get()[0]);
|
||||
boost::format fmt("ERM.VR(%s):H(%s)");
|
||||
fmt % v.str() % opt;
|
||||
putLine(fmt.str());
|
||||
@ -779,7 +779,7 @@ namespace ERMConverter
|
||||
if(!trig.params.is_initialized() || trig.params.get().size() != 1)
|
||||
throw EScriptExecError("VR:H/U need 1 parameter!");
|
||||
|
||||
std::string opt = boost::apply_visitor(VR_S(), trig.params.get()[0]);
|
||||
std::string opt = std::visit(VR_S(), trig.params.get()[0]);
|
||||
boost::format fmt("ERM.VR(%s):%c(%s)");
|
||||
fmt % v.str() % (trig.optionCode) % opt;
|
||||
putLine(fmt.str());
|
||||
@ -790,7 +790,7 @@ namespace ERMConverter
|
||||
if(!trig.params.is_initialized() || trig.params.get().size() < 2)
|
||||
throw EScriptExecError("VR:M needs at least 2 parameters!");
|
||||
|
||||
std::string opt = boost::apply_visitor(VR_X(), trig.params.get()[0]);
|
||||
std::string opt = std::visit(VR_X(), trig.params.get()[0]);
|
||||
int paramIndex = 1;
|
||||
|
||||
if(opt == "3")
|
||||
@ -801,7 +801,7 @@ namespace ERMConverter
|
||||
}
|
||||
else
|
||||
{
|
||||
auto target = boost::apply_visitor(VR_X(), trig.params.get()[paramIndex++]);
|
||||
auto target = std::visit(VR_X(), trig.params.get()[paramIndex++]);
|
||||
|
||||
boost::format fmt("%s = ERM.VR(%s):M%s(");
|
||||
fmt % target % v.str() % opt;
|
||||
@ -810,7 +810,7 @@ namespace ERMConverter
|
||||
|
||||
for(int i = paramIndex; i < trig.params.get().size(); i++)
|
||||
{
|
||||
opt = boost::apply_visitor(VR_X(), trig.params.get()[i]);
|
||||
opt = std::visit(VR_X(), trig.params.get()[i]);
|
||||
if(i > paramIndex) put(",");
|
||||
put(opt);
|
||||
}
|
||||
@ -823,7 +823,7 @@ namespace ERMConverter
|
||||
if(!trig.params.is_initialized() || trig.params.get().size() != 1)
|
||||
throw EScriptExecError("VR:X option takes exactly 1 parameter!");
|
||||
|
||||
std::string opt = boost::apply_visitor(VR_X(), trig.params.get()[0]);
|
||||
std::string opt = std::visit(VR_X(), trig.params.get()[0]);
|
||||
|
||||
boost::format fmt("%s = bit.bxor(%s, %s)");
|
||||
fmt % v.str() % v.str() % opt;putLine(fmt.str());
|
||||
@ -840,7 +840,7 @@ namespace ERMConverter
|
||||
if(!trig.params.is_initialized() || trig.params.get().size() != 1)
|
||||
throw EScriptExecError("VR:S option takes exactly 1 parameter!");
|
||||
|
||||
std::string opt = boost::apply_visitor(VR_S(), trig.params.get()[0]);
|
||||
std::string opt = std::visit(VR_S(), trig.params.get()[0]);
|
||||
put(v.str());
|
||||
put(" = ");
|
||||
put(opt);
|
||||
@ -858,7 +858,7 @@ namespace ERMConverter
|
||||
if(!trig.params.is_initialized() || trig.params.get().size() != 1)
|
||||
throw EScriptExecError("VR:V option takes exactly 1 parameter!");
|
||||
|
||||
std::string opt = boost::apply_visitor(VR_X(), trig.params.get()[0]);
|
||||
std::string opt = std::visit(VR_X(), trig.params.get()[0]);
|
||||
boost::format fmt("%s = tostring(%s)");
|
||||
fmt % v.str() % opt;
|
||||
putLine(fmt.str());
|
||||
@ -886,7 +886,7 @@ namespace ERMConverter
|
||||
const ERM::Tbody & bo = body.get();
|
||||
for(int g=0; g<bo.size(); ++g)
|
||||
{
|
||||
boost::apply_visitor(visitor, bo[g]);
|
||||
std::visit(visitor, bo[g]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -915,11 +915,11 @@ namespace ERMConverter
|
||||
|
||||
if(argc > 0)
|
||||
{
|
||||
std::string loopCounter = (boost::apply_visitor(LVL1IexpToVar(), tid.at(0))).str();
|
||||
std::string loopCounter = (std::visit(LVL1IexpToVar(), tid.at(0))).str();
|
||||
|
||||
std::string startVal = argc > 1 ? (boost::apply_visitor(LVL1IexpToVar(), tid.at(1))).str() : loopCounter;
|
||||
std::string stopVal = argc > 2 ? (boost::apply_visitor(LVL1IexpToVar(), tid.at(2))).str() : loopCounter;
|
||||
std::string increment = argc > 3 ? (boost::apply_visitor(LVL1IexpToVar(), tid.at(3))).str() : "1";
|
||||
std::string startVal = argc > 1 ? (std::visit(LVL1IexpToVar(), tid.at(1))).str() : loopCounter;
|
||||
std::string stopVal = argc > 2 ? (std::visit(LVL1IexpToVar(), tid.at(2))).str() : loopCounter;
|
||||
std::string increment = argc > 3 ? (std::visit(LVL1IexpToVar(), tid.at(3))).str() : "1";
|
||||
|
||||
boost::format fmt("for __iter = %s, %s, %s do");
|
||||
|
||||
@ -962,7 +962,7 @@ namespace ERMConverter
|
||||
{
|
||||
for(const auto & id : identifier.get())
|
||||
{
|
||||
Variable v = boost::apply_visitor(LVL1IexpToVar(), id);
|
||||
Variable v = std::visit(LVL1IexpToVar(), id);
|
||||
|
||||
if(v.isSpecial())
|
||||
throw ELineProblem("Special variable syntax ('d') is not allowed in receiver identifier");
|
||||
@ -1018,7 +1018,7 @@ namespace ERMConverter
|
||||
|
||||
void convertConditionInner(const Tcondition & cond, char op) const
|
||||
{
|
||||
std::string lhs = boost::apply_visitor(Condition(), cond.cond);
|
||||
std::string lhs = std::visit(Condition(), cond.cond);
|
||||
|
||||
if(cond.ctype != '/')
|
||||
op = cond.ctype;
|
||||
@ -1057,7 +1057,7 @@ namespace ERMConverter
|
||||
void convertCondition(const Tcondition & cond) const
|
||||
{
|
||||
//&c1/c2/c3|c4/c5/c6 -> (c1 & c2 & c3) | c4 | c5 | c6
|
||||
std::string lhs = boost::apply_visitor(Condition(), cond.cond);
|
||||
std::string lhs = std::visit(Condition(), cond.cond);
|
||||
put("if ");
|
||||
put(lhs);
|
||||
|
||||
@ -1143,7 +1143,7 @@ namespace ERMConverter
|
||||
|
||||
void operator()(const Tcommand & cmd) const
|
||||
{
|
||||
boost::apply_visitor(ERMExp(out), cmd.cmd);
|
||||
std::visit(ERMExp(out), cmd.cmd);
|
||||
}
|
||||
void operator()(const std::string & comment) const
|
||||
{
|
||||
@ -1196,7 +1196,7 @@ namespace ERMConverter
|
||||
void operator()(TLiteral const & opt) const
|
||||
{
|
||||
TLiteralEval tmp;
|
||||
(*out) << boost::apply_visitor(tmp, opt);
|
||||
(*out) << std::visit(tmp, opt);
|
||||
}
|
||||
void operator()(ERM::Tcommand const & opt) const
|
||||
{
|
||||
@ -1204,7 +1204,7 @@ namespace ERMConverter
|
||||
//TODO: can we evaluate to smth more useful?
|
||||
//???
|
||||
throw EVermScriptExecError("Using ERM options in VERM expression is not (yet) allowed");
|
||||
// boost::apply_visitor(ERMExp(out), opt.cmd);
|
||||
// std::visit(ERMExp(out), opt.cmd);
|
||||
}
|
||||
};
|
||||
|
||||
@ -1216,7 +1216,7 @@ namespace ERMConverter
|
||||
|
||||
for(VOption & op : tmpn.children)
|
||||
{
|
||||
boost::apply_visitor(VOptionEval(out), op);
|
||||
std::visit(VOptionEval(out), op);
|
||||
(*out) << ",";
|
||||
}
|
||||
(*out) << "}";
|
||||
@ -1242,7 +1242,7 @@ namespace ERMConverter
|
||||
}
|
||||
void operator()(TERMline const & cmd) const
|
||||
{
|
||||
boost::apply_visitor(Command(out), cmd);
|
||||
std::visit(Command(out), cmd);
|
||||
}
|
||||
};
|
||||
|
||||
@ -1257,7 +1257,7 @@ namespace ERMConverter
|
||||
{
|
||||
ERM::TLine & line = owner->retrieveLine(lp);
|
||||
|
||||
boost::apply_visitor(lineConverter, line);
|
||||
std::visit(lineConverter, line);
|
||||
}
|
||||
|
||||
out << "end" << std::endl;
|
||||
@ -1285,7 +1285,7 @@ namespace ERMConverter
|
||||
if(tid.empty())
|
||||
throw EInterpreterError("Function must have identifier");
|
||||
|
||||
Variable v = boost::apply_visitor(LVL1IexpToVar(), tid[0]);
|
||||
Variable v = std::visit(LVL1IexpToVar(), tid[0]);
|
||||
|
||||
if(v.isSpecial())
|
||||
throw ELineProblem("Special variable syntax ('d') is not allowed in function definition");
|
||||
@ -1304,7 +1304,7 @@ namespace ERMConverter
|
||||
if(owner->isATrigger(curLine))
|
||||
break;
|
||||
|
||||
boost::apply_visitor(lineConverter, curLine);
|
||||
std::visit(lineConverter, curLine);
|
||||
}
|
||||
|
||||
out << "end," << std::endl;
|
||||
@ -1332,7 +1332,7 @@ namespace ERMConverter
|
||||
{
|
||||
for(const auto & id : trig.identifier.get())
|
||||
{
|
||||
Variable v = boost::apply_visitor(LVL1IexpToVar(), id);
|
||||
Variable v = std::visit(LVL1IexpToVar(), id);
|
||||
|
||||
if(v.isSpecial())
|
||||
throw ELineProblem("Special variable syntax ('d') is not allowed in trigger definition");
|
||||
@ -1358,7 +1358,7 @@ namespace ERMConverter
|
||||
if(owner->isATrigger(curLine))
|
||||
break;
|
||||
|
||||
boost::apply_visitor(lineConverter, curLine);
|
||||
std::visit(lineConverter, curLine);
|
||||
}
|
||||
|
||||
out << "end," << std::endl;
|
||||
@ -1383,14 +1383,14 @@ struct ScriptScanner : boost::static_visitor<>
|
||||
{
|
||||
if(cmd.which() == 0) //TCommand
|
||||
{
|
||||
Tcommand tcmd = boost::get<Tcommand>(cmd);
|
||||
Tcommand tcmd = std::get<Tcommand>(cmd);
|
||||
switch (tcmd.cmd.which())
|
||||
{
|
||||
case 0: //trigger
|
||||
{
|
||||
Trigger trig;
|
||||
trig.line = lp;
|
||||
interpreter->triggers[ TriggerType(boost::get<ERM::Ttrigger>(tcmd.cmd).name) ].push_back(trig);
|
||||
interpreter->triggers[ TriggerType(std::get<ERM::Ttrigger>(tcmd.cmd).name) ].push_back(trig);
|
||||
}
|
||||
break;
|
||||
case 1: //instruction
|
||||
@ -1402,7 +1402,7 @@ struct ScriptScanner : boost::static_visitor<>
|
||||
{
|
||||
Trigger trig;
|
||||
trig.line = lp;
|
||||
interpreter->postTriggers[ TriggerType(boost::get<ERM::TPostTrigger>(tcmd.cmd).name) ].push_back(trig);
|
||||
interpreter->postTriggers[ TriggerType(std::get<ERM::TPostTrigger>(tcmd.cmd).name) ].push_back(trig);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -1431,7 +1431,7 @@ bool ERMInterpreter::isATrigger( const ERM::TLine & line )
|
||||
{
|
||||
case 0: //v-exp
|
||||
{
|
||||
TVExp vexp = boost::get<TVExp>(line);
|
||||
TVExp vexp = std::get<TVExp>(line);
|
||||
if(vexp.children.empty())
|
||||
return false;
|
||||
|
||||
@ -1441,7 +1441,7 @@ bool ERMInterpreter::isATrigger( const ERM::TLine & line )
|
||||
return false;
|
||||
break;
|
||||
case TCMD:
|
||||
return isCMDATrigger( boost::get<ERM::Tcommand>(vexp.children[0]) );
|
||||
return isCMDATrigger( std::get<ERM::Tcommand>(vexp.children[0]) );
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
@ -1451,11 +1451,11 @@ bool ERMInterpreter::isATrigger( const ERM::TLine & line )
|
||||
break;
|
||||
case 1: //erm
|
||||
{
|
||||
TERMline ermline = boost::get<TERMline>(line);
|
||||
TERMline ermline = std::get<TERMline>(line);
|
||||
switch(ermline.which())
|
||||
{
|
||||
case 0: //tcmd
|
||||
return isCMDATrigger( boost::get<ERM::Tcommand>(ermline) );
|
||||
return isCMDATrigger( std::get<ERM::Tcommand>(ermline) );
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
@ -1500,17 +1500,17 @@ ERM::TTriggerBase & ERMInterpreter::retrieveTrigger(ERM::TLine & line)
|
||||
{
|
||||
if(line.which() == 1)
|
||||
{
|
||||
ERM::TERMline &tl = boost::get<ERM::TERMline>(line);
|
||||
ERM::TERMline &tl = std::get<ERM::TERMline>(line);
|
||||
if(tl.which() == 0)
|
||||
{
|
||||
ERM::Tcommand &tcm = boost::get<ERM::Tcommand>(tl);
|
||||
ERM::Tcommand &tcm = std::get<ERM::Tcommand>(tl);
|
||||
if(tcm.cmd.which() == 0)
|
||||
{
|
||||
return boost::get<ERM::Ttrigger>(tcm.cmd);
|
||||
return std::get<ERM::Ttrigger>(tcm.cmd);
|
||||
}
|
||||
else if(tcm.cmd.which() == 3)
|
||||
{
|
||||
return boost::get<ERM::TPostTrigger>(tcm.cmd);
|
||||
return std::get<ERM::TPostTrigger>(tcm.cmd);
|
||||
}
|
||||
throw ELineProblem("Given line is not a trigger!");
|
||||
}
|
||||
@ -1533,7 +1533,7 @@ std::string ERMInterpreter::loadScript(const std::string & name, const std::stri
|
||||
scripts[LinePointer(static_cast<int>(buf.size()), g, buf[g].realLineNum)] = buf[g].tl;
|
||||
|
||||
for(auto p : scripts)
|
||||
boost::apply_visitor(ScriptScanner(this, p.first), p.second);
|
||||
std::visit(ScriptScanner(this, p.first), p.second);
|
||||
|
||||
std::stringstream out;
|
||||
|
||||
@ -1575,7 +1575,7 @@ namespace VERMInterpreter
|
||||
{
|
||||
VOption convertToVOption(const ERM::TVOption & tvo)
|
||||
{
|
||||
return boost::apply_visitor(OptionConverterVisitor(), tvo);
|
||||
return std::visit(OptionConverterVisitor(), tvo);
|
||||
}
|
||||
|
||||
VNode::VNode( const ERM::TVExp & exp )
|
||||
|
Reference in New Issue
Block a user