Message: RE: Writing UIcommands with units, and G4BestUnit interface Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

None RE: Writing UIcommands with units, and G4BestUnit interface 

Forum: (Graphical) User Interfaces
Re: None Writing UIcommands with units, and G4BestUnit interface (Michael H. Kelsey)
Re: None RE: Writing UIcommands with units, and G4BestUnit interface (Makoto Asai)
Re: None Re: Writing UIcommands with units, and G4BestUnit interface (Michael H. Kelsey)
Date: 23 Dec, 2010
From: Makoto Asai <Makoto Asai>

Mike,

I thought all of your un-defined number of parameters except the
last one are numbers rather than strings, e.g.
 /your/command 1.2 3.4 5.6 .... 8.9 cm
And you want to make the last unit parameter optional so that the
user may omit it, i.e.
 /your/command 1.2 3.4 5.6 .... 8.9 

Please note that ValueOf() method returns zero if the string is
not defined as a unit string. Thus, for the very last parameter 
token, you may check 
 1) if ValueOf() method returns a non-zero value, then it is a
    valid unit string
 2) if it is zero, convert it to a double. 

Makoto



> -----Original Message-----
> From: Mike Kelsey [mailto:kelsey@slac.stanford.edu]
> Sent: Thursday, December 23, 2010 10:30 AM
> To: Asai, Makoto
> Cc: userinterface-g4hn
> Subject: Re: Writing UIcommands with units, and G4BestUnit interface
> 
> Asai, Makoto writes:
> > http://www-
> geant4.kek.jp/lxr/source/intercoms/include/G4UIcommand.hh#L105
> 
> Yes, indeed, Makoto.  That's where I started.  I'm using ValueOf() in
> several places, where I already have the specific unit name string in
> hand.
> 
> My situation is where I _don't_ have the unit string yet.  G4BestUnit
> doesn't appear to have a way to get either that string (or the scale
> vlaue)
> by itself.  In G4UnitsTable.hh, the G4BestUnit functor,
> 
>  G4BestUnit(G4double value, G4String& category)
> 
> returns only the composite string (either via operator G4String() or
> operator<<) with both the scaled numeric value plus the chosen unit.
> 
> From looking at the code, all of the computational work for G4BestUnit
> is
> embedded in the operator<<() implementation, with no encapsulation of
> the
> pieces.
> 
> I'd like to know whether there might be a different interface somewhere
> which does the same job: given a double value and a units category, it
> returns the unit (by string or by scale) which best suits the input
> value.
> 
> Without such an interface, I can take the string returned by G4BestUnit
> and
> capture the second token, but that seems a bit wasteful.
> 
>       -- Mike

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 None: Re: Writing UIcommands with units, and G4BestUnit interface   (Mike Kelsey - 23 Dec, 2010)
 Add Message Add Message
to: "RE: Writing UIcommands with units, and G4BestUnit interface"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews


[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]