HRESULT CLR_RT_HeapBlock_Queue::Clear()
{
    NATIVE_PROFILE_CLR_CORE();
    TINYCLR_HEADER();

    CLR_RT_HeapBlock_Array* array = GetArray();
    CLR_INT32               size  = GetSize();
    CLR_INT32               head  =    Head();
    CLR_INT32               tail  = GetTail();

    if(size > 0)
    {
        if(head < tail)
        {
            TINYCLR_CHECK_HRESULT(array->ClearElements( head, size ));
        }
        else
        {
            TINYCLR_CHECK_HRESULT(array->ClearElements( head, array->m_numOfElements - head ));
            TINYCLR_CHECK_HRESULT(array->ClearElements( 0   , tail                          ));
        }
        
        SetSize( 0 );
    }

    SetHead( 0 );
    SetTail( 0 );

    TINYCLR_NOCLEANUP();
}
Ejemplo n.º 2
0
// 将结点插入链表
void CDoubleLinkerInfo::insert(CDoubleLinker* pNode)
{
    if (pNode == NULL) {
        return;
    }

    // 没有Next和Prev的节点才能插入链表(无效节点),防止重复插入
    if (pNode->GetNext() != NULL || pNode->GetPrev() != NULL) {
        return;
    }

    if (mpEnd != NULL) {
        // 有数据,则直接将数据插入尾部,并设为尾指针
        mpEnd->SetNext(pNode);
        pNode->SetPrev(mpEnd);
        pNode->SetNext(NULL);
        SetEnd(pNode);
    } else {
        // 尾指针没数据,那么头指针也肯定没数据
        SetHead(pNode);
        SetEnd(pNode);
        pNode->Clear();
    }

    miCnt++;
}
Ejemplo n.º 3
0
void CMyListCtrl::InitList(CString csParams, int nCount)
{
  DeleteAllColumns();
  SetExtendedStyle(GetExtendedStyle()
                    |LVS_EX_GRIDLINES
                    |LVS_EX_FULLROWSELECT
                    |LVS_EX_SUBITEMIMAGES);
  SetParamCount(nCount);
  SetHead(csParams);
  AutoSize();
}
Ejemplo n.º 4
0
// 从链表中删除该结点
// 这个函数应该是不安全的,但为了效率,所以这样处理
// 如果该node不是这个链表中的元素,这里也会处理,当该元素是其他链表的中间元素,则不会出任何问题
// 如果该node不是其他链表的中间元素,那么那个链表将被破坏,而且下面会崩溃,因为prev或next其中一个肯定为空
// 所以在外层使用的是有一定得注意
int CDoubleLinkerInfo::erase(CDoubleLinker* pNode)
{
    int iRet = -1;

    if (pNode == NULL) {
        return iRet;
    }

    if (pNode == mpHead && pNode == mpEnd) {
        // 只有一个元素
        Clear();
        iRet = 0;
    } else if (pNode == mpHead) {
        // 头指针
        if (pNode->GetNext() == NULL) {
            return -1;
        }

        pNode->GetNext()->SetPrev(NULL);
        SetHead(pNode->GetNext());
        iRet = 1;
    } else if (pNode == mpEnd) {
        // 尾指针
        if (pNode->GetPrev() == NULL) {
            return -1;
        }

        pNode->GetPrev()->SetNext(NULL);
        SetEnd(pNode->GetPrev());
        iRet = 2;
    } else {
        // 有Next和Prev的节点才能从链表中删除(有效节点)
        if (pNode->GetNext() == NULL || pNode->GetPrev() == NULL) {
            return -1;
        }

        // 在链表中间
        pNode->GetPrev()->SetNext(pNode->GetNext());
        pNode->GetNext()->SetPrev(pNode->GetPrev());
        iRet = 3;
    }

    if (miCnt > 0) {
        miCnt--;
    }

    pNode->Clear();

    return iRet;
}
Ejemplo n.º 5
0
Character::Character(std::string name, std::string lastname, std::string race, std::string gender, 
                     std::string face, std::string skin, std::string zone, int level, int hp, 
                     int maxHp, int bp, int maxBp, int mp, int maxMp, int ep, int maxEp, 
                     int strength, int constitution, int intelligence, int dexterity, float x, 
                     float y, float z, float pitch, float yaw) {
    SetName(name);
    SetLastname(lastname);
    SetRace(race);
    SetGender(gender);
    SetFace(face);
    SetSkin(skin);
    SetZone(zone);
    SetHead("head");
    SetChest("chest");
    SetArms("arms");
    SetHands("hands");
    SetLegs("legs");
    SetFeet("feet");
    SetCloak("cloak");
    SetNecklace("necklace");
    SetRingOne("ringOne");
    SetRingTwo("ringTwo");
    SetRightHand("rightHand");
    SetLeftHand("leftHand");
    SetLevel(level);
    SetHp(hp);
    SetMaxHp(maxHp);
    SetBp(bp);
    SetMaxBp(maxBp);
    SetMp(mp);
    SetMaxMp(maxMp);
    SetEp(ep);
    SetMaxEp(maxEp);
    SetStrength(strength);
    SetConstitution(constitution);
    SetIntelligence(intelligence);
    SetDexterity(dexterity);
    SetX(x);
    SetY(y);
    SetZ(z);
    SetPitch(pitch);
    SetYaw(yaw);
}
// May Trigger GC, but parameter value will be protected
HRESULT CLR_RT_HeapBlock_Queue::Enqueue( CLR_RT_HeapBlock* value )
{
    NATIVE_PROFILE_CLR_CORE();
    TINYCLR_HEADER();

    CLR_RT_HeapBlock_Array* array    = GetArray();
    CLR_INT32               size     = GetSize();
    CLR_INT32               tail     = GetTail();
    CLR_INT32               capacity = array->m_numOfElements;

    if(size == capacity)
    {
        // Set new capacity
        CLR_RT_HeapBlock newArrayHB;
        
        // Protect value from GC, in case CreateInstance triggers one
        CLR_RT_HeapBlock valueHB; valueHB.SetObjectReference( value );
        CLR_RT_ProtectFromGC gc( valueHB );

        capacity *= 2;

        TINYCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance( newArrayHB, capacity, g_CLR_RT_WellKnownTypes.m_Object ));

        array = newArrayHB.DereferenceArray();

        CopyTo( array, 0 );

        tail = size;

        SetArray( array );
        SetHead ( 0     );
        SetTail ( tail  );
    }

    ((CLR_RT_HeapBlock*)array->GetElement( tail ))->SetObjectReference( value );

    SetTail( (tail + 1) % capacity );

    SetSize( size + 1 );

    TINYCLR_NOCLEANUP();
}
Ejemplo n.º 7
0
//******************************************************************************
//
//  CStatusBar::Create
//
//      创建状态栏窗口
//
//
BOOL CStatusBar::Create(HWND hWndParent)
{
	HINSTANCE hInstance = (HINSTANCE)::GetWindowLong(hWndParent, GWL_HINSTANCE);

	m_hWnd = ::CreateWindowEx(
		0,
		STATUSCLASSNAME,
		NULL,
		WS_VISIBLE | WS_CHILD | SBARS_SIZEGRIP,
		0,
		0,
		0,
		0,
		hWndParent,
		(HMENU)201,
		hInstance,
		NULL);

	if (m_hWnd == NULL)
	{
		::MessageBox(hWndParent, "创建状态栏失败!", NULL, MB_OK);
		return FALSE;
	}

	// 分两部分,第一部分显示说明,第二部分显示坐标
	INT Parts[ 2 ];
	Parts[ 0 ] = 500;
	Parts[ 1 ] = -1;
	
	LRESULT i = ::SendMessage(m_hWnd, SB_SETPARTS, 2, (LPARAM)Parts);

	SetHead("就绪");

	::ShowWindow(m_hWnd, SW_SHOW);
	::UpdateWindow(m_hWnd);

	return TRUE;
}
HRESULT CLR_RT_HeapBlock_Queue::Dequeue( CLR_RT_HeapBlock*& value )
{
    NATIVE_PROFILE_CLR_CORE();
    TINYCLR_HEADER();

    CLR_RT_HeapBlock_Array* array   = GetArray();
    CLR_INT32               size    = GetSize();
    CLR_INT32               head    = Head();
    CLR_RT_HeapBlock*       removed;

    if(size == 0) TINYCLR_SET_AND_LEAVE(CLR_E_INVALID_OPERATION);

    removed = (CLR_RT_HeapBlock*)array->GetElement( head );

    value = removed->Dereference();

    removed->SetObjectReference( NULL );

    SetHead( (head + 1) % array->m_numOfElements );
    
    SetSize( size - 1 );

    TINYCLR_NOCLEANUP();
}