RISCSoftware / cpacs_tigl_gen

Generates CPACS schema based classes for TiGL
Apache License 2.0
5 stars 5 forks source link

Get aircraft/model element #43

Closed MarAlder closed 2 years ago

MarAlder commented 2 years ago

Hi,

I'm generating classes for cpacs/header/... and cpacs/vehicles/aircraft/model/reference/... to use it for my cpacsLibrary project.

The first one is working fine in my test cases, e.g.:

std::string name = m_cpacsTree->GetHeader().GetName();

However, I can't access the reference node. Is this the intended way to get an aircraft model?:

auto model = m_cpacsTree->GetVehicles()->GetAircraft()->GetModels().at(0);

I guess the unique_ptr usage is not yet clear to me, as my (MinGW) compiler complains:

call to deleted constructor of 'std::unique_ptr<cpacsLib::generated::CPACSAircraftModel, std::default_delete<cpacsLib::generated::CPACSAircraftModel>>'

Until now my cpacsLibrary only has a dummy uID manager (just the function declarations, no content yet). But this should not be used at this point anyway, should it?

generated.zip

RlanderRISCSW commented 2 years ago

Hi,

The problem is that the variable model is of type std::unique_ptr<CPACSAircraftModel>, so a copy of the unique_ptr would be generated in the following line due to the assignment, which is not possible (would not be unique any more):

auto model = m_cpacsTree->GetVehicles()->GetAircraft()->GetModels().at(0);

Instead of copying the unique_ptr you could take a reference to it by changing the code to:

auto& model = m_cpacsTree->GetVehicles()->GetAircraft()->GetModels().at(0);

The uID manager is not relevant in this case.

MarAlder commented 2 years ago

Ok, this makes sense. Thanks!

And then, how to I finally get the reference node? I can see from the debugger that all the member variables are initialized in my model, but calling the getter functions like below is obviously wrong:

m_cpacsTree->GetVehicles()->GetAircraft()->GetModels().at(0)->GetReference();
RlanderRISCSW commented 2 years ago

Getting the reference-node via the GetReference function should be fine. The reference node is optional, thus the function returns a reference to the boost::optional type:

        CPLIB_EXPORT virtual boost::optional<CPACSReference>& GetReference();

So accessing it could be written for example:


const auto& reference = m_cpacsTree->GetVehicles()->GetAircraft()->GetModels().at(0)->GetReference();
if (reference) {
    const auto& point = reference->GetPoint();
}
MarAlder commented 2 years ago

Edit: I'll delete what I just wrote as I forgot an include of CPACSAircraftModel.h in my test file... :flushed:

Thanks for your help, R.!!

MarAlder commented 2 years ago

Being happy about the answer and therefore closing the issue :)