Hi Crystal,

NodeRefList does _not_ do a deep copy, since it's a list of "references" or
pointers to XalanNode instances.  Believe me, you do not want a deep copy
-- the expense would be enormous.

DOM_NodeList works because the Xerces DOM is reference-counted, so the
DOM_Node instances, which are smart-pointers, are copied and the references
counts are maintained.

The XalanDOM is _not_ reference-counted for performance reasons.  You need
to make sure that the XalanDocument instance you're using is in scope the
entire time you want to reference nodes from it.  You may want to make it a
member of your class, depending on the overall flow of data in your system.

By the way this constructor parameter:

             My_Class (const NodeRefList theSource) {

really ought to be:

             My_Class (const NodeRefList& theSource) {

There's no need for this parameter to be passed by value.

Dave



|---------+--------------------------->
|         |           "Shang, Crystal"|
|         |           <Cshang@rsasecur|
|         |           ity.com>        |
|         |                           |
|         |           04/17/2002 10:47|
|         |           AM              |
|         |           Please respond  |
|         |           to xalan-dev    |
|         |                           |
|---------+--------------------------->
  
>---------------------------------------------------------------------------------------------------------------------------|
  |                                                                                    
                                       |
  |        To:      [EMAIL PROTECTED]                                           
                                       |
  |        cc:      "Huynh, Dung" <[EMAIL PROTECTED]>, (bcc: David N 
Bertoni/Cambridge/IBM)                                |
  |        Subject: NodeRefList& operator=                                             
                                       |
  
>---------------------------------------------------------------------------------------------------------------------------|



Hi,

The following code crashes on my system. Note if I do the same operation in
the My_Class constructor ( ... xNode->getNodeType() ), everything is fine.
Looks like the copy constructor is not doing a "deep" copy? We're doing the
same thing on DOM_NodeList as well, seems everything works fine. Can you
let
me know if I'm implementing in the right way? Thanks!

class My_Class {
public:
             My_Class (const NodeRefList theSource) {
                         ...
                         nodeList = theSource;

                         /* check the nodeList.getLength() > 0 */
                         XalanNode *xNode = nodeList.item(0);
                         xNode->getNodeType();
 <----- everything is
fine here

             }

             ~My_Class ();

             My_Function() {
                         ...
                         /* check the nodeList.getLength() > 0 */
                         XalanNode *xNode = nodeList.item(0);
                         xNode->getNodeType();
 <----- crashes here
             }

private:
             NodeRefList nodeList;
};

- Crystal






Reply via email to