- From: ak.miller at auckland.ac.nz (Andrew Miller)
- Subject: [cellml-dev] CellML wchar sizes
- Date: Fri, 04 Dec 2009 13:07:52 +1300
Lucian Smith wrote:
>
Ok, I appear to be taking things in tiny tiny baby steps, but I keep
>
thinking that if only I understood the next bit, I'd get it. If we take a
>
slightly-modified version of your code:
>
>
nsresult rv;
>
nsCOMPtr<cellml_apiICellMLBootstrap>
>
boot(do_GetService(CELLML_BOOTSTRAP_CONTRACTID, &rv));
>
NS_ENSURE_SUCCESS(rv, );
>
nsCOMPtr<cellml_apiIModel> mod;
>
rv = boot->CreateModel(NS_LITERAL_STRING("1.1"), getter_AddRefs(mod));
>
NS_ENSURE_SUCCESS(rv, );
>
>
(NS_ENSURE_SUCCESS(rv, rv) didn't compile for some reason; I saw the above
>
version in DataCollector.cpp so I went with that and it compiled. I don't
>
know why, but I'm not complaining...)
That's probably because the function you were in doesn't return nsresult.
NS_ENSURE_SUCCESS(a, b) checks if a is a successful code (e.g. NS_OK is
an example of a successful code, while NS_ERROR_FAILURE is an example of
a failure code). If it is a failure code, it returns b.
All XPCOM methods return nsresult, but if you are calling XPCOM from a
non-XPCOM method you need to adjust the NS_ENSURE_SUCCESS second
parameter to return an appropriate thing (in your case, not returning
anything because presumably you are in a void method).
>
>
To me, it seemed like since you created 'boot' using those methods, and
>
then called a function that was originally defined for the CellML
>
Bootstrap interface thingy, I could then do the following:
>
>
nsCOMPtr<cellml_apiICellMLComponentSet> components =
>
mod->localComponents();
That's because all XPCOM functions return nsresult, and the return value
is the second parameter. They also capitalise the first letter. So you need:
nsCOMPtr<cellml_apiICellMLComponentSet> components;
rv = mod->LocalComponents(getter_AddRefs(components));
NS_ENSURE_SUCCESS(rv, );
I'd suggest reading up on XPCOM - there is a lot of good information on
the Internet about it.
Best wishes,
Andrew
>
>
But... no such luck:
>
>
error: 'class cellml_apiIModel' has no member named 'localComponents'
>
>
So how do I get at those functions like 'localComponents' that I used to
>
be able to call when 'mod' was a cellml_api::Model* ?
>
>
-Lucian
>
_______________________________________________
>
cellml-tools-developers mailing list
>
cellml-tools-developers at cellml.org
>
http://www.cellml.org/mailman/listinfo/cellml-tools-developers
Archive powered by MHonArc 2.6.18.