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


C++ SystemInfo::CPUCount方法代码示例

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


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

示例1: BMessage

void
ActivityView::MouseDown(BPoint where)
{
	int32 buttons = B_SECONDARY_MOUSE_BUTTON;
	if (Looper() != NULL && Looper()->CurrentMessage() != NULL)
		Looper()->CurrentMessage()->FindInt32("buttons", &buttons);

	if (buttons == B_PRIMARY_MOUSE_BUTTON) {
		fZoomPoint = where;
		fOriginalResolution = fDrawResolution;
		fZooming = true;
		SetMouseEventMask(B_POINTER_EVENTS);
		return;
	}

	BPopUpMenu *menu = new BPopUpMenu(B_EMPTY_STRING, false, false);
	menu->SetFont(be_plain_font);

	BMenu* additionalMenu = new BMenu(B_TRANSLATE("Additional items"));
	additionalMenu->SetFont(be_plain_font);

	SystemInfo info;
	BMenuItem* item;

	for (int32 i = 0; i < DataSource::CountSources(); i++) {
		const DataSource* source = DataSource::SourceAt(i);

		if (source->MultiCPUOnly() && info.CPUCount() == 1)
			continue;

		BMessage* message = new BMessage(kMsgToggleDataSource);
		message->AddInt32("index", i);

		item = new BMenuItem(source->Name(), message);
		if (FindDataSource(source))
			item->SetMarked(true);

		if (source->Primary())
			menu->AddItem(item);
		else
			additionalMenu->AddItem(item);
	}

	menu->AddItem(new BMenuItem(additionalMenu));
	menu->AddSeparatorItem();
	menu->AddItem(item = new BMenuItem(B_TRANSLATE("Show legend"),
		new BMessage(kMsgToggleLegend)));
	item->SetMarked(fShowLegend);

	menu->SetTargetForItems(this);
	additionalMenu->SetTargetForItems(this);

	ActivityWindow* window = dynamic_cast<ActivityWindow*>(Window());
	if (window != NULL && window->ActivityViewCount() > 1) {
		menu->AddSeparatorItem();
		BMessage* message = new BMessage(kMsgRemoveView);
		message->AddPointer("view", this);
		menu->AddItem(item = new BMenuItem(B_TRANSLATE("Remove graph"),
			message));
		item->SetTarget(window);
	}

	ConvertToScreen(&where);
	menu->Go(where, true, false, true);
}
开发者ID:,项目名称:,代码行数:65,代码来源:

示例2: _

status_t
ActivityView::AddDataSource(const DataSource* source, const BMessage* state)
{
	if (source == NULL)
		return B_BAD_VALUE;

	BAutolock _(fSourcesLock);

	// Search for the correct insert spot to maintain the order of the sources
	int32 insert = DataSource::IndexOf(source);
	for (int32 i = 0; i < fSources.CountItems() && i < insert; i++) {
		DataSource* before = fSources.ItemAt(i);
		if (DataSource::IndexOf(before) > insert) {
			insert = i;
			break;
		}
	}
	if (insert > fSources.CountItems())
		insert = fSources.CountItems();

	// Generate DataHistory and ViewHistory objects for the source
	// (one might need one history per CPU)

	uint32 count = 1;
	if (source->PerCPU()) {
		SystemInfo info;
		count = info.CPUCount();
	}

	for (uint32 i = 0; i < count; i++) {
		DataHistory* values = new(std::nothrow) DataHistory(10 * 60000000LL,
			RefreshInterval());
		ListAddDeleter<DataHistory> valuesDeleter(fValues, values, insert);

		ViewHistory* viewValues = new(std::nothrow) ViewHistory;
		ListAddDeleter<ViewHistory> viewValuesDeleter(fViewValues, viewValues,
			insert);

		if (valuesDeleter.Failed() || viewValuesDeleter.Failed())
			return B_NO_MEMORY;

		values->SetScale(_ScaleFor(source->ScaleType()));

		DataSource* copy;
		if (source->PerCPU())
			copy = source->CopyForCPU(i);
		else
			copy = source->Copy();

		ListAddDeleter<DataSource> sourceDeleter(fSources, copy, insert);
		if (sourceDeleter.Failed())
			return B_NO_MEMORY;

		BString colorName = source->Name();
		colorName << " color";
		if (state != NULL) {
			const rgb_color* color = NULL;
			ssize_t colorLength;
			if (state->FindData(colorName.String(), B_RGB_COLOR_TYPE, i,
					(const void**)&color, &colorLength) == B_OK
				&& colorLength == sizeof(rgb_color))
				copy->SetColor(*color);
		}

		valuesDeleter.Detach();
		viewValuesDeleter.Detach();
		sourceDeleter.Detach();
		insert++;
	}

#ifdef __HAIKU__
	InvalidateLayout();
#endif
	return B_OK;
}
开发者ID:,项目名称:,代码行数:75,代码来源:


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