* @brief Some output WMEs will come to us "out of order". * That's to say, a child of an identifier appears before * the identifier (e.g. (X ^name me) before (Y ^person X)). * This function searches the list of wmes that haven't been * attached to an identifier yet and attaches them together * (if the identifier strings match). * By the end of a single out
| 388 | * @param pPossibleParent The identifier that may have orphaned children to attach. |
| 389 | *************************************************************/ |
| 390 | bool WorkingMemory::TryToAttachOrphanedChildren(Identifier* pPossibleParent) |
| 391 | { |
| 392 | if (m_OutputOrphans.empty()) |
| 393 | { |
| 394 | return false ; |
| 395 | } |
| 396 | |
| 397 | bool deleteFromList = true ; |
| 398 | WMElement* pWme = SearchWmeListForID(&m_OutputOrphans, pPossibleParent->GetValueAsString(), deleteFromList) ; |
| 399 | |
| 400 | while (pWme) |
| 401 | { |
| 402 | assert(pWme->m_ID == NULL) ; |
| 403 | assert(pWme->m_IDName.compare(pPossibleParent->GetValueAsString()) == 0) ; |
| 404 | pWme->SetSymbol(pPossibleParent->GetSymbol()); |
| 405 | pPossibleParent->AddChild(pWme) ; |
| 406 | |
| 407 | if (this->GetAgent()->GetKernel()->IsTracingCommunications()) |
| 408 | { |
| 409 | sml::PrintDebugFormat("Adding orphaned child to this ID: %s ^%s %s (time tag %d)", pWme->GetIdentifierName(), pWme->GetAttribute(), pWme->GetValueAsString(), pWme->GetTimeTag()) ; |
| 410 | } |
| 411 | |
| 412 | // If the wme being attached is itself an identifier, we have to check in turn to see if it has any orphaned children |
| 413 | if (pWme->IsIdentifier()) |
| 414 | { |
| 415 | TryToAttachOrphanedChildren(pWme->ConvertToIdentifier()) ; |
| 416 | } |
| 417 | |
| 418 | // Make a record that this wme was added so we can alert the client to this change. |
| 419 | RecordAddition(pWme) ; |
| 420 | |
| 421 | pWme = SearchWmeListForID(&m_OutputOrphans, pPossibleParent->GetValueAsString(), deleteFromList) ; |
| 422 | } |
| 423 | |
| 424 | return true ; |
| 425 | } |
| 426 | |
| 427 | /************************************************************* |
| 428 | * @brief This function is called when an output wme has been removed. |
nothing calls this directly
no test coverage detected