📄 sortedchain.cpp
字号:
//===========================================================================//
// File: vchain.cc //
// Contents: Implementation details of SortedChain class //
//---------------------------------------------------------------------------//
// Copyright (C) Microsoft Corporation. All rights reserved. //
//===========================================================================//
#include "StuffHeaders.hpp"
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SortedChainLink ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###########################################################################
// SortedChainLink
//###########################################################################
//
SortedChainLink::SortedChainLink(
SortedChain *vchain,
Plug *plug
):
Link(vchain, plug)
{
next = NULL;
prev = NULL;
}
//
//###########################################################################
// ~SortedChainLink
//###########################################################################
//
SortedChainLink::~SortedChainLink()
{
Check_Object(this);
SortedChain *vchain = Cast_Object(SortedChain*, socket);
//
//-------------------------------------------
// Notify iterators that deletion is occuring
//-------------------------------------------
//
vchain->SendIteratorMemo(PlugRemoved, this);
//
//---------------------------
// Remove from existing links
//---------------------------
//
if (prev != NULL)
{
Check_Object(prev);
prev->next = next;
}
else
{
Check_Object(vchain);
vchain->head = next;
}
if (next != NULL)
{
Check_Object(next);
next->prev = prev;
}
else
{
Check_Object(vchain);
vchain->tail = prev;
}
prev = next = NULL;
//
//------------------------------------------
// Remove this link from any plug references
//------------------------------------------
//
ReleaseFromPlug();
//
//-------------------------------------------------------------
// Tell the node to release this link. Note that this link
// is not referenced by the plug or the chain at this point in
// time.
//-------------------------------------------------------------
//
if (vchain->GetReleaseNode() != NULL)
{
Check_Object(vchain->GetReleaseNode());
vchain->GetReleaseNode()->ReleaseLinkHandler(vchain, plug);
}
}
//
//###########################################################################
// TestInstance
//###########################################################################
//
void
SortedChainLink::TestInstance()
{
Link::TestInstance();
if (next != NULL)
{
Check_Signature(next);
}
if (prev != NULL)
{
Check_Signature(prev);
}
}
//
//###########################################################################
// SetupSortedChainLinks
//###########################################################################
//
void
SortedChainLink::SetupSortedChainLinks(
SortedChainLink *next,
SortedChainLink *prev
)
{
Check_Object(this);
this->next = next;
this->prev = prev;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SortedChain ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###########################################################################
// SortedChain
//###########################################################################
//
SortedChain::SortedChain(
Node *node,
bool has_unique_entries
):
SortedSocket(node, has_unique_entries)
{
head = NULL;
tail = NULL;
}
//
//###########################################################################
// ~SortedChain
//###########################################################################
//
SortedChain::~SortedChain()
{
Check_Object(this);
SetReleaseNode(NULL);
SortedChainLink *link = head;
while (link)
{
Check_Object(link);
SortedChainLink *next = link->next;
Unregister_Object(link);
delete link;
link = next;
}
}
//
//###########################################################################
// TestInstance
//###########################################################################
//
void
SortedChain::TestInstance()
{
SortedSocket::TestInstance();
if (head != NULL)
{
Check_Object(head);
}
if (tail != NULL)
{
Check_Object(tail);
}
}
//
//###########################################################################
// MakeSortedChainLink
//###########################################################################
//
SortedChainLink
*SortedChain::MakeSortedChainLink(
Plug*,
const void*
)
{
Check_Object(this);
STOP(("SortedChain::MakeSortedChainLink - Should never reach here"));
return NULL;
}
//
//###########################################################################
// CompareSortedChainLinks
//###########################################################################
//
int
SortedChain::CompareSortedChainLinks(
SortedChainLink*,
SortedChainLink*
)
{
Check_Object(this);
STOP(("SortedChain::CompareSortedChainLinks - Should never reach here"));
return 0;
}
//
//###########################################################################
// CompareValueToSortedChainLink
//###########################################################################
//
int
SortedChain::CompareValueToSortedChainLink(
const void*,
SortedChainLink*
)
{
Check_Object(this);
STOP(("SortedChain::CompareValueToSortedChainLink - Should never reach here"));
return 0;
}
//
//###########################################################################
// AddImplementation
//###########################################################################
//
void
SortedChain::AddImplementation(
Plug *plug
)
{
Check_Object(this);
STOP(("Must use AddValue call"));
// AddValueImplementation(plug, NULL);
}
//
//###########################################################################
// AddValueImplementation
//###########################################################################
//
void
SortedChain::AddValueImplementation(
Plug *plug,
const void *value
)
{
Check_Object(this);
SortedChainLink *link;
//
//-------------------------------------------------------------
// Verify that value has not been added
//-------------------------------------------------------------
//
Verify(HasUniqueEntries() ? (SearchForValue(value) == NULL) : (bool)true);
//
//-------------------------------------------------------------
// Make new vchain link
//-------------------------------------------------------------
//
link = MakeSortedChainLink(plug, value);
Register_Object(link);
//
//-------------------------------------------------------------
// Find insertion point for the new link
//-------------------------------------------------------------
//
if (head == NULL)
{
link->SetupSortedChainLinks(NULL, NULL);
head = link;
tail = link;
}
else
{
SortedChainLink *greater_link;
Check_Object(head);
Check_Object(tail);
for (
greater_link = head;
greater_link != NULL;
greater_link = greater_link->next
)
{
Check_Object(greater_link);
if (CompareValueToSortedChainLink(value, greater_link) < 0)
break;
}
if (greater_link == NULL)
{
//
// Add after tail
//
link->SetupSortedChainLinks(NULL, tail);
tail->next = link;
tail = link;
}
else if (greater_link == head)
{
//
// Add before head
//
link->SetupSortedChainLinks(head, NULL);
head->prev = link;
head = link;
}
else
{
//
// Add before greater_link
//
link->SetupSortedChainLinks(greater_link, greater_link->prev);
greater_link->prev->next = link;
greater_link->prev = link;
}
}
SendIteratorMemo(PlugAdded, link);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -