Click here to Skip to main content
15,886,030 members
Articles / Programming Languages / XML

XMLFoundation

Rate me:
Please Sign up or sign in to vote.
4.82/5 (12 votes)
2 Jul 20029 min read 75.2K   1.4K   34  
Obtaining data marked up in XML creates the need for Application Layer tools to easily and efficiently work with XML data.
// --------------------------------------------------------------------------
//					www.UnitedBusinessTechnologies.com
//			  Copyright (c) 1998 - 2002  All Rights Reserved.
//
// Source in this file is released to the public under the following license:
// --------------------------------------------------------------------------
// This toolkit may be used free of charge for any purpose including corporate
// and academic use.  For profit, and Non-Profit uses are permitted.
//
// This source code and any work derived from this source code must retain 
// this copyright at the top of each source file.
// 
// UBT welcomes any suggestions, improvements or new platform ports.
// email to: XMLFoundation@UnitedBusinessTechnologies.com
// --------------------------------------------------------------------------
#ifndef __OBJ_RESULT_H__
#define __OBJ_RESULT_H__

#include "GList.h"

template <class TYPE> class ObjQuery;

// Private inheritance
template <class TYPE> class ObjResultSet : private GListIterator
{
	// Our only friend, has the power to create an instance of ObjResultSet
	// Our constructor is private, our friend will create this on the heap.
	friend class ObjQuery<TYPE>;
	
	// Count of TYPE objects, this iterator has returned
	int m_nReturned;  

	// The m_pCreatorQuery that generated the results we are iterating
	ObjQuery<TYPE> *m_pCreatorQuery;

	// Private destructor for reassurance of our trusted friend creator
	~ObjResultSet()	{	}

	// 'ctor for ObjQuery.  Our mutual friend.
	ObjResultSet( ObjQuery<TYPE>* s ) :
		GListIterator( s ) 
	{ 
		m_nReturned = 0;
		m_pCreatorQuery = s;
	}

	// Automatically issued by the ObjQuery when the scope of existence has 
	// been reached. All objects end here in destruction() unless a 
	// call to freedom() or AddRef() has been requested before scope is met.
	void destruction()
	{
		GListIterator innerResults( m_pCreatorQuery );
		while (innerResults())
			((TYPE *)innerResults++)->DecRef();
	}

public:
	// Get rid of the resultset container, but keep the objects
	void freedom()
	{
		// write in the memory of our creator that we have been freed.
		m_pCreatorQuery->m_bHasBeenFreed = true;

		// With trust in our creator, destruction is not fatal because
		// we know we're on the heap. freedom() releases us from our 
		// own cleanup responsibility, and we bypass the second and 
		// final destruction() in ~ObjQuery.
		delete this;
	}

	bool hasMoreToFetch()
	{
		 return m_pCreatorQuery->hasMoreUnfetchedResults();
	}

	// Sets the number of objects that should be retrieved per WAN call.
	// Any value < 0, causes next() to return NULL when it has reached
	// the end of the current block of objects.
	void setNextBulkFetchCount( int nValue )
	{
		m_pCreatorQuery->SetReturnRowCount ( nValue );
	}

	// Get the next object out of the result set.  Every Nth call to
	// next() will cause a WAN call back to the database. 
	TYPE*	next()
	{
		// if we need to fetch the next chunk, do so before calling 
		// the base class operator ()
		TYPE *pRet = 0;
		if ( ( m_pCreatorQuery->IsUsingChunkFetching())			&&
			 ( m_nReturned % m_pCreatorQuery->GetRowCount() == 0 ) &&  
			 ( m_nReturned > 0 )
		   ) 
			 
		{
			// fetch the next chunk of data from the database
			m_pCreatorQuery->Execute();
		}
		if ( GListIterator::operator()() )
		{
			pRet = (TYPE *)GListIterator::operator++(0);
		}
		m_nReturned++;
		return pRet;
	}
};

#endif //__OBJ_RESULT_H__

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Founder United Business Technologies
United States United States
http://about.me/brian.aberle
https://www.linkedin.com/in/brianaberle
http://SyrianRue.org/Brian

Comments and Discussions