当前位置: 首页>>代码示例>>C++>>正文


C++ BObjectList::SortItems方法代码示例

本文整理汇总了C++中BObjectList::SortItems方法的典型用法代码示例。如果您正苦于以下问题:C++ BObjectList::SortItems方法的具体用法?C++ BObjectList::SortItems怎么用?C++ BObjectList::SortItems使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BObjectList的用法示例。


在下文中一共展示了BObjectList::SortItems方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: data

status_t
DebugReportGenerator::_DumpRunningThreads(BFile& _output)
{
    AutoLocker< ::Team> locker(fTeam);

    BString data("\nActive Threads:\n");
    WRITE_AND_CHECK(_output, data);
    BObjectList< ::Thread> threads;
    ::Thread* thread;
    for (ThreadList::ConstIterator it = fTeam->Threads().GetIterator();
          (thread = it.Next());) {
         threads.AddItem(thread);
    }

    threads.SortItems(&_CompareThreads);
    for (int32 i = 0; (thread = threads.ItemAt(i)) != NULL; i++) {
        try {
            data.SetToFormat("\tthread %" B_PRId32 ": %s %s\n", thread->ID(),
                    thread->Name(), thread->IsMainThread()
                        ? "(main)" : "");
            WRITE_AND_CHECK(_output, data);

            if (thread->State() == THREAD_STATE_STOPPED) {
                data.SetToFormat("\t\tstate: %s",
                    UiUtils::ThreadStateToString(thread->State(),
                            thread->StoppedReason()));
                const BString& stoppedInfo = thread->StoppedReasonInfo();
                if (stoppedInfo.Length() != 0)
                    data << " (" << stoppedInfo << ")";
                data << "\n\n";
                WRITE_AND_CHECK(_output, data);

                // we need to release our lock on the team here
                // since we might need to block and wait
                // on the stack trace.
                BReference< ::Thread> threadRef(thread);
                locker.Unlock();
                status_t error = _DumpDebuggedThreadInfo(_output, thread);
                if (error != B_OK)
                    return error;
                locker.Lock();
            }
        } catch (...) {
            return B_NO_MEMORY;
        }
    }

    return B_OK;
}
开发者ID:AmirAbrams,项目名称:haiku,代码行数:49,代码来源:DebugReportGenerator.cpp

示例2: BMessage

