VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "QFilterLinkComplex"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Private laws_ As Scripting.Dictionary
Private linkType_ As TQueryLink
Private linkDir_ As TLinkDirection
Private onlyInternal_ As Boolean

Public Function Init(iLaws As Scripting.Dictionary, theType As TQueryLink, linkDir As TLinkDirection, onlyInternal As Boolean)
  Set laws_ = iLaws
  linkType_ = theType
  linkDir_ = linkDir
  onlyInternal_ = onlyInternal
End Function

Public Function CheckLink(aLink As IteratorLinkAll) As Boolean
  CheckLink = False
  If Not CheckType(aLink.LType) Then _
    Exit Function
    
  Dim isSource As Boolean: isSource = laws_.Exists(aLink.SourceID)
  Dim isDestination As Boolean: isDestination = laws_.Exists(aLink.DestinationID)
  If onlyInternal_ Then _
    If Not isSource Or Not isDestination Then _
      Exit Function
      
  Select Case linkDir_
    Case T_LD_STRAIGHT: CheckLink = isSource
    Case T_LD_REVERSE: CheckLink = isDestination
    Case T_LD_BOTH:
      CheckLink = isSource Or isDestination
  End Select
End Function

' =======
Private Function CheckType(LType As TLinkType) As Boolean
  Select Case linkType_
    Case T_QL_ALL: CheckType = True
    Case T_QL_ASPECT: CheckType = LType = T_LINK_ASPECT
    Case T_QL_DEFINITION: CheckType = LType = T_LINK_DEFINITION
    Case T_QL_FOUND: CheckType = LType = T_LINK_FOUNDATION
  End Select
End Function

