Timestamper Class Extension
TimestampedFCDescription.cpp
// Copyright 2006 ESRI
// 
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
// 
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
// 
// See the use restrictions.

// TimestampedFCDescription.cpp : Implementation of CTimestampedFCDescription
#include "stdafx.h"
#include "Timestamper.h"
#include "TimestamperUtils.h"
#include "TimestampedFCDescription.h"

/////////////////////////////////////////////////////////////////////////////
// CTimestampedFCDescription
// IObjectClassDescription
STDMETHODIMP CTimestampedFCDescription::get_Name(BSTR *Name)
{
  if (!Name) return E_POINTER;

  CComBSTR str(L"Timestamped Feature Class");
  *Name = str.Detach();
  return S_OK; 
}

STDMETHODIMP CTimestampedFCDescription::get_AliasName(BSTR *Name)
{
  if (!Name) return E_POINTER;

  CComBSTR str(L"");
  *Name = str.Detach();
  return S_OK; 
}

STDMETHODIMP CTimestampedFCDescription::get_ModelName(BSTR *Name)
{
  if (!Name) return E_POINTER;

  CComBSTR str(L"");
  *Name = str.Detach();
  return S_OK; 
}

STDMETHODIMP CTimestampedFCDescription::get_ModelNameUnique(VARIANT_BOOL *IsUnique)
{
  if (!IsUnique) return E_POINTER;

  *IsUnique = VARIANT_FALSE;
  return S_OK;
}

STDMETHODIMP CTimestampedFCDescription::get_InstanceCLSID(IUID **InstanceCLSID)
{

  if (!InstanceCLSID) return E_POINTER;

  HRESULT hr;

  IUIDPtr ipClsid(CLSID_UID);

  OLECHAR str[101];
  StringFromGUID2(CLSID_Feature, str, 100);
  
  hr = ipClsid->put_Value(CComVariant(str));
  if (FAILED(hr)) return hr;

  *InstanceCLSID = ipClsid.Detach(); // pass ownership of object to client

  return S_OK;
}

STDMETHODIMP CTimestampedFCDescription::get_ClassExtensionCLSID(IUID **ClassExtensionCLSID)
{
  if (!ClassExtensionCLSID) return E_POINTER;

  HRESULT hr;

  IUIDPtr ipClsid(CLSID_UID);

  OLECHAR str[101];
  StringFromGUID2(CLSID_TimestampClassExtension, str, 100);
  
  hr = ipClsid->put_Value(CComVariant(str));
  if (FAILED(hr)) return hr;

  *ClassExtensionCLSID = ipClsid.Detach(); // pass ownership of object to client

  return S_OK;
}

STDMETHODIMP CTimestampedFCDescription::get_RequiredFields(IFields **fieldDescription)
{
  if (!fieldDescription) return E_POINTER;

  HRESULT hr;
  
  // First get the standard fields for an feature class
  IObjectClassDescriptionPtr ipOCDesc(CLSID_FeatureClassDescription);

  IFieldsPtr ipFields;
  hr = ipOCDesc->get_RequiredFields(&ipFields);
  if (FAILED(hr)) return hr;

  IFieldsEditPtr ipFieldsEdit(ipFields);

  // Now add the extra fields
  hr = AddTimestampFields(ipFieldsEdit);
  if (FAILED(hr)) return hr;

  *fieldDescription = ipFieldsEdit.Detach(); // pass ownership of object to client 
  return S_OK;
}

// IFeatureClassDescription
STDMETHODIMP CTimestampedFCDescription::get_FeatureType(esriFeatureType *FeatureType)
{
  if (!FeatureType) return E_POINTER;

  *FeatureType = esriFTSimple;
  return S_OK;

}

STDMETHODIMP CTimestampedFCDescription::get_ShapeFieldName(BSTR *Name)
{
  if (!Name) return E_POINTER;
   
  CComBSTR str(L"Shape");
  *Name = str.Detach();
  return S_OK; 
}