NeXus C++ API

Mark Koennecke Mark.Koennecke at psi.ch
Thu Jan 10 07:36:32 GMT 2002




Dear Sebastian Huber,

On Wed, 9 Jan 2002, Sebastian Huber wrote:

> Hello,
> is someone working on a C++ API for NeXus or has someone developed one?
> I'am currently working on this topic and it may be helpful to share ideas.
> 
  There is nobody working on a C++ API. However we strive to have the
  NeXus API in such a state that it can be compiled with a C++ compiler
  and can be used easily with C++.

  I wrote the Java-API for NeXus and this made me think about object 
  orientation within the NeXus-API and I want to share that. Initially
  one would think that NeXus files, groups, datasets and attributes could
  constitute objects of their own right. When taking a closer look into
  this I realized that such a separation  would lead to very complicated
  code due to the fact that the underlying HDF libraries are sophisticated
  state machines by themselves. So I stepped back from this and just
  encapsulated the NeXus-API in one class. This is also the way how the
  people from NCSA did it for their Java-API's to both HDF-4 and HDF-5.
  And I'am sure with due consideration and for a good reason.

> The work on this API resulted in the question why the C API does not make a
> consequent use of the const specifier?
> 
> For example the NXmakegroup function:
> 	The first parameter is CONSTCHAR, but the second not, although the
> 	functions executed with that parameter (strcmp, sprintf and Vsetclass)
> 	declare it as const char.
> 
  You are right, the NXclass parameter can almost always be CONSTCHAR as 
  well. I know that some people feel strongly about const and there are 
  even good theoretical arguments in favour of it. I personally am very
  sloppy with const because it tends to come in my way and forces me to
  clutter the code with lots of casts. 

> And why do you use sprintf instead of snprintf?

  Probably because it is in the ANSI-C standard library and snprintf
  isn't. Though it might be POSIX. I also learned about the virtues of
  snprintf only recently when reading a paper about writing secure
  programs. I think changing the code to use snprintf wherevever 
  feasible is a good idea. Before doing this I would like to check if this
  function is available on all important platforms or if there is a 
  implementation of snprintf which can be distributed with the NeXus code
  for systems which do not have that function. Any info about this anyone?
  I know that both Linux and True64 Unix seem to support snprintf. 
 
                      Regards,
		
				Mark Koennecke





More information about the NeXus mailing list