[omniORB] Fixed and string output

Mike Mascari mascarm@mascari.com
Fri Jul 12 01:37:00 2002


Duncan Grisby wrote:
> 
> On Thursday 11 July, Mike Mascari wrote:
> 
> > I have a rather stupid question. How can I convert a Fixed type to (char
> > *) or (const char *) ?
> 
> Sadly, the rather stupid answer is that there is no standard (direct)
> way to do it. An omniORB specific way is to call the NP_asString()
> method. It returns a char* that you must free with
> CORBA::string_free().
> 
> The C++ mapping does say that there should be stream operators to
> read/write Fixeds to streams, but they are still on the todo list.

NP_asString() confuses me. I have IDL that looks like this:

---

typedef fixed<16,4> Numeric;

typedef struct DBStore {
 Numeric taxrate;
};

interface StoreManager {

void updateStore(in DBStore store);

};

---

On the client, I have code that does this:

 store.taxrate = ".045";

Right before calling obj->updateStore(store), I do this (I know it leaks
memory, but its a debug line):

 ::AfxMessageBox(store.taxrate.NP_asString());

It correctly displays ".045". 

---

On the server, I do this:

 void IStoreManager::updateStore(const DBStore &data) {
 
  fprintf(stderr, "Tax rate: %s\n", data.taxrate.NP_asString());

  if (data.taxrate < Numeric(10)) {
   fprintf(stderr, "Confusing!\n");
  }

  ...

 }

Now the server's output is"

"45"
"Confusing!"

Is there something I'm not getting? Should I be making assumptions about
how to interpret the text output based upon the precision and scale?
Obviously the marshalling of the underlying data worked correctly
otherwise the comparison against Numeric(10) would be false. But why
does NP_asString() return "45" on the server and, seemingly correctly,
".045" on the client? If I use "4.5" as the value, I get "4.5" on the
client and "4.5" on the server. Also, in my search before my post I
found this:

http://cgi.omg.org/issues/cxx_revision.open.html#Issue3944

Does this mean that there will be a to_string() method in later
versions?

Thank you for any help,

Mike (Confused) Mascari
mascarm@mascari.com