Skip to content

Commit

Permalink
replace boost list_of with C++11 builtins (#3522)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfranke committed Oct 26, 2015
1 parent 069f34e commit 64ec735
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 37 deletions.
31 changes: 14 additions & 17 deletions Compiler/Template/CodegenCpp.tpl
Expand Up @@ -8144,10 +8144,10 @@ template memberVariableInitialize2(SimVar simVar, HashTableCrIListArray.HashTabl
<%arrayName%> = StatArrayDim<%dims%><<%typeString%>, <%arrayextentDims(name, v.numArrayElement)%>, true>(&_pointerTo<%type%>Vars[<%arrayHeadIdx%>]);
>>
else
let arrayIndices = SimCodeUtil.getVarIndexListByMapping(varToArrayIndexMapping,name,indexForUndefinedReferences) |> idx => '(<%idx%>)'; separator=""
let arrayIndices = SimCodeUtil.getVarIndexListByMapping(varToArrayIndexMapping,name,indexForUndefinedReferences) |> idx => '<%idx%>'; separator=" LIST_SEP "
<<
<%typeString%>* <%arrayName%>_ref_data[<%size%>];
_sim_vars->init<%type%>AliasArray(boost::assign::list_of<%arrayIndices%>,<%arrayName%>_ref_data);
_sim_vars->init<%type%>AliasArray(LIST_OF <%arrayIndices%> LIST_END, <%arrayName%>_ref_data);
<%arrayName%> = RefArrayDim<%dims%><<%typeString%>, <%arrayextentDims(name, v.numArrayElement)%>>(<%arrayName%>_ref_data);
>>
/*special case for variables that marked as array but are not arrays */
Expand Down Expand Up @@ -9493,8 +9493,8 @@ template outputIndices(ModelInfo modelInfo)
case MODELINFO(varInfo=VARINFO(__),vars=SIMVARS(__)) then
if varInfo.numOutVars then
<<
var_ouputs_idx = boost::assign::map_list_of <%
{(vars.outputVars |> SIMVAR(__) => '(<%index%>,"<%crefStr(name)%>")';separator=",") };separator=","%>;
var_ouputs_idx = MAP_LIST_OF <%
{(vars.outputVars |> SIMVAR(__) => '<%index%>,"<%crefStr(name)%>"';separator=",") };separator=" MAP_LIST_SEP "%> MAP_LIST_END;
>>
end outputIndices;

Expand Down Expand Up @@ -12743,8 +12743,8 @@ then
<<
label_list_type <%lastIdentOfPath(modelInfo.name)%>::getLabels()
{
label_list_type labels = tuple_list_of
<%(labels |> label hasindex index0 => '(<%index0%>,&_<%label%>_1,&_<%label%>_2)') ;separator=" "%>;
label_list_type labels = TUPLE_LIST_OF
<%(labels |> label hasindex index0 => '<%index0%>,&_<%label%>_1,&_<%label%>_2') ;separator=" TUPLE_LIST_SEP "%> TUPLE_LIST_END;
return labels;
}
>>
Expand Down Expand Up @@ -13726,22 +13726,19 @@ template functionInitDelay(DelayedExpression delayed,SimCode simCode ,Text& extr
let &varDecls = buffer "" /*BUFD*/
let &preExp = buffer "" /*BUFD*/
let delay_id = (match delayed case DELAYED_EXPRESSIONS(__) then (delayedExps |> (id, (e, d, delayMax)) =>
'<%id%>';separator=","))
'<%id%>';separator=" LIST_SEP "))
let delay_max = (match delayed case DELAYED_EXPRESSIONS(__) then (delayedExps |> (id, (e, d, delayMax)) =>
let delayExpMax = daeExp(delayMax, contextSimulationNonDiscrete, &preExp /*BUFC*/, &varDecls /*BUFD*/,simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)
'<%delayExpMax%>';separator=","))
'<%delayExpMax%>';separator=" LIST_SEP "))
if delay_id then
<<
<<
//init delay expressions
<%varDecls%>
<%varDecls%>
<%preExp%>
vector<double> delay_max;
vector<unsigned int > delay_ids;
delay_ids+= <%delay_id%>;
delay_max+=<%delay_max%>;
intDelay(delay_ids,delay_max);

