Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Variant.trustedGet multiple values #33

Closed
andre2007 opened this issue Dec 13, 2020 · 4 comments
Closed

Feature request: Variant.trustedGet multiple values #33

andre2007 opened this issue Dec 13, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@andre2007
Copy link

I have a scenario like this:

There are 2 FMU classes version 1 and two FMU classes version 2.
Version 1 supports a method initialize, while this method is not available in version 2.

I want to call trustedGet like this fmu.trustedGet!(FMU1Slave, FMU1Model).initialize();.
At the specific code line, I know fmu is either FMU1Slave or FMU1Model. Both classes
supports method initialize. It should call method initialize independent whether it is now FMU1Slave or FMU1Model.

/+ dub.sdl:
	name "app"
	dependency "mir-core" version="1.1.51"
+/

import mir.algebraic;

class FMU1Slave
{
	void instantiate() {}
	void initialize() {}
}

class FMU1Model
{
	void instantiate() {}
	void initialize() {}
}

class FMU2Slave
{
	void instantiate() {}
	void enterInitializationMode() {}
	void exitInitializationMode() {}
}

class FMU2Model
{
	void instantiate() {}
	void enterInitializationMode() {}
	void exitInitializationMode() {}
}

void main()
{

	Variant!(FMU1Slave, FMU1Model, FMU2Slave, FMU2Model) fmu;
	string fmiVersion;
	bool isCoSimulation;

    if (fmiVersion == "1.0")
    {
        if (isCoSimulation)
            fmu = new FMU1Slave();
        else
            fmu = new FMU1Model();
        fmu.instantiate();
        fmu.trustedGet!(FMU1Slave, FMU1Model).initialize();
    }
    else
    {
        if (isCoSimulation)
            fmu = new FMU2Slave();
        else
            fmu = new FMU2Model();
        fmu.instantiate();
        fmu.enterInitializationMode();
        fmu.exitInitializationMode();
    }
}
@9il 9il added the enhancement New feature or request label Dec 16, 2020
@9il
Copy link
Member

9il commented Dec 16, 2020

Yes, we already have a draft for it. Will be added.

9il added a commit that referenced this issue Dec 19, 2020
9il added a commit that referenced this issue Dec 19, 2020
@9il
Copy link
Member

9il commented Dec 19, 2020

Overload to work with algebraic type sets.

@deviator this may be helpful for the #34

@9il 9il closed this as completed Dec 19, 2020
@9il
Copy link
Member

9il commented Dec 19, 2020

v1.1.56

@andre2007
Copy link
Author

@9il thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants