You're correct - it does have those member functions.  It's been a while
since I've used DOMString, so I guess we both stand corrected...

Dave



                                                                                       
                           
                    "Adams,                                                            
                           
                    David"               To:     "'[EMAIL PROTECTED]'" 
<[EMAIL PROTECTED]>    
                    <dadae@allsta        cc:     (bcc: David N Bertoni/CAM/Lotus)      
                           
                    te.com>              Subject:     RE: sample for down casting 
DOM_Node to DOM_Entity ??       
                                                                                       
                           
                    06/11/2001                                                         
                           
                    09:53 AM                                                           
                           
                    Please                                                             
                           
                    respond to                                                         
                           
                    xerces-c-dev                                                       
                           
                                                                                       
                           
                                                                                       
                           



I stand corrected and I apologize if I mislead any younger C++ developers.
I guess I haven't written to many base classes that didn't have a 'virtual'
function in it. 'dynamic_cast' doesn't require a 'pure virtual' method or
even to have the derived class override the base class 'virtual' method,
however.  I guess that down low, 'dynamic_cast' is looking at the virtual
tables.
I thank Dave at lotus for pointing this out. Even older engineers can still
learn.

Dave, one question though on the 'DOMString::print()',
'DOMString::println()'.  The header file I downloaded for Xerces-C 1.4 for
the MS platform does have those two methods in it. Are we on the same page
on this one?


