예제 #1
0
void main()
{
	struct node* head = PushAtTailbyTail(10);

	int ndx;
	scanf("%d", &ndx);
	PrintList(head);
	printf("\nData at %d is  = %d\n", ndx, GetNth(head, ndx));
}
예제 #2
0
main()
{
	struct node* head = build123();
	printdata(head);
	printf("1 occur %d times\n",count(head,1));
	printf("3 occur %d times\n",count(head,3));
	printf("10 occur %d times\n",count(head,10));
	printf("0th element is %d \n",GetNth(head,0));
	DeleteList(&head);
}
bool ChangeGuid(std::string& str, uint32 n, PlayerDump::DumpGuidMap& guidMap, ObjectGuid::LowType guidOffset, bool allowZero = false)
{
    ObjectGuid::LowType oldGuid = strtoull(GetNth(str, n).c_str(), nullptr, 10);
    if (allowZero && !oldGuid)
        return true;                                        // not an error

    char chritem[20];
    ObjectGuid::LowType newGuid = RegisterNewGuid(oldGuid, guidMap, guidOffset);
    snprintf(chritem, 20, "%u", newGuid);

    return ChangeNth(str, n, chritem, false, allowZero);
}
예제 #4
0
main()
{
	struct node* head = build123();
	printdata(head);
	printf("0th element is %d \n",GetNth(head,0));
	printf("value = %d\n",pop(&head));
	printdata(head);
	printf("value = %d\n",pop(&head));
	printdata(head);
	printf("value = %d\n",pop(&head));
	printdata(head);
	printf("value = %d\n",pop(&head));
	printdata(head);
}
예제 #5
0
bool wxWindowSettings::SaveConfig(wxConfigBase& config)
{
    unsigned int i = 0;
    for (i = 0; i < GetCount(); i++)
    {
        wxWindowSettingsObject* obj = GetNth(i);

        wxString name(obj->m_windowName);
        name.Replace(wxT(" "), wxT(""));

        SaveFont(config, name, obj->m_font);
    }

    return TRUE;
}
예제 #6
0
VError VBagArray::_GetJSONString(VString& outJSONString, sLONG& curlevel, bool prettyformat, JSONOption inModifier) const
{
	AppendBeginJSONArray(outJSONString, curlevel, prettyformat);

	VIndex nbelem = GetCount();
	for (VIndex i = 1; i <= nbelem; i++)
	{
		GetNth(i)->_GetJSONString(outJSONString, curlevel, prettyformat, inModifier);
		if (i != nbelem)
			outJSONString.AppendUniChar(',');
	}

	AppendEndJSONArray(outJSONString, curlevel, prettyformat);
	return VE_OK;
}
예제 #7
0
파일: test.cpp 프로젝트: irenams/IrenaSt
int main()
{
	struct node* head;
	int len;
	head = BuildOneTwoThree();

	ReverseTest();
	display(head);

	
	Push(&head, 13);
	
	Push(&(head->next), 42);
	

	len = Length(head);
	printf("%d\n", len);

	int m = Count(head, 2);
	//printf("%d\n",m);
	display(head);

	DeleteList(&head); 
	

	

	struct node* myList = BuildOneTwoThree(); 
	
	int lastNode = GetNth(myList, 2); 
	
	//printf("%d\n", lastNode);

	InsertNthTest();

	PopTest();
	display(head);

	MoveNodeTest();
	DestroyTest();
   


	getchar();
	return 0;
}
예제 #8
0
파일: ll1.c 프로젝트: himz/C
int main() {
	int a;
	head = NULL;
	push( &head, 3);
	push( &head, 2);
	push( &head, 1);
	push( &head, 1);
	checkList();
	printf("Head Node: \n");
	printNode(head);
	printf("List: \n");
	printList(head);
	/* Count Test */
	printf("Count of 1 = %d\n", Count( head, 1 ));
	/* GetNth test */
	printf("Value at node 2 = %d \n", GetNth( head, 2));
	scanf("%d",&a);
}
예제 #9
0
/* Drier program to test above function*/
int main() {
	/* Start with the empty list */
	struct node* head = NULL;
	int num;
	
	/* Use push() to construct below list
	1->12->1->4->1 */
	push(&head, 1);
	push(&head, 4);
	push(&head, 1);
	push(&head, 12);
	push(&head, 1); 

	printf("Please enter the index to search for\n");
	scanf("%d", &num);
	/* Check the count function */
	printf("Element at index %d is %d\n", num, GetNth(head, num)); 
	getchar();
}
예제 #10
0
bool wxWindowSettings::ApplyFontsToWindows()
{
    if (m_useDefaults)
        return FALSE;

    unsigned int i = 0;
    for (i = 0; i < GetCount(); i++)
    {
        wxWindowSettingsObject* obj = GetNth(i);

        unsigned int j = 0;
        for (j = 0; j < obj->m_arrWindow.GetCount(); j++)
        {
            wxWindow* win = (wxWindow*) obj->m_arrWindow[j];
            win->SetFont(obj->m_font);
            win->Refresh();
        }
    }
    return TRUE;
}
예제 #11
0
void GetNthTest(void)
{
		struct node *head = BuildOneTwoThree();
		int LastNode = GetNth(head,3);
		printf("%d\n",LastNode);
}
DumpReturn PlayerDumpReader::LoadDump(std::string const& file, uint32 account, std::string name, ObjectGuid::LowType guid)
{
    uint32 charcount = AccountMgr::GetCharactersCount(account);
    if (charcount >= 10)
        return DUMP_TOO_MANY_CHARS;

    FILE* fin = fopen(file.c_str(), "r");
    if (!fin)
        return DUMP_FILE_OPEN_ERROR;

    char newguid[20], chraccount[20];

    // make sure the same guid doesn't already exist and is safe to use
    bool incHighest = true;
    if (guid && guid < sObjectMgr->GetGenerator<HighGuid::Player>().GetNextAfterMaxUsed())

    {
        PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHECK_GUID);
        stmt->setUInt32(0, guid);
        PreparedQueryResult result = CharacterDatabase.Query(stmt);

        if (result)
            guid = sObjectMgr->GetGenerator<HighGuid::Player>().GetNextAfterMaxUsed();                     // use first free if exists

        else
            incHighest = false;
    }
    else
        guid = sObjectMgr->GetGenerator<HighGuid::Player>().GetNextAfterMaxUsed();


    // normalize the name if specified and check if it exists
    if (!normalizePlayerName(name))
        name.clear();

    if (ObjectMgr::CheckPlayerName(name, sWorld->GetDefaultDbcLocale(), true) == CHAR_NAME_SUCCESS)
    {
        PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHECK_NAME);
        stmt->setString(0, name);
        PreparedQueryResult result = CharacterDatabase.Query(stmt);

        if (result)
            name.clear();                                       // use the one from the dump
    }
    else
        name.clear();

    // name encoded or empty

    snprintf(newguid, 20, "%u", guid);
    snprintf(chraccount, 20, "%u", account);

    DumpGuidMap items;
    DumpGuidMap mails;
    char buf[32000];
    memset(buf, 0, sizeof(buf));

    typedef std::map<uint32 /*old*/, uint32 /*new*/> PetIds;
    PetIds petIds;

    uint8 gender = GENDER_NONE;
    uint8 race = RACE_NONE;
    uint8 playerClass = 0;
    uint8 level = 1;

    ObjectGuid::LowType itemLowGuidOffset = sObjectMgr->GetGenerator<HighGuid::Item>().GetNextAfterMaxUsed();

    SQLTransaction trans = CharacterDatabase.BeginTransaction();
    while (!feof(fin))
    {
        if (!fgets(buf, 32000, fin))
        {
            if (feof(fin))
                break;
            ROLLBACK(DUMP_FILE_BROKEN);
        }

        std::string line; line.assign(buf);

        // skip empty strings
        size_t nw_pos = line.find_first_not_of(" \t\n\r\7");
        if (nw_pos == std::string::npos)
            continue;

        // skip logfile-side dump start notice, the important notes and dump end notices
        if ((line.substr(nw_pos, 16) == "== START DUMP ==") ||
            (line.substr(nw_pos, 15) == "IMPORTANT NOTE:") ||
            (line.substr(nw_pos, 14) == "== END DUMP =="))
            continue;

        // add required_ check
        /*
        if (line.substr(nw_pos, 41) == "UPDATE character_db_version SET required_")
        {
            if (!CharacterDatabase.Execute(line.c_str()))
                ROLLBACK(DUMP_FILE_BROKEN);

            continue;
        }
        */

        // determine table name and load type
        std::string tn = GetTableName(line);
        if (tn.empty())
        {
            TC_LOG_ERROR("misc", "LoadPlayerDump: Can't extract table name from line: '%s'!", line.c_str());
            ROLLBACK(DUMP_FILE_BROKEN);
        }

        DumpTableType type = DumpTableType(0);
        uint8 i;
        for (i = 0; i < DUMP_TABLE_COUNT; ++i)
        {
            if (tn == dumpTables[i].name)
            {
                type = dumpTables[i].type;
                break;
            }
        }

        if (i == DUMP_TABLE_COUNT)
        {
            TC_LOG_ERROR("misc", "LoadPlayerDump: Unknown table: '%s'!", tn.c_str());
            ROLLBACK(DUMP_FILE_BROKEN);
        }

        // change the data to server values
        switch (type)
        {
            case DTT_CHARACTER:
            {
                if (!ChangeNth(line, 1, newguid))           // characters.guid update
                    ROLLBACK(DUMP_FILE_BROKEN);

                if (!ChangeNth(line, 2, chraccount))        // characters.account update
                    ROLLBACK(DUMP_FILE_BROKEN);

                race = uint8(atoul(GetNth(line, 4).c_str()));
                playerClass = uint8(atoul(GetNth(line, 5).c_str()));
                gender = uint8(atoul(GetNth(line, 6).c_str()));
                level = uint8(atoul(GetNth(line, 7).c_str()));
                if (name.empty())
                {
                    // check if the original name already exists
                    name = GetNth(line, 3);

                    PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHECK_NAME);
                    stmt->setString(0, name);
                    PreparedQueryResult result = CharacterDatabase.Query(stmt);

                    if (result)
                        if (!ChangeNth(line, 37, "1"))      // characters.at_login set to "rename on login"
                            ROLLBACK(DUMP_FILE_BROKEN);
                }
                else if (!ChangeNth(line, 3, name.c_str())) // characters.name
                    ROLLBACK(DUMP_FILE_BROKEN);

                const char null[5] = "NULL";
                if (!ChangeNth(line, 74, null))             // characters.deleteInfos_Account
                    ROLLBACK(DUMP_FILE_BROKEN);
                if (!ChangeNth(line, 75, null))             // characters.deleteInfos_Name
                    ROLLBACK(DUMP_FILE_BROKEN);
                if (!ChangeNth(line, 76, null))             // characters.deleteDate
                    ROLLBACK(DUMP_FILE_BROKEN);
                break;
            }
            case DTT_CHAR_TABLE:
            {
                if (!ChangeNth(line, 1, newguid))           // character_*.guid update
                    ROLLBACK(DUMP_FILE_BROKEN);
                break;
            }
            case DTT_EQSET_TABLE:
            {
                if (!ChangeNth(line, 1, newguid))
                    ROLLBACK(DUMP_FILE_BROKEN);             // character_equipmentsets.guid

                char newSetGuid[24];
                snprintf(newSetGuid, 24, UI64FMTD, sObjectMgr->GenerateEquipmentSetGuid());
                if (!ChangeNth(line, 2, newSetGuid))
                    ROLLBACK(DUMP_FILE_BROKEN);             // character_equipmentsets.setguid

                for (uint8 slot = 0; slot < EQUIPMENT_SLOT_END; ++slot)
                    if (!ChangeGuid(line, 7 + slot, items, itemLowGuidOffset, true))
                        ROLLBACK(DUMP_FILE_BROKEN);         // character_equipmentsets.item
                break;
            }
            case DTT_INVENTORY:
            {
                if (!ChangeNth(line, 1, newguid))           // character_inventory.guid update
                    ROLLBACK(DUMP_FILE_BROKEN);

                if (!ChangeGuid(line, 2, items, itemLowGuidOffset, true))
                    ROLLBACK(DUMP_FILE_BROKEN);             // character_inventory.bag update
                if (!ChangeGuid(line, 4, items, itemLowGuidOffset))
                    ROLLBACK(DUMP_FILE_BROKEN);             // character_inventory.item update
                break;
            }
            case DTT_MAIL:                                  // mail
            {
                if (!ChangeGuid(line, 1, mails, sObjectMgr->_mailId))
                    ROLLBACK(DUMP_FILE_BROKEN);             // mail.id update
                if (!ChangeNth(line, 6, newguid))           // mail.receiver update
                    ROLLBACK(DUMP_FILE_BROKEN);
                break;
            }
            case DTT_MAIL_ITEM:                             // mail_items
            {
                if (!ChangeGuid(line, 1, mails, sObjectMgr->_mailId))
                    ROLLBACK(DUMP_FILE_BROKEN);             // mail_items.id
                if (!ChangeGuid(line, 2, items, itemLowGuidOffset))
                    ROLLBACK(DUMP_FILE_BROKEN);             // mail_items.item_guid
                if (!ChangeNth(line, 3, newguid))           // mail_items.receiver
                    ROLLBACK(DUMP_FILE_BROKEN);
                break;
            }
            case DTT_ITEM:
            {
                // item, owner, data field:item, owner guid
                if (!ChangeGuid(line, 1, items, itemLowGuidOffset))
                   ROLLBACK(DUMP_FILE_BROKEN);              // item_instance.guid update
                if (!ChangeNth(line, 3, newguid))           // item_instance.owner_guid update
                    ROLLBACK(DUMP_FILE_BROKEN);
                break;
            }
            case DTT_ITEM_GIFT:
            {
                if (!ChangeNth(line, 1, newguid))           // character_gifts.guid update
                    ROLLBACK(DUMP_FILE_BROKEN);
                if (!ChangeGuid(line, 2, items, itemLowGuidOffset))
                    ROLLBACK(DUMP_FILE_BROKEN);             // character_gifts.item_guid update
                break;
            }
            case DTT_PET:
            {
                // store a map of old pet id to new inserted pet id for use by DTT_PET_TABLE tables
                std::string petIdStr = GetNth(line, 1);

                uint32 currentPetId = atoul(petIdStr.c_str());

                PetIds::const_iterator petIdsItr = petIds.find(currentPetId);
                if (petIdsItr != petIds.end())              // duplicate pets
                    ROLLBACK(DUMP_FILE_BROKEN);

                uint32 newPetId = sObjectMgr->GeneratePetNumber();
                petIds[currentPetId] = newPetId;

                if (!ChangeNth(line, 1, std::to_string(newPetId).c_str())) // character_pet.id update
                    ROLLBACK(DUMP_FILE_BROKEN);
                if (!ChangeNth(line, 3, newguid))           // character_pet.owner update
                    ROLLBACK(DUMP_FILE_BROKEN);

                break;
            }
            case DTT_PET_TABLE:                             // pet_aura, pet_spell, pet_spell_cooldown
            {
                std::string petIdStr = GetNth(line, 1);

                // lookup currpetid and match to new inserted pet id
                PetIds::const_iterator petIdsItr = petIds.find(atoul(petIdStr.c_str()));
                if (petIdsItr == petIds.end())              // couldn't find new inserted id
                    ROLLBACK(DUMP_FILE_BROKEN);

                if (!ChangeNth(line, 1, std::to_string(petIdsItr->second).c_str()))
                    ROLLBACK(DUMP_FILE_BROKEN);

                break;
            }
            default:
                TC_LOG_ERROR("misc", "Unknown dump table type: %u", type);
                break;
        }

        fixNULLfields(line);

        trans->Append(line.c_str());
    }

    CharacterDatabase.CommitTransaction(trans);

    // in case of name conflict player has to rename at login anyway
    sWorld->AddCharacterInfo(ObjectGuid(HighGuid::Player, guid), account, name, gender, race, playerClass, level);

    sObjectMgr->GetGenerator<HighGuid::Item>().Set(sObjectMgr->GetGenerator<HighGuid::Item>().GetNextAfterMaxUsed() + items.size());

    sObjectMgr->_mailId     += mails.size();

    if (incHighest)
        sObjectMgr->GetGenerator<HighGuid::Player>().Generate();


    fclose(fin);

    return DUMP_SUCCESS;
}
예제 #13
0
void GetNthTest() {
	struct node* myList = BuildOneTwoThree(); // build {1, 2, 3}
	int lastNode = GetNth(myList, 2); // returns the value 3
}
예제 #14
0
double
ContainerParameter<Container>::Get() const{
    if(fIndex >= fContainer.size())
        throw std::out_of_range("Container Parameter is out of bounds!");
    return GetNth(fContainer, fIndex, Category());
}
예제 #15
0
double& 
GetNth(Container& C_, size_t n_, std::forward_iterator_tag){
    return GetNth(C_, n_, std::bidirectional_iterator_tag());
}
예제 #16
0
void
ContainerParameter<Container>::Set(double val_){
    if(fIndex >= fContainer.size())
        throw std::out_of_range("Container Parameter is out of bounds!");
    GetNth(fContainer, fIndex, Category()) = val_;
}