A list for the developers of CellML tools

Text archives Help


[cellml-dev] CellML wchar sizes


Chronological Thread 
  • From: lpsmith at spod-central.org (Lucian Smith)
  • Subject: [cellml-dev] CellML wchar sizes
  • Date: Tue, 1 Dec 2009 20:11:05 +0000

* Andrew Miller <ak.miller at auckland.ac.nz> [2009-12-01 02:11] writes:
> Lucian Smith wrote:
> >I have the following code in my own program:
> >
> > cellml_api::CellMLBootstrap* boot = CreateCellMLBootstrap();
> > wstring lev;
> > lev = L"1.1";
> > m_cellmlmodel = boot->createModel(lev.c_str());
> >
> >In GDB, I can look at lev.c_str()[0] - [3] and see that it is 49 46 49 00.
> >So far, so good. However, once the program steps into the 'createModel'
> >function, suddenly the passed-in string is no longer the same--it's
> >3014705 49 795046515 [etc etc]. And the wchar_t* is exactly the same, and
> >if I do a 'frame 1' to go back to my code, *that* part still sees 49 46 49
> >0. The net result is that 'createModel' throws an exception because the
> >passed-in 'version' is not what it thinks is "1.0" or "1.1".
> >
> >I think I can trace this down to the fact that in order to successfully
> >#include <nsStringAPI.h>, I had to use the compiler flag '-fshort-wchar'.
>
> Indeed - we need to be compatible with existing compiled libraries on
> the system (which typically use 32 bit wchar_t strings), as well as with
> XPCOM, so we have to explicitly convert between coding systems (see
> http://cellml-api.hg.sf.net/hgweb/cellml-api/cellml-api/file/42412b41ed02/simple_interface_generators/glue/xpcom/WideCharSupport.cpp)
>
> For the API user, this means that you have two choices:
> * Compile your code for use through XPCOM and only use the CellML API
> through XPCOM (with the exception of setting up the bootstrap). In this
> case build with -fshort-wchar
> * Don't use XPCOM, don't include XPCOM headers like nsStringAPI.h,
> and build without -fshort-wchar
>
> For example, you could compile your code with -fshort-wchar and write
> what you had above as:
>
> nsresult rv;
> nsCOMPtr<cellml_apiICellMLBootstrap>
> boot(do_GetService(CELLML_BOOTSTRAP_CID, &rv));
> NS_ENSURE_SUCCESS(rv, rv);
> nsCOMPtr<cellml_apiIModel> mod;
> rv = boot->CreateModel(NS_LITERAL_STRING("1.1"), getter_AddRefs(mod));
> NS_ENSURE_SUCCESS(rv, rv);
>
> i.e. the same thing as what you already have, but using XPCOM instead
> (note that I haven't checked that the above compiles, but it should at
> least give you the idea of what you need to do if you want to access the
> API through XPCOM from C++).
>
> OpenCell mainly accesses the API through Javascript where you can do a
> similar thing using notation like
>
> Components.classes["@cellml.org/cellml-bootstrap;1"].getService(Components.interfaces.cellml_apiICellMLBootstrap).createModel("1.1");

Am I right in assuming that if I want to use OpenCell's DataCollector
library (cellml-opencell/opencellStage/components/libDataCollector.so ) I
will need to use XPCOM, and write code like the above, in order to use
functions like MathMLToInputFormat, which takes an nsCString as an
argument?

If so, where do the functions 'boot' and 'do_GetService' come from (as
well as the (I assume) #define's) from your example?

-Lucian




Archive powered by MHonArc 2.6.18.

Top of page