本文整理汇总了C++中SNode::Insert方法的典型用法代码示例。如果您正苦于以下问题:C++ SNode::Insert方法的具体用法?C++ SNode::Insert怎么用?C++ SNode::Insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SNode
的用法示例。
在下文中一共展示了SNode::Insert方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Clear
//.........这里部分代码省略.........
int temp = sortedIndices[i];
sortedIndices[i] = sortedIndices[maxGlyphIndex];
sortedIndices[maxGlyphIndex] = temp;
}
// tree
struct SNode
{
SNode* m_pChild[2];
SRect m_Rect;
int m_CharIndex;
SNode()
{
m_pChild[0] = NULL;
m_pChild[1] = NULL;
m_CharIndex = -1;
}
void Clear()
{
if (m_pChild[0] != NULL)
{
m_pChild[0]->Clear();
SAFE_DELETE(m_pChild[0]);
}
if (m_pChild[1] != NULL)
{
m_pChild[1]->Clear();
SAFE_DELETE(m_pChild[1]);
}
}
SNode* Insert(const SCharData& data)
{
if (m_pChild[0] != NULL && m_pChild[1] != NULL)
{
// try inserting into first child
SNode* pNewNode = m_pChild[0]->Insert(data);
if (pNewNode != NULL)
{
return pNewNode;
}
// no room, insert into second
return m_pChild[1]->Insert(data);
}
else
{
// if there's already a glyph here, return
if (m_CharIndex >= 0)
{
return NULL;
}
int width = m_Rect.m_Right - m_Rect.m_Left;
int height = m_Rect.m_Bottom - m_Rect.m_Top;
// if we're too small, return
if (data.m_Width > width ||
data.m_Height > height)
{
return NULL;
}
// if we're just right, accept
if (data.m_Width == width &&