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


C++ weak_ptr::reset方法代码示例

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


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

示例1:

 virtual ~A() {
     parent.reset();
     cout<<name<<" died"<<endl;
 }
开发者ID:CCJY,项目名称:coliru,代码行数:4,代码来源:main.cpp

示例2: mouseEvent

// ----------------------------------------------------------------------
// static method - called once for all widgets by the
//                 WidgetEventResponder, which self-
//                 registers to all events upon creation of the first widget.
//
bool ofxWidget::mouseEvent(ofMouseEventArgs& args_) {
	// If we register a mouse down event, we do a hit test over
	// all visible widgets, and re-order if necessary.
	// Then, and in all other cases, we do a hit-test on the 
	// frontmost widget and, if positive, forward the event to this 
	// widget.

	updateVisibleWidgetsList();

	if (sVisibleWidgets.empty()) return false;

	// ---------| invariant: there are some widgets flying around.

	bool eventAttended = false;

	float mx = args_.x;
	float my = args_.y;

	// if we have a mouse down on a widget, we need to check which 
	// widget was hit and potentially re-order widgets.

	// find the first widget that is under the mouse, that is also visible
	// if it is not yet up front, bring it to the front.

	// hit-test only visible widgets - this makes sure to only evaluate 
	// the widgets which are visible, and whose parents are visible, too.
	auto itUnderMouse = std::find_if(sVisibleWidgets.begin(), sVisibleWidgets.end(), [&mx, &my](std::weak_ptr<ofxWidget>& w) ->bool {
		auto p = w.lock();
		if (p && p->mVisible && p->mRect.inside(mx, my)) {
			return true;
		} else {
			return false;
		}
	});

	// if we have a click, we want to make sure the widget gets to be the topmost widget.
	if (args_.type == ofMouseEventArgs::Pressed) {

		// --- now iterate over sAllWidgets instead of just the visible widgets.
		// we need to do this, because otherwise the reorder check won't be safe 
		// as the number of children in sVisibleWidgets is potentially incorrect,
		// as the number of children there refers to all children of a widget,
		// and not just the visible children of the widget.
		auto itPressedWidget = (itUnderMouse == sVisibleWidgets.end() ?
			sAllWidgets.end() :
			findIt(*itUnderMouse, sAllWidgets.begin(), sAllWidgets.end()));

		if (itPressedWidget != sAllWidgets.end()) {
			if (!isSame(*itPressedWidget, sFocusedWidget)) {
				// change in focus detected.
				// first, let the first element know that it is losing focus
				if (auto previousElementInFocus = sFocusedWidget.lock())
					if (previousElementInFocus->onFocusLeave)
						previousElementInFocus->onFocusLeave();

				sFocusedWidget = *itPressedWidget;

				// now that the new wiget is at the front, send an activate callback.
				if (auto nextFocusedWidget = sFocusedWidget.lock())
					if (nextFocusedWidget->onFocusEnter)
						nextFocusedWidget->onFocusEnter();
			}
			bringToFront(itPressedWidget); // reorder widgets
		} else {
			// hit test was not successful, no wigets found.
			if (auto previousElementInFocus = sFocusedWidget.lock())
				if (previousElementInFocus->onFocusLeave)
					previousElementInFocus->onFocusLeave();

			sFocusedWidget.reset(); // no widget gets the focus, then.
		}
	} // end if (args_.type == ofMouseEventArgs::Pressed)

	// now, we will attempt to send the mouse event to the widget that 
	// is in focus.

	if (itUnderMouse != sVisibleWidgets.end()) {
			// a widget is under the mouse.
			// is it the same as the current widget under the mouse?
		if (!isSame(*itUnderMouse, sWidgetUnderMouse)) {
			if (auto nU = itUnderMouse->lock())
			{
				// there is a new widget under the mouse
				if (auto w = sWidgetUnderMouse.lock()) {
					// there was an old widget under the mouse
					if (w->onMouseLeave)
						w->onMouseLeave();
					w->mHover = false;
				}
				if (nU->onMouseEnter)
					nU->onMouseEnter();
				nU->mHover = true;
				sWidgetUnderMouse = *itUnderMouse;
			}
		}
//.........这里部分代码省略.........
开发者ID:tgfrerer,项目名称:ofxWidget,代码行数:101,代码来源:ofxWidget.cpp


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