// ---------------------------------------------------------------
// AddTranslationItems
//
// Envious of that "Save As" menu in ShowImage? Well, you can have your own!
// AddTranslationItems will add menu items for all translations from the
// basic format you specify (B_TRANSLATOR_BITMAP, B_TRANSLATOR_TEXT etc).
// The translator ID and format constant chosen will be added to the message
// that is sent to you when the menu item is selected.
//
// The following code is a modified version of code
// written by Jon Watte from
// http://www.b500.com/bepage/TranslationKit2.html
//
// Preconditions:
//
// Parameters: intoMenu, the menu where the entries are created
//             fromType, the type of translators to put on
//                       intoMenu
//             kModel, the BMessage model for creating the menu
//                     if NULL, B_TRANSLATION_MENU is used
//             kTranslationIdName, the name used for
//                                 translator_id in the menuitem,
//                                 if NULL, be:translator is used
//             kTranslatorTypeName, the name used for
//                                  output format id in the menuitem
//             roster, BTranslatorRoster used to find translators
//                     if NULL, the default translators are used
//             
//
// Postconditions:
//
// Returns: B_BAD_VALUE, if intoMenu is NULL
//          B_OK, if successful
//          error value if not successful
// ---------------------------------------------------------------
status_t
BTranslationUtils::AddTranslationItems(BMenu *intoMenu, uint32 fromType,
    const BMessage *kModel, const char *kTranslatorIdName,
    const char *kTranslatorTypeName, BTranslatorRoster *roster)
{
    if (!intoMenu)
        return B_BAD_VALUE;
        
    if (!roster)
        roster = BTranslatorRoster::Default();

    if (!kTranslatorIdName)
        kTranslatorIdName = "be:translator";

    if (!kTranslatorTypeName)
        kTranslatorTypeName = "be:type";

    translator_id * ids = NULL;
    int32 count = 0;
    status_t err = roster->GetAllTranslators(&ids, &count);
    if (err < B_OK)
        return err;

    BObjectList<translator_info> infoList;

    for (int tix = 0; tix < count; tix++) {
        const translation_format *formats = NULL;
        int32 numFormats = 0;
        bool ok = false;
        err = roster->GetInputFormats(ids[tix], &formats, &numFormats);
        if (err == B_OK) {
            for (int iix = 0; iix < numFormats; iix++) {
                if (formats[iix].type == fromType) {
                    ok = true;
                    break;
                }
            }
        }
        if (!ok)
            continue;

        // Get supported output formats
        err = roster->GetOutputFormats(ids[tix], &formats, &numFormats); 
        if (err == B_OK) {
            for (int oix = 0; oix < numFormats; oix++) {
                if (formats[oix].type != fromType) {
                    infoList.AddItem(_BuildTranslatorInfo(ids[tix],
                        const_cast<translation_format*>(&formats[oix])));
                }
            }
        }
    }

    // Sort alphabetically by name
    infoList.SortItems(&_CompareTranslatorInfoByName);

    // Now add the menu items
    for (int i = 0; i < infoList.CountItems(); i++) {
        translator_info* info = infoList.ItemAt(i);

        BMessage *itemmsg;
        if (kModel)
            itemmsg = new BMessage(*kModel);
        else
            itemmsg = new BMessage(B_TRANSLATION_MENU);
//.........这里部分代码省略.........
开发者ID:Barrett17,项目名称:haiku-contacts-kit-old,代码行数:101,代码来源:TranslationUtils.cpp

示例3: new

status_t
ThreadModelLoader::_Load()
{
    // create a model
    fThreadModel = new(std::nothrow) ThreadModel(fModel, fThread);
    if (fThreadModel == NULL)
        return B_NO_MEMORY;

    // collect all wait objects
    BObjectList<Model::ThreadWaitObject> waitObjects;

    int32 groupCount = fThread->CountThreadWaitObjectGroups();
    for (int32 i = 0; i < groupCount; i++) {
        Model::ThreadWaitObjectGroup* group
            = fThread->ThreadWaitObjectGroupAt(i);

        if (!group->GetThreadWaitObjects(waitObjects))
            return B_NO_MEMORY;
    }

    // sort them by type and name
    waitObjects.SortItems(&compare_by_type_and_name);

    // create the groups
    int32 waitObjectCount = waitObjects.CountItems();
    printf("%" B_PRId32 " wait objects\n", waitObjectCount);
    for (int32 i = 0; i < waitObjectCount;) {
        printf("new wait object group at %" B_PRId32 "\n", i);
        // collect the objects for this group
        Model::ThreadWaitObject* firstObject = waitObjects.ItemAt(i);
        int32 k = i + 1;
        for (; k < waitObjectCount; k++) {
            if (compare_by_type_and_name(firstObject, waitObjects.ItemAt(k))
                    != 0) {
                break;
            }
        }

        if (fThreadModel->AddWaitObjectGroup(waitObjects, i, k) == NULL)
            return B_NO_MEMORY;

        i = k;
    }

    // filter the events
    thread_id threadID = fThread->ID();
    bool done = false;
    uint32 count = 0;

    system_profiler_event_header** events = fModel->Events();
    size_t eventCount = fModel->CountEvents();
    for (size_t i = 0; i < eventCount; i++) {
        system_profiler_event_header* header = events[i];
        void* buffer = header + 1;

        // process the event
        bool keepEvent = false;

        switch (header->event) {
            case B_SYSTEM_PROFILER_THREAD_REMOVED:
            {
                system_profiler_thread_removed* event
                    = (system_profiler_thread_removed*)buffer;
                if (event->thread == threadID)
                    done = true;
                break;
            }

            case B_SYSTEM_PROFILER_THREAD_SCHEDULED:
            {
                system_profiler_thread_scheduled* event
                    = (system_profiler_thread_scheduled*)buffer;
                keepEvent = event->thread == threadID
                    || event->previous_thread == threadID ;
                break;
            }

            case B_SYSTEM_PROFILER_THREAD_ENQUEUED_IN_RUN_QUEUE:
            {
                thread_enqueued_in_run_queue* event
                    = (thread_enqueued_in_run_queue*)buffer;
                keepEvent = event->thread == threadID;
                break;
            }

            case B_SYSTEM_PROFILER_THREAD_REMOVED_FROM_RUN_QUEUE:
            {
                thread_removed_from_run_queue* event
                    = (thread_removed_from_run_queue*)buffer;
                keepEvent = event->thread == threadID;
                break;
            }

            default:
                break;
        }

        if (keepEvent)
            fThreadModel->AddSchedulingEvent(header);

//.........这里部分代码省略.........
开发者ID:AmirAbrams,项目名称:haiku,代码行数:101,代码来源:ThreadModelLoader.cpp


注:本文中的BObjectList::SortItems方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。