[omniORB] Complex numbers

Marc Eberhard m.a.eberhard at aston.ac.uk
Thu Oct 9 20:51:35 BST 2003


On Thu, Oct 09, 2003 at 05:39:44PM +0100, Duncan Grisby wrote:
> As others have pointed out, it's basically luck that it works. Any
> number of things could cause it to break.

That's exactly what I was afraid of...

> The best, and simplest thing to do is just to use conversion functions
> that convert to and from the types you need. If (and only if) you find

OK, so I should look into this option first then.

> that the copying overhead is too high, the best thing to do would be
> to modify the omniidl output so it used the types you need rather than
> the CORBA types. That's fragile in that the layout of the generated
> code can change between omniORB versions, but it avoid second-guessing
> the way the C++ compiler arranges things.

That's a very interesting option. Looking at the output from omniidl, my
Complex struct reads

  struct Complex {
    typedef _CORBA_ConstrType_Fix_Var<Complex> _var_type;

    CORBA::Double re;
    CORBA::Double im;

    void operator>>= (cdrStream &) const;
    void operator<<= (cdrStream &);
  };

and the complex class definition from the C++ template library is

  // 26.2.2  Primary template class complex
  template<typename _Tp>
    class complex
    {
    public:
      typedef _Tp value_type;
      
      complex(const _Tp& = _Tp(), const _Tp & = _Tp());

      [... a few template defines...]

    private:
      _Tp _M_real, _M_imag;
    };

which results in the same binary data structure as long as CORBA::Double
equals _Tp.

Now would it do the trick, if I modify the output from omniidl to

  class Complex : public complex<double> {
    typedef _CORBA_ConstrType_Fix_Var<Complex> _var_type;

//    CORBA::Double re;
//    CORBA::Double im;

    void operator>>= (cdrStream &) const;
    void operator<<= (cdrStream &);
  };

this? The implementation of the stream operators needs to be cahnged too to
use the native fields as defined in the C++ complex type.

Is it considered dangerous to fiddle around with these definitions in such a
way? More or less dangerous than casting the types directly?

Thanks,
Marc
_______________________________________________________________________________

email: marc at greenie.net, marc.eberhard at alumni.tum.de, marc at affs.org.uk
email: m.a.eberhard at aston.ac.uk, web: http://www.aston.ac.uk/~eberhama/



More information about the omniORB-list mailing list