Click here to Skip to main content
Click here to Skip to main content
Articles » Database » Database » General » Downloads
 
Add your own
alternative version

C++ Object Oriented Database Generator

, 17 Nov 1999
This project is a code generator to produce CObject-dervied data classes for Object-Oriented database management
///////////////////////////////////////////////////////////////////////////
// CTest -- Implementation for CTest object


#include "stdafx.h"
#include "Test.h"

IMPLEMENT_SERIAL(CTest, CObject, 0);
////////////////////////////////////////////////////////////
// CTestList class members


CTest* CTestList::FindEntry(COleDateTime dtDate, int nOrder, CString strLocationID)
{
	POSITION Pos = FindEntryPos(XXX);
	if (Pos == NULL) return NULL;
	return (CTest*)GetAt(Pos);
}


POSITION CJournalList::FindEntryPos(COleDateTime dtDate)
{
	POSITION Pos;
	CJournal* pJournal;
	int nCurrent, nHigh, nLow, nCompareResult, nLastCurrent = -1;
	nLow = 0;
	nHigh = GetCount();
	nCurrent = nLow + Div(nHigh - nLow, 2);

	if (nHigh <= 0) goto l_NotFound;  // no items in the list
	while (TRUE)
	{
		Pos = FindIndex(nCurrent);
		pJournal = (CJournal*)GetAt(Pos);
		nCompareResult = pJournal->Compare(dtDate);
		if (nCompareResult == 0)
		{
			return Pos;
		}
		if (nCompareResult > 0) // we are in lower half of test range
		{
			nHigh = nCurrent;
			nCurrent = nLow + Div(nHigh - nLow, 2);
		}
		else // we are in upper half of test range
		{
			nLow = nCurrent;
			nCurrent = nLow + Div(nHigh - nLow, 2);
		}
		if (nCurrent == nLastCurrent) goto l_NotFound;
		nLastCurrent = nCurrent;
	}

	l_NotFound:;

#ifdef _DEBUG
	Pos = FindEntryPosBruteForce(dtDate);
	if (Pos != NULL) TRACE("Journal searching algorithm failed
");
#endif

	return NULL;
} // end of FindEntryPos



POSITION CJournalList::FindEntryPosBruteForce(COleDateTime dtDate)
{
	CJournal* pJournal;
	POSITION Pos = GetHeadPosition();
	while (Pos)
	{
		pJournal = (CJournal*)GetNext(Pos);
		if (pJournal->Compare(dtDate) == 0)
		{
			return Pos;
		}
	}
	return NULL;
} // end of FindEntryPosBruteForce


void CTestList::AddTest(CTest* pNew)
{
	CTest* pTest;
	int nCompareResult;
	POSITION Pos;

	// need to search through list and add in the proper sorted order
	ASSERT_VALID(pNew);
	ASSERT(Find(pNew) == NULL);

	// start from end because it is more likely to be added to the end
	Pos = GetTailPosition();
	while (Pos)
	{
		pTest = (CTest*)GetAt(Pos);
		nCompareResult = pTest->Compare(pNew);
		ASSERT(nCompareResult != 0);
		if (nCompareResult == 0) return;
		if (nCompareResult == -1)
		{
			InsertAfter(Pos, pNew);
			return;
		}
		GetPrev(Pos);
	}
	AddHead(pNew);
	return;
}


void CTestList::RemoveTest(COleDateTime dtDate, int nOrder, CString strLocationID)
{
	POSITION Pos = FindEntryPos(XXX);
	if (Pos) RemoveAt(Pos);
}


void CTestList::Serialize(CArchive& ar)
{
	DWORD dwVersion = 0x00000000;
	int n, nCount;
	POSITION Pos;
	CJournal* pJournal;

	if (ar.IsStoring())
	{
		ar<<dwVersion;

		nCount = GetCount();
		ar<<nCount;
		Pos = GetHeadPosition();
		while (Pos)
		{
			pTest = (CTest*)GetNext(Pos);
			pTest->Serialize(ar);
		}
	}
	else
	{
		ar>>dwVersion;
		ASSERT(GetCount() == 0);
		ar>>nCount;
		for (n = 0; n < nCount; ++n)
		{
			pTest = new CTest();
			if (pTest == NULL)
			THROW(new CMemoryException());
			pTest->Serialize(ar);
			AddTail(pTest);
		}
	}
	CObList::Serialize(ar);
} // end of Serialize


void CTestList::ClearAndDelete()
{
	CTest* pTest;
	POSITION Pos = GetHeadPosition();
	while (Pos)
	{
		pTest = (CTest*)GetNext(Pos);
		ASSERT_VALID(pTest);
		delete pTest;
	}
	RemoveAll();
}



////////////////////////////////////////////////////////////
// CTest class members





////////////////////////////////////////////
// CTest construction/destruction 


// Construction
CTest::CTest()
{
	Clear();
	m_dtCreated = COleDateTime::GetCurrentTime();
}


// Initialization
void CTest::Clear()
{
	m_dtDate = 0.0;
	m_nOrder = 0;
	m_strLocationID = _T("");
	m_strCustomerName = _T("");
	m_dtBirthDate = 0.0;
	m_rgbColor = 0;
	m_dtCreated = 0.0;
	m_dtLastModified = 0.0;
}



// Destruction
CTest::~CTest()
{



}




////////////////////////////////////////////
// CTest Diagnostics 

#ifdef _DEBUG

void CTest::Dump(CDumpContext& dc) const
{
	dc.SetDepth(1);
	dc <<"Date = " << m_dtDate;
	dc <<"Order = " << m_nOrder;
	dc <<"LocationID = " << m_strLocationID;
	dc <<"CustomerName = " << m_strCustomerName;
	dc <<"BirthDate = " << m_dtBirthDate;
	dc <<"Color = " << m_rgbColor;
	dc <<"Created = " << m_dtCreated;
	dc <<"LastModified = " << m_dtLastModified;
}

#endif

void CTest::AssertValid() const
{
	CObject::AssertValid();
	// TODO:  Add validity checking here
}




////////////////////////////////////////////
// CTest operations 


void CTest::Serialize(CArchive& ar)
{
	DWORD dwVersion = 0x00000000;

	if (ar.IsStoring())
	{
		ar<<dwVersion;
		ar<<m_dtDate<<m_nOrder<<m_strLocationID<<m_strCustomerName<<m_dtBirthDate<<m_rgbColor<<m_dtCreated<<m_dtLastModified;


	}
	else
	{
		ar>>dwVersion;
		ar>>m_dtDate>>m_nOrder>>m_strLocationID>>m_strCustomerName>>m_dtBirthDate>>m_rgbColor>>m_dtCreated>>m_dtLastModified;


	}
	CObject::Serialize(ar);
} // end of Serialize


void CTest::Duplicate(CTest* pSource)
{
	m_dtDate = pSource->m_dtDate;
	m_nOrder = pSource->m_nOrder;
	m_strLocationID = pSource->m_strLocationID;
	m_strCustomerName = pSource->m_strCustomerName;
	m_dtBirthDate = pSource->m_dtBirthDate;
	m_rgbColor = pSource->m_rgbColor;
	m_dtCreated = pSource->m_dtCreated;
	m_dtLastModified = pSource->m_dtLastModified;
} // end of Duplicate


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

Share

About the Author

Robert Pittenger, MCPD-EAD
President Starpoint Software Inc.
United States United States
Bob Pittenger is founder and President of Starpoint Software Inc. He holds a B.A. degree from Miami University, M.S. and Ph.D. degrees from Purdue University, and an MBA from Xavier University. He has been programming since 1993, starting with Windows application development in C++/MFC and moving to C# and .NET around 2005 and is a .NET Microsoft Certified Professional Developer.
 
Bob is the author of two books:
Billionaire: How the Ultra-Rich Built Their Fortunes Through Good and Evil and What You Can Learn from Them
and
Wealthonomics: The Most Important Economic and Financial Concepts that Can Make You Rich Fast.
Visit http://www.billionairebook.net for more information.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150302.1 | Last Updated 18 Nov 1999
Article Copyright 1999 by Robert Pittenger, MCPD-EAD
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid