
#ifdef __NT__

#include "pdblocal.hpp"

// ---------------------------------------------------------------------------
template <typename T>
struct dia_ptr_t
{
  dia_ptr_t() : thing(NULL) {}

  ~dia_ptr_t()
  {
    if ( thing != NULL )
      thing->Release();
  }

  T *thing;
};

// ---------------------------------------------------------------------------
HRESULT local_pdb_access_t::do_iterate_children(pdb_sym_t &sym,
                                                enum SymTagEnum type,
                                                children_visitor_t &visitor)
{
  dia_ptr_t<IDiaEnumSymbols> pEnumSymbols;
  HRESULT hr = dia_session->findChildren(sym.data, type, NULL, nsNone, &pEnumSymbols.thing);
  if ( hr == S_OK )
  {
    while ( true )
    {
      ULONG celt = 0;
      IDiaSymbol *pChild;
      hr = pEnumSymbols.thing->Next(1, &pChild, &celt);
      if ( FAILED(hr) || celt != 1 )
      {
        hr = S_OK; // end of enumeration
        break;
      }
      pdb_sym_t child(*this, pChild, true);
      hr = visitor.visit_child(child);
      if ( FAILED(hr) )
        break;
    }
  }
  return hr;
}

// ---------------------------------------------------------------------------
HRESULT local_pdb_access_t::load(pdb_sym_t &sym, DWORD id)
{
  IDiaSymbol *dia_sym;
  HRESULT hr = dia_session->symbolById(id, &dia_sym);
  if ( hr == S_OK )
    sym.set_symbol(dia_sym, true);
  return hr;
}



#endif