>>
vector<double> delay_max = LIST_OF <%delay_max%> LIST_END;
vector<unsigned int> delay_ids = LIST_OF <%delay_id%> LIST_END;
intDelay(delay_ids, delay_max);
>>
else " "
end functionInitDelay;

Expand Down
Expand Up @@ -8,13 +8,21 @@
#include <Core/Utils/Modelica/ModelicaSimulationError.h>
string error_id_string(SIMULATION_ERROR id)
{
std::map<SIMULATION_ERROR,std::string> error_id_info= map_list_of(SOLVER,"solver")(ALGLOOP_SOLVER,"algloop solver")(MODEL_EQ_SYSTEM,"model equation system")(ALGLOOP_EQ_SYSTEM,"algloop equation system")
( SOLVER,"csv")(MODEL_FACTORY,"model factory")(SIMMANAGER,"simulation manager")(EVENT_HANDLING,"event handling")
(TIME_EVENTS,"time event")( DATASTORAGE,"data storage")(UTILITY,"utility")(MODEL_ARRAY_FUNCTION,"array function")
(MATH_FUNCTION,"math function");


return error_id_info[id];
std::map<SIMULATION_ERROR, std::string> error_id_info = MAP_LIST_OF
SOLVER, "solver" MAP_LIST_SEP
ALGLOOP_SOLVER, "algloop solver" MAP_LIST_SEP
MODEL_EQ_SYSTEM, "model equation system" MAP_LIST_SEP
ALGLOOP_EQ_SYSTEM, "algloop equation system" MAP_LIST_SEP
MODEL_FACTORY, "model factory" MAP_LIST_SEP
SIMMANAGER, "simulation manager" MAP_LIST_SEP
EVENT_HANDLING, "event handling" MAP_LIST_SEP
TIME_EVENTS, "time event" MAP_LIST_SEP
DATASTORAGE, "data storage" MAP_LIST_SEP
UTILITY, "utility" MAP_LIST_SEP
MODEL_ARRAY_FUNCTION, "array function" MAP_LIST_SEP
MATH_FUNCTION, "math function" MAP_LIST_END;

return error_id_info[id];
}


Expand All @@ -35,4 +43,4 @@


}
/** @} */ // end of coreUtils
/** @} */ // end of coreUtils
30 changes: 25 additions & 5 deletions SimulationRuntime/cpp/Include/Core/Modelica.h
Expand Up @@ -13,8 +13,6 @@
#include <numeric>
#include <functional>

#include <boost/assign/std/vector.hpp> // for 'operator+=()'
#include <boost/assign/list_of.hpp> // for 'list_of()'
#include <boost/unordered_map.hpp>
#include <boost/unordered_set.hpp>
//#include <boost/function.hpp>
Expand All @@ -38,12 +36,9 @@ using std::endl;
using std::cout;
using std::cerr;
using std::ostream_iterator;
using boost::unordered_map;
using namespace boost::numeric;
using std::map;
using std::pair;
using std::make_pair;
using namespace boost::assign;
using std::max;
using std::min;
using std::string;
Expand All @@ -55,6 +50,8 @@ using std::deque;
using std::copy;
using std::exception;
using std::runtime_error;
using boost::unordered_map;
using namespace boost::numeric;

#if defined(USE_CPP_ELEVEN)
#include <array>
Expand All @@ -64,6 +61,17 @@ using std::runtime_error;
#include <condition_variable>
#include <tuple>
#include <memory>

#define LIST_OF {
#define LIST_SEP ,
#define LIST_END }
#define MAP_LIST_OF {{
#define MAP_LIST_SEP },{
#define MAP_LIST_END }}
#define TUPLE_LIST_OF {std::make_tuple(
#define TUPLE_LIST_SEP ),std::make_tuple(
#define TUPLE_LIST_END )}

