but what about the memory leak ( due to pointer creation with in function
body ) ??



-----Original Message-----
From: Adams, David [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, June 12, 2001 2:12 PM
To: '[EMAIL PROTECTED]'
Subject: RE: wrapping Xerces API in my code !!


Similar to how your getParentNode() method worked.

        Xml_DOM_Node Xml_DOM_Node::getFirstChild() const 
        {
                DOM_Node node  = pdomnodeimpl->domnode.getFirstChild();
                Xml_DOM_Node_Impl* p = new Xml_DOM_Node_Impl;
                p->domnode = node;

                // I didn't notice this before, but it could be a problem.
                // You're returning a stack value here. Look at 'main()'
below.
                return Xml_DOM_Node(p);

                // You might want  to do this instead:
                Xml_DOM_Node* pXmlDOMNode = new Xml_DOM_Node(p);
                return pXmlDOMNode; // change the return type on your method
declaration to return a pointer
        }

        void main(void)
        {
                .
                .
                .
                DOM_Node n; // again, some valid node
                Xml_DOM_Node_Impl* impl = new Xml_DOM_Node_Impl;
                Xml_DOM_Node xmlnode1(impl);
                
                // DISASTER. Pointer to a return stack value that no longer
exists.
                //Xml_DOM_Node* xmlnode2 = xmlnode1.getFirstChild(); 

                // This is better. Uses the assignment operator. 
                // You may need to add one to your wrapper class.
                Xml_DOM_Node xmlnode2 = xmlnode1.getFirstChild();
        }

> -----Original Message-----
> From: Awasthi, Anand [SMTP:[EMAIL PROTECTED]]
> Sent: Tuesday, June 12, 2001 1:47 PM
> To:   '[EMAIL PROTECTED]'
> Subject:      RE: wrapping Xerces API in my code !!
> 
> Hi ,
> 
> I am calling getFirstChild() method on my xml_DOM_Node() , but this method
> 
> modifies my Xml_DOM_Node but i dont want them to modify it. 
> how do i  do this ?? 
> 
>  
> 
> 
> Xml_DOM_Node Xml_DOM_Node::getFirstChild() const 
> {
>       DOM_Node node  = pdomnodeimpl->domnode.getFirstChild();
>       pdomnodeimpl->domnode = node; 
>       return Xml_DOM_Node(pdomnodeimpl);
> }
> 
> -----Original Message-----
> From: Adams, David [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, June 12, 2001 11:02 AM
> To: '[EMAIL PROTECTED]'
> Subject: RE: wrapping Xerces API in my code !!
> 
> 
> Has your DOM_Node object within your struct been initialized to a valid
> DOM
> tree node?  If not, when you call your        'DOMString
> Xml_DOM_Node::getNodeName() const' and 'Xml_DOM_Node
> Xml_DOM_Node::getParentNode() const' methods, you will get an Access
> Violation. Outside of that, I can only suggest you run it through the
> debugger and look at the variables that are getting the violation and see
> if
> they appear valid. If they aren't, trace your stack backwards and see
> where
> the failed to get set to a valid value.
> 
> p.s.
> void main(void)
> {
>       // assume this is some valid DOM_Node object
>       DOM_Node n;
>       
>       // ERROR! your destructor will try to delete this stack variable. Be
> careful here.
>       //Xml_DOM_Node_Impl impl;
>       //impl.domnode = n;
>       //Xml_DOM_Node xml_domnode(&impl);
> 
>       // use this instead
>       Xml_DOM_Node_Impl* impl = new Xml_DOM_Node_Impl;
>       impl->domnode = n;
>       Xml_DOM_Node xml_domnode(impl);
>       DOMString domstring = xml_domnode.getNodeName();
> }
> 
> > -----Original Message-----
> > From:       Awasthi, Anand [SMTP:[EMAIL PROTECTED]]
> > Sent:       Tuesday, June 12, 2001 10:22 AM
> > To: '[EMAIL PROTECTED]'
> > Subject:    RE: wrapping Xerces API in my code !!
> > 
> > thanks for quick repsonse Adams.
> > 
> > Answer to your queries:
> > 
> > 1. I dont want my clients to know about third party classes like
> DOM_Node
> > when they construct Xml_DOM_Node. thats why i
> > hidden them beneath my struct Xml_DOM_Node_Impl 
> > 
> > 2. and since i am constrcuting  like Xml_DOM_Node(Xml_DOM_Node_Impl*) 
> > i cant pass DOM_Node in constructor.
> > 
> > 
> > 
> > this code complies but I am getting Access violation all the time when i
> > run
> > this code.
> > could you pls tell how to debug access violations ?? 
> > 
> > 
> > thanks a lot
> > Anand
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > -----Original Message-----
> > From: Adams, David [mailto:[EMAIL PROTECTED]]
> > Sent: Tuesday, June 12, 2001 10:09 AM
> > To: '[EMAIL PROTECTED]'
> > Subject: RE: wrapping Xerces API in my code !!
> > 
> > 
> > It compiles and it does run, but I don't understand what you are trying
> to
> > do in a couple of spots. 
> > 
> > 1) unless you are deliberately trying to hide DOM_Node in that struct,
> or
> > unless you deliberately left some additional stuff out of that struct
> for
> > the sake of simplifying your email, I don't see why you don't just put
> the
> > 'DOM_Node' directly in your class. You have a class that wraps a struct
> > that
> > wraps a DOM_Node. Why not just have a class that wraps DOM_Node ?
> > 
> >     class Xml_DOM_Node 
> >     {
> >     public: 
> >             Xml_DOM_Node(DOM_Node); // Xerces Referencing counting makes
> > this essentially the same as 'DOM_Node&'
> >             ~Xml_DOM_Node();        
> >             DOMString getNodeName() const;  
> >             Xml_DOM_Node getParentNode() const;
> >     private:
> >         DOM_Node domnode; 
> >     };
> > 
> > 2) I don't understand why you are reassiging your DOM_Node value in this
> > routine, but I don't know what you attend to do with your application.
> You
> > will be pointing your wrapper class to some other node on the tree;
> maybe
> > that's what you intended.
> >     Xml_DOM_Node Xml_DOM_Node::getParentNode() const 
> >     {
> >      DOM_Node node =
> >     pdomnodeimpl->domnode.getParentNode();
> >      pdomnodeimpl->domnode = node; 
> >      return Xml_DOM_Node(pdomnodeimpl);
> >     }
> > 
> >     /*
> >     // could this be what you really wanted?
> >     Xml_DOM_Node Xml_DOM_Node::getParentNode() const 
> >     {
> >      DOM_Node node =
> >     pdomnodeimpl->domnode.getParentNode();
> >      return Xml_DOM_Node(node);
> >     }
> >     */
> > 
> > 
> > > -----Original Message-----
> > > From:     anand awasthi [SMTP:[EMAIL PROTECTED]]
> > > Sent:     Tuesday, June 12, 2001 9:28 AM
> > > To:       [EMAIL PROTECTED]
> > > Subject:  wrapping Xerces API in my code !!
> > > 
> > > Hi,
> > > 
> > > I am trying to wrap Xerces API in my code in following
> > > manner :
> > > 
> > > 
> > > oni.h 
> > > ----------
> > > 
> > > struct Xml_DOM_Node_Impl;
> > > struct Xml_DOM_Node_Impl
> > > {
> > >     DOM_Node domnode;
> > > };
> > > 
> > > class Xml_DOM_Node 
> > > {
> > > public:   
> > >   Xml_DOM_Node(Xml_DOM_Node_Impl*);       
> > >   ~Xml_DOM_Node();        
> > >   DOMString getNodeName() const;  
> > >   Xml_DOM_Node getParentNode() const;
> > > private:
> > >     Xml_DOM_Node_Impl* pdomnodeimpl; 
> > > };
> > > 
> > > 
> > > -------------------------------------------
> > > 
> > > oni.cpp
> > > ---------
> > > 
> > > #include "oni.h"
> > > #include <xercesheaders>
> > > 
> > > 
> > > Xml_DOM_Node::Xml_DOM_Node(Xml_DOM_Node_Impl* impl) :
> > > pdomnodeimpl(impl)
> > > {
> > > }
> > > 
> > > DOMString Xml_DOM_Node::getNodeName() const 
> > > {
> > >  return (pdomnodeimpl->domnode.getNodeName());
> > > }
> > > 
> > > Xml_DOM_Node Xml_DOM_Node::getParentNode() const 
> > > {
> > >  DOM_Node node =
> > > pdomnodeimpl->domnode.getParentNode();
> > >  pdomnodeimpl->domnode = node; 
> > >  return Xml_DOM_Node(pdomnodeimpl);
> > > }
> > > 
> > > Xml_DOM_Node::~Xml_DOM_Node()
> > > {
> > > delete pdomnodeimpl;
> > > }
> > > 
> > > could C++/Xerces gurus pls tell me that above code is
> > > correct or not ?? if notr then pls suggest me better
> > > ways.
> > > 
> > > i would really appreciate that.
> > > 
> > > thanks
> > > 
> > > __________________________________________________
> > > Do You Yahoo!?
> > > Get personalized email addresses from Yahoo! Mail - only $35 
> > > a year!  http://personal.mail.yahoo.com/
> > > 
> > > ---------------------------------------------------------------------
> > > 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