vle-forge / vle

Virtual Laboratory Environment
http://www.vle-project.org
GNU General Public License v3.0
21 stars 22 forks source link

Executive::dump and add Conditions strange behavior #150

Closed rtrepos closed 5 years ago

rtrepos commented 10 years ago

Let us consider this example (this is the init function of an executive model)

virtual vd::Time init(const vd::Time& /*time*/)
{
    std::string condName1 = "coucou";
    std::string condName2 = "coucou2";
    vz::Condition& cond = conditions().add(condName1);
cond = conditions().add(condName2);
std::ofstream of("/tmp/tmp.vpz");
    dump(of);
    return vd::infinity;
}

the simulation of this executive leeds to the following error (on the call to dump):

Error while loading project The condition 'coucou2' already exists

The problem comes from the fact that there is no function Conditions::addCondition(const std::string&) only this one : Conditions::addCondition(const Condition&)

rtrepos commented 5 years ago

In vle 2.1, the error does not occur but the conditions, at the end, contain two conditions of name 'coucou2' which is forbidden. This is due to the operator :

Conditions& operator=(const Conditions& cond)

use in the line

cond = conditions().add(condName2);

which modifies the previous added condition.

This should nit be used that way and this does not require correction.