/** namespace for generated code to avoid name clashes */
namespace omcpp {
using std::ref;
Expand Down Expand Up @@ -103,6 +111,7 @@ using std::runtime_error;
using boost::make_tuple;
using boost::minmax_element;
#endif
#include <boost/assign/list_of.hpp>
#include <boost/array.hpp>
#include <boost/math/special_functions/trunc.hpp>
#include <boost/ref.hpp>
Expand All @@ -125,6 +134,17 @@ using std::runtime_error;
using boost::unique_lock;
using boost::dynamic_pointer_cast;
#endif //USE_THREAD

#define LIST_OF boost::assign::list_of(
#define LIST_SEP )(
#define LIST_END )
#define MAP_LIST_OF boost::assign::map_list_of(
#define MAP_LIST_SEP )(
#define MAP_LIST_END )
#define TUPLE_LIST_OF boost::assign::tuple_list_of(
#define TUPLE_LIST_SEP )(
#define TUPLE_LIST_END )

/** namespace for generated code to avoid name clashes */
namespace omcpp {
using boost::ref;
Expand Down
23 changes: 16 additions & 7 deletions SimulationRuntime/cpp/SimCoreFactory/OMCFactory/OMCFactory.cpp
Expand Up @@ -72,9 +72,17 @@ SimSettings OMCFactory::readSimulationParameter(int argc, const char* argv[])
{
int opt;
int portnum;
map<string,LogCategory> logCatMap = map_list_of("init", LC_INIT)("nls", LC_NLS)("ls",LC_LS)("solv", LC_SOLV)("output", LC_OUT)("event",LC_EVT)("model",LC_MOD)("other",LC_OTHER);
map<string,LogLevel> logLvlMap = map_list_of("error", LL_ERROR)("warning", LL_WARNING)("info", LL_INFO)("debug", LL_DEBUG);
map<string,OutputPointType> outputPointTypeMap = map_list_of("all", OPT_ALL)("step", OPT_STEP)("none", OPT_NONE);
map<string, LogCategory> logCatMap = MAP_LIST_OF
"init", LC_INIT MAP_LIST_SEP "nls", LC_NLS MAP_LIST_SEP
"ls", LC_LS MAP_LIST_SEP "solv", LC_SOLV MAP_LIST_SEP
"output", LC_OUT MAP_LIST_SEP "event", LC_EVT MAP_LIST_SEP
"model", LC_MOD MAP_LIST_SEP "other", LC_OTHER MAP_LIST_END;
map<string, LogLevel> logLvlMap = MAP_LIST_OF
"error", LL_ERROR MAP_LIST_SEP "warning", LL_WARNING MAP_LIST_SEP
"info", LL_INFO MAP_LIST_SEP "debug", LL_DEBUG MAP_LIST_END;
map<string, OutputPointType> outputPointTypeMap = MAP_LIST_OF
"all", OPT_ALL MAP_LIST_SEP "step", OPT_STEP MAP_LIST_SEP
"none", OPT_NONE MAP_LIST_END;
po::options_description desc("Allowed options");

//program options that can be overwritten by OMEdit must be declared as vector
Expand Down Expand Up @@ -303,10 +311,11 @@ vector<const char *> OMCFactory::handleComplexCRuntimeArguments(int argc, const
else if ((oit = opts.find(arg)) != opts.end() && i < argc - 1)
opts[oit->first] = argv[++i]; // regular override
else if (strncmp(argv[i], "-override=", 10) == 0) {
map<string, string> supported = map_list_of
("startTime", "-S")("stopTime", "-E")("stepSize", "-H")
("numberOfIntervals", "-G")("solver", "-I")("tolerance", "-T")
("outputFormat", "-O");
map<string, string> supported = MAP_LIST_OF
"startTime", "-S" MAP_LIST_SEP "stopTime", "-E" MAP_LIST_SEP
"stepSize", "-H" MAP_LIST_SEP "numberOfIntervals", "-G" MAP_LIST_SEP
"solver", "-I" MAP_LIST_SEP "tolerance", "-T" MAP_LIST_SEP
"outputFormat", "-O" MAP_LIST_END;
vector<string> strs;
boost::split(strs, argv[i], boost::is_any_of(",="));
for (int j = 1; j < strs.size(); j++) {
Expand Down

0 comments on commit 64ec735

Please sign in to comment.