VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "QueryMaster"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
' Class for query processing
Option Explicit

Private database_ As InfoDatabase
Private outLinks_ As Excel.Worksheet
Private outLaws_ As Excel.Worksheet
Private nLaw_ As Long
Private nLink_ As Long

Private Sub Class_Initialize()
  Set outLinks_ = ThisWorkbook.Sheets(SHT_OUT_LINKS)
  Set outLaws_ = ThisWorkbook.Sheets(SHT_OUT_DOCS)
  nLink_ = WorksheetFunction.CountA(outLinks_.Columns(1)) + 1
  nLaw_ = WorksheetFunction.CountA(outLaws_.Columns(1)) + 1
End Sub

Public Function Init(db As InfoDatabase)
  Set database_ = db
End Function

' template aFilter
' !requires function CheckLaw(IteratorLaw) -> Boolean
Public Function QueryLaws(aFilter As Object)
  Dim docIter As IteratorLaw: Set docIter = database_.Laws
  Do While Not docIter.IsDone
    If aFilter.CheckLaw(docIter) Then
      Call OutputLaw(docIter)
    End If
    Call docIter.Increment
  Loop
End Function

' template aFilter
' !requires function CheckLink(IteratorLinkAll) -> Boolean
Public Function QueryLinks(aFilter As Object)
  Dim lnkIter As IteratorLinkAll: Set lnkIter = database_.Links
  Do While Not lnkIter.IsDone
    If aFilter.CheckLink(lnkIter) Then
      Call OutputLink(lnkIter)
    End If
    Call lnkIter.Increment
  Loop
End Function

' ===============
Private Function OutputLaw(target As IteratorLaw)
  outLaws_.Cells(nLaw_, S_QD_ID) = target.ID
  outLaws_.Cells(nLaw_, S_QD_TYPE) = target.DType
  outLaws_.Cells(nLaw_, S_QD_TITLE) = target.Title
  outLaws_.Cells(nLaw_, S_QD_TYPE_TXT) = target.TypeText
  outLaws_.Cells(nLaw_, S_QD_CREATOR) = target.Creator
  outLaws_.Cells(nLaw_, S_QD_DATE) = target.CreationDate
  outLaws_.Cells(nLaw_, S_QD_NUMBER) = target.Number
  outLaws_.Cells(nLaw_, S_QD_HEADER) = target.Header
  outLaws_.Cells(nLaw_, S_QD_ATTACH) = target.Attachment
  outLaws_.Cells(nLaw_, S_QD_TIME_SCOPED) = IIf(target.IsScoped, 1, 0)
  nLaw_ = nLaw_ + 1
End Function

Private Function OutputLink(target As IteratorLinkAll)
  outLinks_.Cells(nLink_, S_QL_SOURCE_ID) = target.SourceID
  outLinks_.Cells(nLink_, S_QL_SOURCE_SUB) = target.SourceSub
  outLinks_.Cells(nLink_, S_QL_TARGET_ID) = target.DestinationID
  outLinks_.Cells(nLink_, S_QL_TARGET_SUB) = target.DestinationSub
  outLinks_.Cells(nLink_, S_QL_TYPE) = target.LType
  nLink_ = nLink_ + 1
End Function
