Type case from base class to children class.

Type case from base class to children class.

Post by Shunri Gu » Fri, 14 Jul 2000 04:00:00



See example below:
        interface a{
        }
        interface b:a{
        }
        interface c:a{
        }

        at Client side(C++), I want to do the following cast operation:

        void SomeOperation(a a_instance)
        {
         if (certain condition)
         {
         b b_instance = (b) a_instance;
         do some operations only defined in b   ...
         }
         else
         {
         c c_instance = (c) a_instance;
         do some operations only defined in c  
         }

        }

        Becuase IDL inheritance map to C++ public virtual inheritance, the compiling process will file for it is impossible to case from a virtual base. Any workwround?

 
 
 

Type case from base class to children class.

Post by Ruslan Shevchenk » Fri, 14 Jul 2000 04:00:00



> See example below:
>         interface a{
>         }
>         interface b:a{
>         }
>         interface c:a{
>         }

>         at Client side(C++), I want to do the following cast operation:

>         void SomeOperation(a a_instance)
>         {
>          if (certain condition)
>          {
>          b b_instance = (b) a_instance;
>          do some operations only defined in b   ...
>          }
>          else
>          {
>          c c_instance = (c) a_instance;
>          do some operations only defined in c
>          }

>         }

>         Becuase IDL inheritance map to C++ public virtual inheritance, the compiling process will file for it is impossible to case from a virtual base. Any workwround?

 _narrow() // or _downcast() in CORBA 2.3, i. e:

c_var c_instance = c::_narrow(a_instance);
if (CORBA::is_nil(c)) {
  throw WhatYouWantToThrowHere;

Quote:}

do some operations only defined in c

 
 
 

Type case from base class to children class.

Post by Michi Hennin » Sat, 15 Jul 2000 04:00:00



> >         Becuase IDL inheritance map to C++ public virtual inheritance, the compiling process will file for it is impossible to case from a virtual base. Any workwround?

>  _narrow() // or _downcast() in CORBA 2.3, i. e:

For interfaces, you must use _narrow(). _downcast() works only for exceptions.

                                                        Cheers,

                                                                Michi.
--
Michi Henning               +61 7 3891 5744
Object Oriented Concepts    +61 4 1118 2700 (mobile)
Suite 4, 904 Stanley St     +61 7 3891 5009 (fax)

AUSTRALIA                   http://www.ooc.com.au/staff/michi-henning.html

 
 
 

1. Legacy Class, implementation with class A in class B parameter...

Hello,

Hello, I have some questions about implementing CORBA with legacy class
inC++(which was not develooped for this...).

I have 2 legacy class:

//------------------
Classe LcDatabase
//------------------
 bool Open( const char* szPathname);
 bool Close();
...}

//------------------
Classe LcAdmLookup
//------------------
 long Count(const LcDatabase& Database, const char* CountryName);
...}

IDL

module Napi
 {
 interface Database
  {
  boolean Open(in string szPathname);
  void Close();
  };
 interface AdmLookup
  {
  long Count(in Database Db, in string CountryName);
  };
 };

IMPLEMENTATION

class DatabaseImpl: public POA_Napi::Database
{
protected:
    LcDatabase Db;   //Legacy class
public:
    CORBA::Boolean Open(const char * szPathname)
        {
         CORBA::Boolean res = Db.Open(szPathname);
         return res;
        };
    void Close()
        {
         Db.Close();
        };

class AdmLookupImpl: public POA_Napi::AdmLookup
{
public:
 virtual CORBA::Long Count(Napi::Database_ptr DbI)
    {
     LcAdmLookup Count( Db, "Test" );
    }

Here, the problem, is that 'Db' should be a reference of LcDatabase and not
DatabaseImpl
How can I use an get the LcDatabase instance from DatabaseImpl instance in
AdmLookupImpl..., could you give me the exemple.

Thanks for your HELP.

2. Pathworks server perfomance problem on OpenVMS VAX

3. class inherit class A _and_ class B

4. Windows graphics in games ??

5. Range Class / Spinner class/ numeric data type

6. about image processing, imcontour

7. How do I derive classes from a base class

8. New w2k install - continual error messages

9. xbox console Class A and Class B

10. MNP Protocol Specifications - Class 4 & Class 5

11. Class C subnet mask on class B network

12. What are legacy classes, wat zijn legacy classes?