SIMPDATA.CPP

//+----------------------------------------------------------------------- 
//
// Simple Tabular Data Object
// Copyright (C) Microsoft Corporation, 1996, 1997
//
// File: SimpData.cpp
//
// Contents: Implementation of the CSimpleTabularData COM object.
//
//------------------------------------------------------------------------

#include "stdafx.h"
#include "STD.h"
#include "TDC.h"
#include <MLang.h>
#include "Notify.h"
#include "TDCParse.h"
#include "TDCArr.h"
#include "SimpData.h"
#include "TDCIds.h"


//------------------------------------------------------------------------
//
// Method: CSimpleTabularData() - Constructor
//
// Synopsis: Clears internal data. Due to the COM model, the
// member function "Create" should be called to actually
// initialize the STD data structures.
//------------------------------------------------------------------------

CSimpleTabularData::CSimpleTabularData() : m_cRef(1), m_pTDCArr(NULL)
{
}

//------------------------------------------------------------------------
//
// Method: Create()
//
// Synopsis: Initializes STD.
// This method should be called after an STD object is contructed
// to initialize it.
//
// Arguments: pTDCArr Pointer to the TDCArr object containing the
// data for this control.
//
// Returns: Nothing.
//
//------------------------------------------------------------------------

void
CSimpleTabularData::Create(CTDCArr *pTDCArr)
{
m_pTDCArr = pTDCArr;
if (m_pTDCArr != NULL)
m_pTDCArr->AddRef();
}


//------------------------------------------------------------------------
//
// Method: ~CSimpleTabularData()
//
// Synopsis: Destructor
//
//------------------------------------------------------------------------

CSimpleTabularData::~CSimpleTabularData()
{
if (m_pTDCArr != NULL)
m_pTDCArr->Release();
}


//------------------------------------------------------------------------
//
// Method: Invalidate()
//
// Synopsis: Marks the current interface as invalid. References to
// the TDCArr object are released. Subsequent calls to the
// SimpleTabularData interface will return the code E_INVALID.
//
// Arguments: None.
//
// Returns: S_OK to indicate success.
//
//------------------------------------------------------------------------

STDMETHODIMP
CSimpleTabularData::Invalidate()
{
if (m_pTDCArr != NULL)
{
m_pTDCArr->Release();
m_pTDCArr = NULL;
}
return S_OK;
}


//////////////////////////////////////////////////////////////////////////
//
// Implementation of IUnknown COM interface.
// -----------------------------------------
//
//////////////////////////////////////////////////////////////////////////

//+-----------------------------------------------------------------------
//
// Method: QueryInterface()
//
// Synopsis: Implements part of the standard IUnknown COM interface.
// (Returns a pointer to this COM object)
//
// Arguments: riid GUID to recognise
// ppv Pointer to this COM object [OUT]
//
// Returns: S_OK upon success.
// E_NOINTERFACE if queried for an unrecognised interface.
//
//+-----------------------------------------------------------------------

STDMETHODIMP
CSimpleTabularData::QueryInterface (REFIID riid, LPVOID * ppv)
{
HRESULT hr;

_ASSERTE(ppv != NULL);

// This is the non-delegating IUnknown implementation
if (riid == IID_IUnknown || riid == IID_OLEDBSimpleProvider)
{
*ppv = this;
((LPUNKNOWN)*ppv)->AddRef();
hr = S_OK;
}
else
{
*ppv = NULL;
hr = E_NOINTERFACE;
}

#ifdef _ATL_DEBUG_QI
AtlDumpIID(riid, _T("CSimpleTabularData"), hr);
#endif
return hr;
}


//+-----------------------------------------------------------------------
//
// Method: AddRef()
//
// Synopsis: Implements part of the standard IUnknown COM interface.
// (Adds a reference to this COM object)
//
// Arguments: None
//
// Returns: Number of references to this COM object.
//
//+-----------------------------------------------------------------------

STDMETHODIMP_(ULONG)
CSimpleTabularData::AddRef ()
{
return ++m_cRef;
}


//+-----------------------------------------------------------------------
//
// Method: Release()
//
// Synopsis: Implements part of the standard IUnknown COM interface.
// (Removes a reference to this COM object)
//
// Arguments: None
//
// Returns: Number of remaining references to this COM object.
// 0 if the COM object is no longer referenced.
//
//+-----------------------------------------------------------------------

STDMETHODIMP_(ULONG)
CSimpleTabularData::Release ()
{
ULONG retval;

m_cRef -= 1;
retval = m_cRef;
if (!m_cRef)
{
m_cRef = 0xffff; //MM: Use this 'flag' for debug?
delete this;
}
return retval;
}