void IdCollection<ESXRecordT>::load (ESM::ESMReader& reader, bool base) { std::string id = reader.getHNOString ("NAME"); if (reader.isNextSub ("DELE")) { int index = searchId (id); reader.skipRecord(); if (index==-1) { // deleting a record that does not exist // ignore it for now /// \todo report the problem to the user } else if (base) { removeRows (index, 1); } else { mRecords[index].mState = RecordBase::State_Deleted; } } else { ESXRecordT record; record.mId = id; record.load (reader); int index = searchId (record.mId); if (index==-1) { // new record Record<ESXRecordT> record2; record2.mState = base ? RecordBase::State_BaseOnly : RecordBase::State_ModifiedOnly; (base ? record2.mBase : record2.mModified) = record; appendRecord (record2); } else { // old record Record<ESXRecordT>& record2 = mRecords[index]; if (base) record2.mBase = record; else record2.setModified (record); } } }
type_elem removeId(list *l, int id) { type_elem aux = {0, 0, FALSE}; node *n; n = searchId(l, NULL, id); if(n == NULL) return aux; aux = n->elem; if (l->tail == n && l->head == n) { l->head = NULL; l->tail = NULL; } else if (l->head == n) { l->head = n->next; l->head->prev = NULL; } else if (l->tail == n) { l->tail = n->prev; l->tail->next = NULL; } else { n->prev->next = n->next; n->next->prev = n->prev; } free(n); l->count--; return aux; }
void CSMWorld::RefIdCollection::load (ESM::ESMReader& reader, bool base, UniversalId::Type type) { std::string id = reader.getHNOString ("NAME"); int index = searchId (id); if (reader.isNextSub ("DELE")) { reader.skipRecord(); if (index==-1) { // deleting a record that does not exist // ignore it for now /// \todo report the problem to the user } else if (base) { mData.erase (index, 1); } else { mData.getRecord (mData.globalToLocalIndex (index)).mState = RecordBase::State_Deleted; } } else { if (index==-1) { // new record int index = mData.getAppendIndex (type); mData.appendRecord (type, id); RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (index); mData.load (localIndex, reader, base); mData.getRecord (localIndex).mState = base ? RecordBase::State_BaseOnly : RecordBase::State_ModifiedOnly; } else { // old record RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (index); if (!base) if (mData.getRecord (localIndex).mState==RecordBase::State_Erased) throw std::logic_error ("attempt to access a deleted record"); mData.load (localIndex, reader, base); if (!base) mData.getRecord (localIndex).mState = RecordBase::State_Modified; } } }
int IdCollection<ESXRecordT>::getIndex (const std::string& id) const { int index = searchId (id); if (index==-1) throw std::runtime_error ("invalid ID: " + id); return index; }
int CSMWorld::RefIdCollection::getIndex (const std::string& id) const { int index = searchId (id); if (index==-1) throw std::runtime_error ("invalid ID: " + id); return index; }
static void checkById(int id, int params, int specs) { bool ok = false; if ((params == 2) && (specs == 0)) { int size = sizeof(two_parameter_functions) / sizeof(int); ok = searchId(id, two_parameter_functions, size); } else if ((params == 1) && (specs == 0)) { int size = sizeof(one_parameter_functions) / sizeof(int); ok = searchId(id, one_parameter_functions, size); } else if ((params == 0) && (specs == 1)) { int size = sizeof(spec_functions) / sizeof(int); ok = searchId(id, spec_functions, size); } else if ((params == 0) && (specs == 0)) { int size = sizeof(non_argument_functions) / sizeof(int); ok = searchId(id, non_argument_functions, size); } if (!ok) { throw Exception("Interpreter: invalid arguments of function"); } }
node *searchId(list *l, node *start, int id) { if (start == NULL) start = l->head; if (l->head == NULL) return NULL; if (start->elem.id == id) { return start; } if (start->next != NULL) { return searchId(l, start->next, id); } else { return NULL; } }
int CSMWorld::Resources::getIndex (const std::string& id) const { int index = searchId (id); if (index==-1) { std::ostringstream stream; stream << "Invalid resource: " << mBaseDirectory << '/' << id; throw std::runtime_error (stream.str().c_str()); } return index; }
void CSMWorld::InfoCollection::load (const Info& record, bool base) { int index = searchId (record.mId); if (index==-1) { // new record Record<Info> record2; record2.mState = base ? RecordBase::State_BaseOnly : RecordBase::State_ModifiedOnly; (base ? record2.mBase : record2.mModified) = record; int index = -1; std::string topic = Misc::StringUtils::lowerCase (record2.get().mTopicId); if (!record2.get().mPrev.empty()) { index = getInfoIndex (record2.get().mPrev, topic); if (index!=-1) ++index; } if (index==-1 && !record2.get().mNext.empty()) { index = getInfoIndex (record2.get().mNext, topic); } if (index==-1) { Range range = getTopicRange (topic); index = std::distance (getRecords().begin(), range.second); } insertRecord (record2, index); } else { // old record Record<Info> record2 = getRecord (index); if (base) record2.mBase = record; else record2.setModified (record); setRecord (index, record2); } }
void CSMWorld::InfoCollection::load (ESM::ESMReader& reader, bool base, const ESM::Dialogue& dialogue) { std::string id = Misc::StringUtils::lowerCase (dialogue.mId) + "#" + reader.getHNOString ("INAM"); if (reader.isNextSub ("DELE")) { int index = searchId (id); reader.skipRecord(); if (index==-1) { // deleting a record that does not exist // ignore it for now /// \todo report the problem to the user } else if (base) { removeRows (index, 1); } else { Record<Info> record = getRecord (index); record.mState = RecordBase::State_Deleted; setRecord (index, record); } } else { Info record; record.mTopicId = dialogue.mId; record.mId = id; record.load (reader); load (record, base); } }
MWWorld::Ptr MWWorld::ContainerStore::search (const std::string& id) { { Ptr ptr = searchId (potions, id, this); if (!ptr.isEmpty()) return ptr; } { Ptr ptr = searchId (appas, id, this); if (!ptr.isEmpty()) return ptr; } { Ptr ptr = searchId (armors, id, this); if (!ptr.isEmpty()) return ptr; } { Ptr ptr = searchId (books, id, this); if (!ptr.isEmpty()) return ptr; } { Ptr ptr = searchId (clothes, id, this); if (!ptr.isEmpty()) return ptr; } { Ptr ptr = searchId (ingreds, id, this); if (!ptr.isEmpty()) return ptr; } { Ptr ptr = searchId (lights, id, this); if (!ptr.isEmpty()) return ptr; } { Ptr ptr = searchId (lockpicks, id, this); if (!ptr.isEmpty()) return ptr; } { Ptr ptr = searchId (miscItems, id, this); if (!ptr.isEmpty()) return ptr; } { Ptr ptr = searchId (probes, id, this); if (!ptr.isEmpty()) return ptr; } { Ptr ptr = searchId (repairs, id, this); if (!ptr.isEmpty()) return ptr; } { Ptr ptr = searchId (weapons, id, this); if (!ptr.isEmpty()) return ptr; } return Ptr(); }
int main() { system("clear"); BookList_t*List = malloc(sizeof(BookList_t)); if (!List) return 0; List->first = NULL; List->last = NULL; int temp = 0; int choice; MainMenu:system ("clear"); mainmenu(); //MainMenu Iniziale printf("\nChoice: "); scanf("%d", &choice); while(choice!=5) //Riferito al mainmenu iniziale, esco solo con 5 -> END PROGRAM { switch (choice) { //::::::::::::::::::::::::::::::::::::::::FUNC:INSERT::::::::::::::::::::::::::::::::::::::::::: case 1: while (1){ system("clear"); printf("Insert the element:\n1)At the top of the list.\n2)At the end of the list.\n\n0)Main Menu\n\n"); scanf ("%d", &temp); if (temp == 1) { //Insert Head________________________ system("clear"); printf("Enter the book:\n"); insHead(List); printList(List); printf("Press any number to continue.."); scanf("%d", &temp); system("clear"); break;} else if (temp == 2){ //Insert Tail________________________ system("clear"); printf("Enter the book:\n"); insTail(List); printList(List); printf("Press any number to continue..\n"); scanf("%d", &temp); system("clear"); break;} else if (temp == 0) { goto MainMenu; } else { printf ("Please Insert a valid Number\a\n"); printf("Press any number to continue..\n"); scanf("%d", &temp); } } //::::::::::::::::::::::::::::::::::::::::FUNC:REMOVE::::::::::::::::::::::::::::::::::::::::::: case 2: while (1){ system("clear"); printf("Remove the element:\n1)At the top of the list.\n2)At the end of the list \n3)Remove from id.\n\n0)Main Menu\n\n"); scanf ("%d", &temp); if (temp == 1) { //Remove Head________________________ system ("clear"); printf("Book removed successfully.\n"); rmvHead(List); printf("Press any number to continue..\n"); scanf("%d", &temp); break;} else if (temp == 2){ //Remove Tail________________________ system ("clear"); rmvTail(List); printf("Book removed successfully.\n"); printf("Press any number to continue.."); scanf("%d", &temp); break;} else if (temp == 3){ //Remove From ID_____________________ system ("clear"); printf("Enter the book's id you want to delete:\n"); Cell_t* Ptr = searchId(List); Cell_t *Temp = List->first; if (Ptr != NULL) while(Temp != Ptr) { Temp = Temp->pNext; Temp->pNext = NULL; free(Ptr); Ptr = Temp; printf("Press any number to continue.."); scanf("%d", &temp); break; } } else if (temp == 0) { goto MainMenu; } else { printf ("Please Insert a valid Number\a\n"); printf("Press any number to continue..\n"); scanf("%d", &temp); } } //::::::::::::::::::::::::::::::::::::FUNC:LOAN:RETURN::::::::::::::::::::::::::::::::::::::::: case 3: while (1){ system("clear"); printf("Which action do you want to do?:\n1)Loan a book.\n2)Return a book.\n\n0)Main Menu\n\n"); scanf("%d", &temp); if (temp == 1){ system ("clear"); //Copyout________________ copyOut(List); printf("Function worked correctly.\n"); printf("Press any number to continue..\n"); scanf("%d", &temp); break;} else if (temp == 2){ //Copyin________________________ system ("clear"); copyIn(List); printf("Function worked correctly.\n"); printf("Press any number to continue..\n"); scanf("%d", &temp); break; } else if (temp == 0) goto MainMenu; else { printf ("Please Insert a valid Number\a\n"); printf("Press any number to continue..\n"); scanf("%d", &temp); } } //::::::::::::::::::::::::::::::::::::::FUNC:SEE:LIST::::::::::::::::::::::::::::::::::::::::::: case 4: while (1){ system("clear"); printf("What do you want to see?\n1)The List\n2)A specific book\n3)To check if the book is in the list\n\n0)Main Menu\n\n"); scanf ("%d", &temp); if (temp == 1){ //see the list_________________________________________ system ("clear"); printList(List); printf("Press any number to continue..\n"); scanf("%d", &temp); break; } else if (temp ==2){ //see a specific book______________________________ system ("clear"); printf("Enter the id:\n"); Cell_t *p = searchId(List); if(p != NULL){ printElem(p->book); printf("Press any number to continue..\n"); scanf("%d", &temp); break;} else { printf("No book with this id available.\n"); printf("Press any number to continue..\n"); scanf("%d", &temp); break;} } else if (temp==3){//To controll if the book is in the list_____________ system ("clear"); printf("Enter the id to see if the book is in the list:\n"); Cell_t *ren = searchId(List); if (ren != NULL) { printf("TRUE - In List\n"); printf("Press any number to continue..\n"); scanf("%d", &temp); break;} else { printf("FALSE - Not in list\n"); printf("Press any number to continue..\n"); scanf("%d", &temp); break;} } else if (temp == 0) { goto MainMenu; } else { printf ("Please Insert a valid Number\a\n"); printf("Press any number to continue..\n"); scanf("%d", &temp); } } } //::::::::::::::::::::::::::::::::::::::FINE:FUNZIONI::::::::::::::::::::::::::::::::::::::::::: system ("clear"); mainmenu(); printf("\nChoice: "); scanf("%d", &choice); } //Fine While system ("clear"); int e = 0; finalpiont: printf("\nExiting...\n\nAre you sure?\n1)Yes\n2)No\n"); scanf("%d", &e); if (e == 1){ system ("clear"); printf("\nThanks for using -Book's Registration Program-\n\nCopyright © 2016 Matteo Peruzzi. All rights reserved.\n\n\n"); return 0; } else if (e == 2) { system("clear"); goto MainMenu; } else { system ("clear"); printf ("Please Insert a valid Number\a\n"); goto finalpiont; } }