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

Update c++ example to use c++11 features, std lib, and error handling #134

Closed
mschollmeier opened this issue Jul 17, 2020 · 2 comments
Closed
Milestone

Comments

@mschollmeier
Copy link
Contributor

I've updated the c++ example 6 to include std library features (e.g., unique_ptr, auto, cout, ...) and added rudimentary error handling. For example:

/*parser test for Ca(HCO3)2 (calcium bicarbonate)*/
auto cdtest = unique_ptr<compoundData>(CompoundParser("Ca(HCO3)2", &err));
if (cdtest) {
    cout << "Ca(HCO3)2 contains " << cdtest->nAtomsAll << " atoms, " << cdtest->nElements 
         << " elements and has a molar mass of " << cdtest->molarMass << " g/mol" << endl;
    for (int i = 0; i < cdtest->nElements; i++)
        cout << "  Element " << cdtest->Elements[i] << ": " 
             << cdtest->massFractions[i] * 100.0 << "% and " 
             << cdtest->nAtoms[i] << " atoms" << endl;
}
else
    throw errorstring(__LINE__, *err);

If you're interested I can upload and create a pull request.

@tschoonj
Copy link
Owner

Yep that looks cool. Feel free to open a PR.

Thanks!

@tschoonj
Copy link
Owner

tschoonj commented Jan 6, 2021

Closed in #139 and #144

@tschoonj tschoonj closed this as completed Jan 6, 2021
@tschoonj tschoonj added this to the 4.1.0 milestone Mar 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants