int main(void) { List list; Item item; //初始化单链表 printf("Initialize List\n"); Initialize(&list); if (IsEmpty(&list)) { printf("List is empty!\n"); while (1 == scanf("%d", &item)) { AddItemHead(item, &list); } ClearBuffer(); } printf("List items:\n"); Traverse(&list, (void (*) (Item item)) (&DisplayItem)); printf("\nList has %d items.\n", ItemCount(&list)); if (IsFull(&list)) { printf("List is full!\n"); } printf("Clear List!\n"); ClearList(&list); if (IsEmpty(&list)) { printf("List is empty!\n"); while (1 == scanf("%d", &item)) { AddItemTail(item, &list); } ClearBuffer(); } DeleteFirstItem(&list); DeleteLastItem(&list); printf("List items:\n"); Traverse(&list, (void (*) (Item item)) (&DisplayItem)); printf("\nList has %d items.\n", ItemCount(&list)); item = 3; RemoveItem(item, &list); printf("List items:\n"); Traverse(&list, (void (*) (Item item)) (&DisplayItem)); printf("\nList has %d items.\n", ItemCount(&list)); DestroyList(&list); return 0; }
void CTraceContainer::TimerExpired() { RExampleServerClient CrashClient; CrashClient.Connect(); CrashClient.GetCPUMax(iMaxCpuCount); TExampleItem ItemBuffer; TFileName Bufferrr; TInt ItemCount(0); CrashClient.GetItemCount(ItemCount); TInt GotCunt = iArray.Count(); for(TInt i = (GotCunt - 1); i < ItemCount; i++) { ItemBuffer.iIndex = i; CrashClient.GetItemL(ItemBuffer); AddItemListL(ItemBuffer); } if(iServerIsOn) { iTimeOutTimer->After(1000000); } CrashClient.Close(); DrawNow(); }
/* ----------------------------------------------------------------------- ----------------------------------------------------------------------- */ void CCrashContainer::DisplayListBoxL(void) { iArray.ResetAndDestroy(); delete iSelectionBox; iSelectionBox = NULL; iSelectionBox = new( ELeave ) CAknDoubleStyleListBox();//CAknDoubleNumberStyleListBox(); iSelectionBox->ConstructL(this,EAknListBoxMarkableList); CDesCArrayFlat* ListArray = new(ELeave)CDesCArrayFlat(1); CleanupStack::PushL(ListArray); RExampleServerClient CrashClient; CrashClient.Connect(); TExampleItem ItemBuffer; TInt ItemCount(0); CrashClient.GetItemCount(ItemCount); for(TInt i=0; i < ItemCount; i++) { TBool showMe(ETrue); ItemBuffer.iIndex = i; CrashClient.GetItemL(ItemBuffer); if(iHideKill0) { if(ItemBuffer.iExitType == EExitKill && ItemBuffer.iExitReason == 0) { showMe = EFalse; } } if(showMe) { AddToTheListL(ItemBuffer.iName,ItemBuffer.iExitType,ItemBuffer.iExitReason,ItemBuffer.iExitCatogory,*ListArray); AddItemListL(ItemBuffer); } } if(!iServerIsOn) { CrashClient.ShutServerDownNow(); } CrashClient.Close(); CleanupStack::Pop(); //ListArray iSelectionBox->Model()->SetItemTextArray(ListArray); iSelectionBox->Model()->SetOwnershipType(ELbmOwnsItemArray); iSelectionBox->CreateScrollBarFrameL( ETrue ); iSelectionBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto ); iSelectionBox->SetRect(Rect()); iSelectionBox->ActivateL(); UpdateScrollBar(iSelectionBox); }
void PopupMenu::removeItem(const UInt32& Index) { if(Index < getMFChildren()->size()) { MFChildrenType::iterator RemoveItor(editMFChildren()->begin()); UInt32 ItemCount(0); for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i) { if(getChildren(i)->getType() != Separator::getClassType()) { ++ItemCount; } //if(ItemCount == Index) //{ //break; //} ++RemoveItor; } if(RemoveItor != editMFChildren()->end()) { editMFChildren()->erase(RemoveItor); producePopupMenuContentsChanged(PopupMenuEvent::create(PopupMenuRefPtr(this), getSystemTime())); } } }
void PopupMenu::addItem(MenuItemRefPtr Item, const UInt32& Index) { if(Index < getMFChildren()->size()) { MFChildrenType::iterator InsertItor(editMFChildren()->begin()); UInt32 ItemCount(0); for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i) { if(getChildren(i)->getType() != Separator::getClassType()) { ++ItemCount; } if(ItemCount == Index) { break; } ++InsertItor; } if(InsertItor != editMFChildren()->end()) { editMFChildren()->insert(InsertItor, Item); producePopupMenuContentsChanged(PopupMenuEvent::create(PopupMenuRefPtr(this), getSystemTime())); } } }
/** Executes a new search with the already created CTulAddressStringTokenizer instance. The position in the found items array is reset to the beginning of the array. @param aText will be parsed. @param aSearchCases identifies what items are we looking for: EFindItemSearchPhoneNumberBin EFindItemSearchMailAddressBin EFindItemSearchURLBin EFindItemSearchScheme Any combination of these flags can be given as a bit mask. @param aMinNumbers defines a minimum count of numbers in a phone number string, during a phone number search. @return number of found items. @panic ETulPanicInvalidTokenizerSearchCase in debug build if there is no valid search case. @panic ETulPanicDescriptorLength in debug build if item's position and/or length is out of the document's range. @leave KErrNone, if successful; otherwise one of the other system-wide error codes. */ EXPORT_C TInt CTulAddressStringTokenizer::DoNewSearchL(const TDesC& aText, TInt aSearchCases, TInt aMinNumbers) { delete iFoundItems; iFoundItems = NULL; iPosition = 0; ConstructL(aText, aSearchCases, aMinNumbers); return ItemCount(); }
int ItemCountD(List *list ) { if(!ShowCurrentDesk) return ItemCount(list); /* else */ return ItemCountDesk(list, CurrentDesk); }
//----------------------------------------------------------------------------- // Replace a string in the list with one which has the desired font Boolean WXmList::ChangeItemFont( int pos, char* newtag ) { int count = ItemCount(); if( count < pos ) { return FALSE; } XmStringTable ListStrings = Items(); if( pos == 0 ){ // Zero indicates the last element pos = count; } WXmString OldString( ListStrings[pos-1] ); WXmString NewString(OldString.CopyUsingFont(newtag)); ReplaceItemsPos((XmString*)&NewString, 1, 1); return TRUE; } // WXmList::ChangeItemFont( WXmList* pList, int pos, char* newtag )
// --------------------------------------------------------------------------- // CAppMngr2ListContainer::SetEmptyTextL() // --------------------------------------------------------------------------- // void CAppMngr2ListContainer::SetEmptyTextL( TInt aMoreRefreshesExpected ) { // Set empty text if it is not already set CListBoxView* view = iListBox->View(); if( view ) { const TDesC* text = view->EmptyListText(); if( text == NULL || text->Length() == 0 ) { // The first refresh may happen too soon. If there are no items // to be displayed, and more refreshes are still expected, then // do not set the empty text yet -- it would be displayed. if( ItemCount() > 0 || !aMoreRefreshesExpected ) { HBufC* emptyText = StringLoader::LoadLC( ListEmptyTextResourceId() ); view->SetListEmptyTextL( *emptyText ); CleanupStack::PopAndDestroy( emptyText ); } } } }
//helper function for Pickup::pick_up //return value is amount of ammo added to quiver int Pickup::handle_quiver_insertion(item &here, bool inv_on_fail, int &moves_to_decrement, bool &picked_up) { //add ammo to quiver int quivered = here.add_ammo_to_quiver(&g->u, true); if(quivered > 0) { moves_to_decrement = 0; //moves already decremented in item::add_ammo_to_quiver() picked_up = true; return quivered; } else if (inv_on_fail) { //add to inventory instead item& it = g->u.i_add(here); picked_up = true; //display output message PickupMap map_pickup; int charges = (here.count_by_charges()) ? here.charges : 1; map_pickup.insert(std::pair<std::string, ItemCount>(here.tname(), ItemCount(it, charges))); show_pickup_message(map_pickup); } return 0; }
MenuItem* PopupMenu::getItem(const UInt32& Index) { if(Index < getMFChildren()->size()) { UInt32 ItemCount(0); for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i) { if(getChildren(i)->getType() != Separator::getClassType()) { if(ItemCount == Index) { break; } ++ItemCount; } } if(ItemCount < getMFChildren()->size()) { return dynamic_cast<MenuItem*>(getChildren(ItemCount)); } } return NULL; }
void Pickup::pick_one_up( const tripoint &pickup_target, item &newit, vehicle *veh, int cargo_part, int index, int quantity, bool &got_water, bool &offered_swap, PickupMap &mapPickup, bool autopickup ) { int moves_taken = 100; bool picked_up = false; item leftovers = newit; if( newit.invlet != '\0' && g->u.invlet_to_position( newit.invlet ) != INT_MIN ) { // Existing invlet is not re-usable, remove it and let the code in player.cpp/inventory.cpp // add a new invlet, otherwise keep the (usable) invlet. newit.invlet = '\0'; } if( quantity != 0 && newit.count_by_charges() ) { // Reinserting leftovers happens after item removal to avoid stacking issues. leftovers.charges = newit.charges - quantity; if( leftovers.charges > 0 ) { newit.charges = quantity; } } else { leftovers.charges = 0; } if( newit.made_of(LIQUID) ) { got_water = true; } else if (!g->u.can_pickWeight(newit.weight(), false)) { add_msg(m_info, _("The %s is too heavy!"), newit.display_name().c_str()); } else if( newit.is_ammo() && (newit.ammo_type() == "arrow" || newit.ammo_type() == "bolt")) { //add ammo to quiver int quivered = handle_quiver_insertion( newit, moves_taken, picked_up); if( newit.charges > 0) { if(!g->u.can_pickVolume( newit.volume())) { if(quivered > 0) { //update the charges for the item that gets re-added to the game map quantity = quivered; leftovers.charges = newit.charges; } if( !autopickup ) { // Silence some messaging if we're doing autopickup. add_msg(m_info, ngettext("There's no room in your inventory for the %s.", "There's no room in your inventory for the %s.", newit.charges), newit.tname(newit.charges).c_str()); } } else { //add to inventory instead item &it = g->u.i_add(newit); picked_up = true; //display output message PickupMap map_pickup; int charges = (newit.count_by_charges()) ? newit.charges : 1; map_pickup.insert(std::pair<std::string, ItemCount>(newit.tname(), ItemCount(it, charges))); show_pickup_message(map_pickup); } } } else if (!g->u.can_pickVolume(newit.volume())) { if( !autopickup ) { // Armor can be instantly worn if (newit.is_armor() && query_yn(_("Put on the %s?"), newit.display_name().c_str())) { if (g->u.wear_item(newit)) { picked_up = true; } } else if (g->u.is_armed()) { if (!g->u.weapon.has_flag("NO_UNWIELD")) { if( !offered_swap ) { offered_swap = true; if ( g->u.weapon.type->id != newit.type->id && query_yn(_("No space for %1$s; wield instead? (drops %2$s)"), newit.display_name().c_str(), g->u.weapon.display_name().c_str()) ) { picked_up = true; g->m.add_item_or_charges( pickup_target, g->u.remove_weapon(), 1 ); g->u.inv.assign_empty_invlet( newit, true ); // force getting an invlet. g->u.wield( &( g->u.i_add(newit) ) ); if (newit.invlet) { add_msg(m_info, _("Wielding %c - %s"), newit.invlet, newit.display_name().c_str()); } else { add_msg(m_info, _("Wielding - %s"), newit.display_name().c_str()); } } } } else { add_msg(m_info, _("There's no room in your inventory for the %s " "and you can't unwield your %s."), newit.display_name().c_str(), g->u.weapon.display_name().c_str()); } } else if( !g->u.is_armed() ) { if (g->u.keep_hands_free) { add_msg(m_info, _("There's no room in your inventory for the %s " "and you have decided to keep your hands free."), newit.display_name().c_str()); } else { g->u.inv.assign_empty_invlet(newit, true); // force getting an invlet. g->u.wield(&(g->u.i_add(newit))); picked_up = true; if (newit.invlet) { add_msg(m_info, _("Wielding %c - %s"), newit.invlet, newit.display_name().c_str()); } else { add_msg(m_info, _("Wielding - %s"), newit.display_name().c_str()); } } } // end of if unarmed } // end of if !autopickup } else { auto &entry = mapPickup[newit.tname()]; entry.second += newit.count_by_charges() ? newit.charges : 1; entry.first = g->u.i_add(newit); picked_up = true; } if(picked_up) { Pickup::remove_from_map_or_vehicle(pickup_target, veh, cargo_part, moves_taken, index); } if( leftovers.charges > 0 ) { bool to_map = veh == nullptr; if( !to_map ) { to_map = !veh->add_item( cargo_part, leftovers ); } if( to_map ) { g->m.add_item_or_charges( pickup_target, leftovers ); } } }
void ECCacheBase::DumpStats(ECLogger *lpLogger) { std::string strName; strName = m_strCachename + " cache size:"; lpLogger->Log(EC_LOGLEVEL_FATAL, " %-30s %8lu (%8llu bytes) (usage %.02f%%)", strName.c_str(), ItemCount(), Size(), Size() / (double)MaxSize() * 100.0); strName = m_strCachename + " cache hits:"; lpLogger->Log(EC_LOGLEVEL_FATAL, " %-30s %8llu / %llu (%.02f%%)", strName.c_str(), ValidCount(), HitCount(), ValidCount() / (double)HitCount() * 100.0); }
void ECCacheBase::RequestStats(void(callback)(const std::string &, const std::string &, const std::string &, void*), void *obj) { callback((std::string)"cache_" + m_strCachename + "_items", (std::string)"Cache " + m_strCachename + " items", stringify_int64(ItemCount()), obj); callback((std::string)"cache_" + m_strCachename + "_size", (std::string)"Cache " + m_strCachename + " size", stringify_int64(Size()), obj); callback((std::string)"cache_" + m_strCachename + "_maxsz", (std::string)"Cache " + m_strCachename + " maximum size", stringify_int64(m_ulMaxSize), obj); callback((std::string)"cache_" + m_strCachename + "_req", (std::string)"Cache " + m_strCachename + " requests", stringify_int64(HitCount()), obj); callback((std::string)"cache_" + m_strCachename + "_hit", (std::string)"Cache " + m_strCachename + " hits", stringify_int64(ValidCount()), obj); }
// --------------------------------------------------------------------------- // CAppMngr2ListContainer::PopulateItemArrayL() // --------------------------------------------------------------------------- // void CAppMngr2ListContainer::PopulateItemArrayL() { FLOG( "CAppMngr2ListContainer::PopulateItemArrayL()" ); CArrayPtr<CGulIcon>* iconArray = iListBox->ItemDrawer()->ColumnData()->IconArray(); DeleteItemSpecificIcons( *iconArray ); TInt count = ItemCount(); for( TInt index = 0; index < count; index++ ) { const CAppMngr2InfoBase& appInfo = ItemInfo( index ); // Get name and details TPtrC name = appInfo.Name(); TPtrC size = appInfo.Details(); // Get icon indexes that plugin loaded in LoadIconsL() TInt iconIndexBase; TInt iconIndexMax; Model().GetIconIndexesL( appInfo.Runtime().RuntimeUid(), iconIndexBase, iconIndexMax ); // Get list icon index from plugin TInt iconIndex = appInfo.IconIndex(); // Convert index into the range of 0 .. (icons - 1) if( iconIndex == EAppMngr2UseSpecificIcon ) { CGulIcon* icon = NULL; TRAP_IGNORE( icon = appInfo.SpecificIconL() ); if( icon ) { CleanupStack::PushL( icon ); iconIndex = iconArray->Count(); iconArray->AppendL( icon ); CleanupStack::Pop( icon ); iItemSpecificIcons++; } else { iconIndex = EAppMngr2IconIndex_QgnPropUnknown; } } else { // There are no default list icons that plugins could use, so // this must be list icon that plugin has loaded in LoadIconsL(). // Icons (of this plugin) are indexed from iconIndexBase. iconIndex += iconIndexBase; // Plugin should use only those icons it has provided. Use // default unknown icon if plugin tries to use icons that // another plugin has loaded. if( iconIndex < iconIndexBase || iconIndex >= iconIndexMax ) { iconIndex = EAppMngr2IconIndex_QgnPropUnknown; } } // Sanity check - index must be in range, otherwise list panics if( iconIndex < 0 || iconIndex >= iconArray->Count() ) { iconIndex = EAppMngr2IconIndex_QgnPropUnknown; } // Get indicator icon index from plugin TInt indIconIndex = appInfo.IndicatorIconIndex(); // Convert indicator icon index into the range of 0 .. (icons-1) or // leave special value EAppMngr2NoIndicatorIcon in it if( indIconIndex == EAppMngr2UseSpecificIcon ) { CGulIcon* icon = NULL; TRAP_IGNORE( icon = appInfo.SpecificIndicatorIconL() ); if( icon ) { CleanupStack::PushL( icon ); indIconIndex = iconArray->Count(); iconArray->AppendL( icon ); CleanupStack::Pop( icon ); iItemSpecificIcons++; } else { indIconIndex = EAppMngr2NoIndicatorIcon; } } else { // EAppMngr2NoIndicatorIcon is special value that is handled later if( indIconIndex != EAppMngr2NoIndicatorIcon ) { // Default icon indexes (starting from EAppMngr2NoIndicatorIcon) are // all above the icon index range reserved for plugins if( indIconIndex > EAppMngr2NoIndicatorIcon ) { // Use default icons, indexes start from zero indIconIndex -= ( EAppMngr2NoIndicatorIcon + 1 ); } else { // Use item specific icons, indexes start from iconIndexBase indIconIndex += iconIndexBase; } } } // Sanity check - icon index must be in range, otherwise list panics if( ( indIconIndex != EAppMngr2NoIndicatorIcon ) && ( indIconIndex < 0 || indIconIndex >= iconArray->Count() ) ) { indIconIndex = EAppMngr2NoIndicatorIcon; } // Construct line to be displayed HBufC* temp = HBufC::NewLC( name.Length() + size.Length() + KSpaceForTabsAndIconIndexes ); TPtr line = temp->Des(); if( indIconIndex == EAppMngr2NoIndicatorIcon ) { line.AppendFormat( KItemFormatNoInd, iconIndex, &name, &size ); } else { line.AppendFormat( KItemFormatFull, iconIndex, &name, &size, indIconIndex ); } iItemArray->AppendL( line ); FLOG( "CAppMngr2ListContainer::PopulateItemArrayL(): %S", temp ); CleanupStack::PopAndDestroy( temp ); } }
inline size_t CListView::AppendItem(const tchar* pszText, size_t nImage) { return InsertItem(ItemCount(), pszText, nImage); }
inline size_t CListView::AppendItem(const tstring& text, size_t image) { return InsertItem(ItemCount(), text.c_str(), image); }
inline void CListView::SelectFirstItem() { if (ItemCount() != 0) Select(0); }