Relevant header definitions are as:

class XMLChain
		Segment root;
		std::vector<XMLOpen*> chain;
		Segment * immediate;
		std::vector<XMLOpen> openers;

The function in question is:

void XMLChain::open(std::string tag)
	Segment * last_immediate = immediate;
	openers.push_back( XMLOpen ( tag ) );
	XMLOpen * cast_immediate = &(openers.back());
	(*last_immediate).setNext( cast_immediate );
	immediate = cast_immediate;

Considerations are:

- XMLOpen is a subclass of Segment

My problem is:

Calling XMLChain::open one time has the desired effect; that is;

- the 'immediate' pointer is derived (which references the last Segment of any type to be created into an XMLChain).
- an XMLOpen segment is created and placed to the back of the 'openers' vector.
- the address of the backend of the openers vector is sent to the reference of the immediate pointer via 'setNext()'; this means that the last Segment sees the new XMLOpen Segment as the 'next' part of its output sequence.
- a pointer to the new XMLOpen address replaces the immediate pointer; for next time

However. Calling XMLChain::open again causes the last XMLOpen Segment to be treated as if it were an unextended Segment when I check the output (Segments are like a linked list, with each subclass having a specialized constructor and std::string output() function). The same happens on the next and subsequent attempts to call XMLChain::open; that is, the 'root' Segment has a line of Segments down to the last added Segment subclass, which is treated as if it were the correct Segment subclass.


10 Years
Discussion Span
Last Post by MattEvans

Hm, I should add my test cases:

The first test is a manual setup without holding any information about the chain sequence:

Segment root;
XMLOpen o("hello");
XMLOpen o2("goodbye");

This gives the output below:

This (0xbffff4a0)[Must be overriden] takes next(0xbffff480)[<hello >]
This (0xbffff480)[<hello >] takes next(0xbffff450)[<goodbye >]
Must be overriden<hello ><goodbye >

Blue parts are debugging information from the getNext() function; the red line is the actual output. 'Must be overidden' is the standard output from a Segment.

This is the test using the XMLChain (which is neccessary)

XMLChain chain;

This (0xbffff420)[Must be overriden] takes next(0x804f510)[<hello >]
This (0x804f510)[Must be overriden] takes next(0x804f704)[<goodbye >]
Must be overridenMust be overriden<goodbye >

Round brackets are memory addresses, square brackets are the Segment's current contents.



I noticed my copy constructor for XMLOpen was being called quite regularly; I hadn't used any reserve() value in the 'openers' vector.

My copy constructor deliberately anulls the pointer to the 'next' item in each Segment.. so somehow avoiding uncontrolled copying of the XMLOpen segments fixes the problem.

That needs looking into definately... But at least I'm not staring blankly at the screen wondering what's going on..

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.