> -----Original Message-----
> From:         [EMAIL PROTECTED] [SMTP:[EMAIL PROTECTED]]
> Sent:         Friday, June 08, 2001 9:13 PM
> To:           [EMAIL PROTECTED]
> Subject:           RE: sample for down casting DOM_Node to DOM_Entity ??
>
>
> Sorry, but polymorphism has _everything_ to do with dynamic casting.  If
a
> class has no virtual functions, it's not polymorphic, and you cannot use
> dynamic_cast to do run-time type introspection.
>
> If you don't believe me, why don't you try to put some of that code
you've
> been posting through your compiler and see what its says?  For example,
> Microsoft Visual C++ gives the following error:
>
> void
> foo(DOM_Node  node)
> {
>      DOM_Entity  entity = dynamic_cast<const DOM_Entity&>(node);
> }
>
> --------------------Configuration: TestXSLT - Win32
> Debug--------------------
> Compiling...
> process.cpp
> V:\xml-xalan\c\src\TestXSLT\process.cpp(790) : error C2683: dynamic_cast
:
> 'DOM_Node' is not a polymorphic type
>         ..\..\..\..\..\..\xml-xerces\c\src\dom/DOM_Node.hpp(95) : see
> declaration of 'DOM_Node'
> Error executing cl.exe.
>
> process.obj - 1 error(s), 0 warning(s)
>
> If you're going to post advice/code samples on the list, you ought to at
> least try it out before you post.
>
> Dave
>
>
>
>
>
>                     "Adams,
>
>                     David"               To:
> "'[EMAIL PROTECTED]'"
>                     <dadae@allsta        <[EMAIL PROTECTED]>
>
>                     te.com>              cc:     (bcc: David N
> Bertoni/CAM/Lotus)
>                                          Subject:     RE: sample for down
> casting DOM_Node to DOM_Entity ??
>                     06/08/2001
>
>                     05:40 PM
>
>                     Please
>
>                     respond to
>
>                     xerces-c-dev
>
>
>
>
>
>
>
>
> class CDOM_EXPORT DOM_Entity: public DOM_Node {
> .
> .
> .
> .
> };
>
> polymorphism has nothing to do with dynamically casting up and down a
> class
> heirarchy tree. You might want to downcast to access methods in the
> derived
> type, they don't have to be polymorphic methods.
>
>
> > -----Original Message-----
> > From:         [EMAIL PROTECTED]
[SMTP:[EMAIL PROTECTED]]
> > Sent:         Friday, June 08, 2001 4:07 PM
> > To:           [EMAIL PROTECTED]
> > Subject:           RE: sample for down casting DOM_Node to DOM_Entity
??
> >
> >
> > You cannot use dynamic_cast with DOM_Node because it is not a
> polymorphic
> > type.  If your compiler lets you do this, you should throw it out and
> get
> > a
> > new one.  The whole reason for using dynamic_cast is that you want
> > run-time
> > type casting, not compile-time type casting, so if this doesn't
compile,
> > it's probably not because the compiler figured out the actual type.
> >
> > There are lots of examples of "downcasts" in the sample code.  If you
> like
> > old-style casts (which the Xerces code uses for portability), then use
> > those:
> >
> > void
> > foo(DOM_Node  node)
> > {
> >     if (node.getNodeType() == DOM_Node::ENTITY_NODE)
> >     {
> >         DOM_Entity  ent = (DOM_Entity&)node;
> >     }
> > }
> >
> > If you prefer new-style casts, which are safer, use those:
> >
> > void
> > foo(DOM_Node  node)
> > {
> >     if (node.getNodeType() == DOM_Node::ENTITY_NODE)
> >     {
> >         DOM_Entity  ent = static_cast<const DOM_Entity&>(node);
> >     }
> > }
> >
> > Dave
> >
> >
> >
> >
> >
> >                     "Adams,
> >
> >                     David"               To:
> > "'[EMAIL PROTECTED]'" <[EMAIL PROTECTED]>
> >                     <dadae@allsta        cc:     (bcc: David N
> > Bertoni/CAM/Lotus)
> >                     te.com>              Subject:     RE: sample for
> down
> > casting DOM_Node to DOM_Entity ??
> >
> >
> >                     06/08/2001
> >
> >                     04:42 PM
> >
> >                     Please
> >
> >                     respond to
> >
> >                     xerces-c-dev
> >
> >
> >
> >
> >
> >
> >
> >
> > No it is not safe. That is the old style of casting. With that style I
> > could
> > do something like this:
> > int x = 1;
> > DOM_Node n = (DOM_Node)x; // which you know is not right.
> >
> > I suggest you use the following:
> > DOM_Entity domen = dynamic_cast<DOM_Entity>(node);
> > If it doesn't compile, it may be that the compiler is trying to tell
you
> > that 'node' may NOT be a DOM_Entity type and you are doing an illegal
> > cast.
> >
> > Regarding the blank screen, in your example, if 'node' is not a
> DOM_Entity
> > type, you could be corrupting your screen memory.
> >
> > > -----Original Message-----
> > > From:         Awasthi, Anand [SMTP:[EMAIL PROTECTED]]
> > > Sent:         Friday, June 08, 2001 3:33 PM
> > > To:           '[EMAIL PROTECTED]'
> > > Subject:           RE: sample for down casting DOM_Node to DOM_Entity
> ??
> > >
> > > thanks guys...
> > >
> > > i tried
> > >
> > > DOM_Node node;
> > > DOM_Entity domen = (DOM_Entity &)(node);
> > >
> > > its compiles...but is this safe ??
> > >
> > > later on i want to print PublicId and SystemId associated with this
> > Entity
> > > node and
> > > i coded following:
> > >
> > > cout << "public id "  << ((DOM_Entity
> &)node).getPublicId().transcode()
> > <<
> > > endl;
> > > cout << "system id "  << ((DOM_Entity
> &)node).getSystemId().transcode()
> > <<
> > > endl;
> > >
> > > but I am getting blank screen . is the above code correct or is there
> > any
> > > better
> > > implementation for obtaining PublicId and System Id value ?? pls
> suggest
> > > that.
> > >
> > > as a matter of fact when I use above DOMStrng.transcode() method to
> > obtain
> > >
> > > NOde Name ...i get Node Name. But when I try to obtain Node Value
thru
> > > getNodeValue().transcode(),
> > > I get blank screen..whats wrong ??
> > >
> > >
> > >
> > > pls enlighten me
> > >
> > >
> > > thanks
> > > anand
> > >
> > >
> > >
> > >
> > >
> > >
> > > -----Original Message-----
> > > From: Adams, David [mailto:[EMAIL PROTECTED]]
> > > Sent: Friday, June 08, 2001 3:24 PM
> > > To: '[EMAIL PROTECTED]'
> > > Subject: RE: sample for down casting DOM_Node to DOM_Entity ??
> > >
> > >
> > > Curt is correct, in that I am assuming you know that the Node is an
> > > DOM_Entity type node and was passed around your code as a DOM_Node
and
> > you
> > > simply want to get its derived type back. If you do not know what
type
> > it
> > > really is, you do have to check it. The VC++ macro "DYNAMIC_DOWNCAST"
> is
> > > another way to check if that works for you.
> > >
> > > > -----Original Message-----
> > > > From:       Adams, David [SMTP:[EMAIL PROTECTED]]
> > > > Sent:       Friday, June 08, 2001 3:16 PM
> > > > To:         '[EMAIL PROTECTED]'
> > > > Subject:         RE: sample for down casting DOM_Node to DOM_Entity
> ??
> > > >
> > > > DOM_Node n = // some node;
> > > > DOM_Entity e = dynamic_cast<DOM_Entity>(n);
> > > >
> > > > I do not know what compiler you are using, but you will need to set
> > the
> > > > /GR
> > > > switch on VC++ compilers. This is done by going to
> Project->settings,
> > > > select
> > > > the C/C++ tab, select the C++ Language category, and click on
> "Enable
> > > > Run-Time Type Information (RTTI)" to enable it.
> > > >
> > > > > -----Original Message-----
> > > > > From:          Awasthi, Anand [SMTP:[EMAIL PROTECTED]]
> > > > > Sent:          Friday, June 08, 2001 2:58 PM
> > > > > To:       '[EMAIL PROTECTED]'
> > > > > Subject:       sample for down casting DOM_Node to DOM_Entity ??
> > > > >
> > > > > Hi,
> > > > >
> > > > > could someone pls provide sample code for down casting DOM_Node
to
> > > > > DOM_Entity ??
> > > > >
> > > > > thanks
> > > > > Anand
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > >
> > > >
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to