Exemplo n.º 1
0
HttpPostSocket::HttpPostSocket(SocketHandler& h,const std::string& url)
:HTTPSocket(h)
,m_port(80)
,m_bMultipart(false)
{
	std::string host;
	{
		Parse pa(url,"/");
		pa.getword(); // 'http:'
		host = pa.getword();
		SetUrl( "/" + pa.getrest() );
	}
	{
		Parse pa(host,":");
		m_host = pa.getword();
		m_port = (port_t)pa.getvalue();
		if (!m_port)
		{
			m_port = 80;
		}
	}
	std::string m_boundary = "----";
	for (int i = 0; i < 12; i++)
	{
		char c = 0;
		while (!isalnum(c))
		{
			c = rand() % 96 + 32;
		}
		m_boundary += c;
	}
}
Exemplo n.º 2
0
    CObject *Evaluate(const CObject_Vector &jj)
    {
      if (p_v->V()->id.back()==0) {
	const CVec4Type &a(*jj[0]->Get<CVec4Type>());
	const CVec4Type &b(*jj[1]->Get<CVec4Type>());
	CVec4Type pa(p_v->J(0)->P()), pb(p_v->J(1)->P());
	CScalarType *j(CScalarType::New(-(a*b)*(pa*pb)+(a*pb)*(b*pa)));
	j->SetS(a.S()|b.S());
	return j;
      }
      if (p_v->V()->id.back()==2) {
	const CScalarType &a(*jj[0]->Get<CScalarType>());
	const CVec4Type &b(*jj[1]->Get<CVec4Type>());
	CVec4Type pa(p_v->J(0)->P()), pb(p_v->J(1)->P());
	CVec4Type s(b*(pb*(pa+pb))-(b*(pa+pb))*pb);
	CVec4Type *j(CVec4Type::New(s*a[0]));
	j->SetS(a.S()|b.S());
	return j;
      }
      if (p_v->V()->id.back()==1) {
	const CScalarType &a(*jj[1]->Get<CScalarType>());
	const CVec4Type &b(*jj[0]->Get<CVec4Type>());
	CVec4Type pa(p_v->J(1)->P()), pb(p_v->J(0)->P());
	CVec4Type s(b*(pb*(pa+pb))-(b*(pa+pb))*pb);
	CVec4Type *j(CVec4Type::New(s*a[0]));
	j->SetS(a.S()|b.S());
	return j;
      }
    }
Exemplo n.º 3
0
void HTTPSocket::url_this(const std::string& url_in,std::string& protocol,std::string& host,port_t& port,std::string& url,std::string& file)
{
	Parse pa(url_in,"/");
	protocol = pa.getword(); // http
	if (!strcasecmp(protocol.c_str(), "https:"))
	{
#ifdef HAVE_OPENSSL
		EnableSSL();
#else
		Handler().LogError(this, "url_this", -1, "SSL not available", LOG_LEVEL_WARNING);
#endif
		port = 443;
	}
	else
	{
		port = 80;
	}
	host = pa.getword();
	if (strstr(host.c_str(),":"))
	{
		Parse pa(host,":");
		pa.getword(host);
		port = static_cast<port_t>(pa.getvalue());
	}
	url = "/" + pa.getrest();
	{
		Parse pa(url,"/");
		std::string tmp = pa.getword();
		while (tmp.size())
		{
			file = tmp;
			tmp = pa.getword();
		}
	}
} // url_this
Exemplo n.º 4
0
  static void exec(LHS &lhs, RHS const &rhs)
  {
    if (parallel::has_same_map<D>(lhs.map(), rhs))
    {
      // Maps are same, no communication required.
      typedef typename distributed_local_block<LHS>::type lhs_local_block_type;
      typedef typename distributed_local_block<RHS>::type rhs_local_block_type;
      typedef typename block_traits<lhs_local_block_type>::plain_type 
	lhs_local_storage_type;
      typedef typename block_traits<rhs_local_block_type>::plain_type
	rhs_local_storage_type;

      lhs_local_storage_type lhs_local_block = get_local_block(lhs);
      rhs_local_storage_type rhs_local_block = get_local_block(rhs);

      Dispatcher<D, lhs_local_block_type, rhs_local_block_type>::exec(lhs_local_block,
								      rhs_local_block);
    }
    else
    {
      lhs_view_type lhs_view(lhs);
      rhs_view_type rhs_view(const_cast<RHS&>(rhs));
      parallel::Assignment<D, LHS, RHS, Assign> pa(lhs_view, rhs_view);
      pa();
    }
  }
Exemplo n.º 5
0
    CObject *Evaluate(const CObject_Vector &jj)
    {
      if (p_v->V()->id.back()==0) {
	const CVec4Type &a(*jj[0]->template Get<CVec4Type>());
	const CVec4Type &b(*jj[1]->template Get<CVec4Type>());
	const CVec4Type &c(*jj[2]->template Get<CVec4Type>()); 
	Vec4D pa(p_v->J(0)->P()), pb(p_v->J(1)->P()), pc(p_v->J(2)->P());
	CScalarType *j(CScalarType::New
		       ((a*b)*(c*(pa-pb))+
			(b*c)*(a*(pb-pc))+
			(c*a)*(b*(pc-pa))));
	j->SetS(a.S()|b.S()|c.S());
	return j;
      }
      const CVec4Type &a(*jj[m_n[1]]->template Get<CVec4Type>());
      const CVec4Type &b(*jj[m_n[2]]->template Get<CVec4Type>());
      const CScalarType &e(*jj[m_n[0]]->template Get<CScalarType>()); 
      Vec4D pa(p_v->J(m_n[1])->P()), pb(p_v->J(m_n[2])->P());
      Vec4D pe(p_v->J(m_n[0])->P());
      CVec4Type *j(CVec4Type::New
		   (e[0]*((a*b)*CVec4Type(pa-pb)
			  +(a*ATOOLS::Vec4<SType>(pb+pb+pa+pe))*b
			  -(b*ATOOLS::Vec4<SType>(pa+pa+pb+pe))*a)));
      j->SetS(a.S()|b.S()|e.S());
      return j;
    }
int main(int, char**)
{
    {
        typedef std::piecewise_linear_distribution<> D;
        typedef D::param_type P;
        P pa({}, f);
        std::vector<double> iv = pa.intervals();
        assert(iv.size() == 2);
        assert(iv[0] == 0);
        assert(iv[1] == 1);
        std::vector<double> dn = pa.densities();
        assert(dn.size() == 2);
        assert(dn[0] == 1);
        assert(dn[1] == 1);
    }
    {
        typedef std::piecewise_linear_distribution<> D;
        typedef D::param_type P;
        P pa({12}, f);
        std::vector<double> iv = pa.intervals();
        assert(iv.size() == 2);
        assert(iv[0] == 0);
        assert(iv[1] == 1);
        std::vector<double> dn = pa.densities();
        assert(dn.size() == 2);
        assert(dn[0] == 1);
        assert(dn[1] == 1);
    }
    {
        typedef std::piecewise_linear_distribution<> D;
        typedef D::param_type P;
        P pa({10, 12}, f);
        std::vector<double> iv = pa.intervals();
        assert(iv.size() == 2);
        assert(iv[0] == 10);
        assert(iv[1] == 12);
        std::vector<double> dn = pa.densities();
        assert(dn.size() == 2);
        assert(dn[0] == 20./44);
        assert(dn[1] == 24./44);
    }
    {
        typedef std::piecewise_linear_distribution<> D;
        typedef D::param_type P;
        P pa({6, 10, 14}, f);
        std::vector<double> iv = pa.intervals();
        assert(iv.size() == 3);
        assert(iv[0] == 6);
        assert(iv[1] == 10);
        assert(iv[2] == 14);
        std::vector<double> dn = pa.densities();
        assert(dn.size() == 3);
        assert(dn[0] == 0.075);
        assert(dn[1] == 0.125);
        assert(dn[2] == 0.175);
    }

  return 0;
}
Exemplo n.º 7
0
int main()
{
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
    {
        typedef std::piecewise_linear_distribution<> D;
        typedef D::param_type P;
        P pa({}, f);
        std::vector<double> iv = pa.intervals();
        assert(iv.size() == 2);
        assert(iv[0] == 0);
        assert(iv[1] == 1);
        std::vector<double> dn = pa.densities();
        assert(dn.size() == 2);
        assert(dn[0] == 1);
        assert(dn[1] == 1);
    }
    {
        typedef std::piecewise_linear_distribution<> D;
        typedef D::param_type P;
        P pa({12}, f);
        std::vector<double> iv = pa.intervals();
        assert(iv.size() == 2);
        assert(iv[0] == 0);
        assert(iv[1] == 1);
        std::vector<double> dn = pa.densities();
        assert(dn.size() == 2);
        assert(dn[0] == 1);
        assert(dn[1] == 1);
    }
    {
        typedef std::piecewise_linear_distribution<> D;
        typedef D::param_type P;
        P pa({10, 12}, f);
        std::vector<double> iv = pa.intervals();
        assert(iv.size() == 2);
        assert(iv[0] == 10);
        assert(iv[1] == 12);
        std::vector<double> dn = pa.densities();
        assert(dn.size() == 2);
        assert(dn[0] == 20./44);
        assert(dn[1] == 24./44);
    }
    {
        typedef std::piecewise_linear_distribution<> D;
        typedef D::param_type P;
        P pa({6, 10, 14}, f);
        std::vector<double> iv = pa.intervals();
        assert(iv.size() == 3);
        assert(iv[0] == 6);
        assert(iv[1] == 10);
        assert(iv[2] == 14);
        std::vector<double> dn = pa.densities();
        assert(dn.size() == 3);
        assert(dn[0] == 0.075);
        assert(dn[1] == 0.125);
        assert(dn[2] == 0.175);
    }
#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}
Exemplo n.º 8
0
int main()
{
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
    {
        typedef std::piecewise_constant_distribution<> D;
        typedef D::param_type P;
        P pa({}, f);
        std::vector<double> iv = pa.intervals();
        assert(iv.size() == 2);
        assert(iv[0] == 0);
        assert(iv[1] == 1);
        std::vector<double> dn = pa.densities();
        assert(dn.size() == 1);
        assert(dn[0] == 1);
    }
    {
        typedef std::piecewise_constant_distribution<> D;
        typedef D::param_type P;
        P pa({12}, f);
        std::vector<double> iv = pa.intervals();
        assert(iv.size() == 2);
        assert(iv[0] == 0);
        assert(iv[1] == 1);
        std::vector<double> dn = pa.densities();
        assert(dn.size() == 1);
        assert(dn[0] == 1);
    }
    {
        typedef std::piecewise_constant_distribution<> D;
        typedef D::param_type P;
        P pa({12, 14}, f);
        std::vector<double> iv = pa.intervals();
        assert(iv.size() == 2);
        assert(iv[0] == 12);
        assert(iv[1] == 14);
        std::vector<double> dn = pa.densities();
        assert(dn.size() == 1);
        assert(dn[0] == 0.5);
    }
    {
        typedef std::piecewise_constant_distribution<> D;
        typedef D::param_type P;
        P pa({5.5, 7.5, 11.5}, f);
        std::vector<double> iv = pa.intervals();
        assert(iv.size() == 3);
        assert(iv[0] == 5.5);
        assert(iv[1] == 7.5);
        assert(iv[2] == 11.5);
        std::vector<double> dn = pa.densities();
        assert(dn.size() == 2);
        assert(dn[0] == 0.203125);
        assert(dn[1] == 0.1484375);
    }
#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}
Exemplo n.º 9
0
void HTTPSocket::OnLine(const std::string& line)
{
	if (m_first)
	{
		Parse pa(line);
		std::string str = pa.getword();
		if (str.substr(0,4) == "HTTP") // response
		{
			m_http_version = str;
			m_status = pa.getword();
			m_status_text = pa.getrest();
			m_response = true;
		}
		else // request
		{
			m_method = str;
			m_url = pa.getword();
			size_t spl = m_url.find("?");
			if (spl != std::string::npos)
			{
				m_uri = m_url.substr(0,spl);
				m_query_string = m_url.substr(spl + 1);
			}
			else
			{
				m_uri = m_url;
			}
			m_http_version = pa.getword();
			m_request = true;
		}
		m_first = false;
		OnFirst();
		return;
	}
	if (!line.size())
	{
//		SetLineProtocol(false);
		m_header = false;
		OnHeaderComplete();
		return;
	}
	Parse pa(line,":");
	std::string key = pa.getword();
	std::string value = pa.getrest();
	OnHeader(key,value);
	/* If remote end tells us to keep connection alive, and we're operating
	in http/1.1 mode (not http/1.0 mode), then we mark the socket to be
	retained. */
/*	if (!strcasecmp(key.c_str(), "connection") &&
	    !strcasecmp(value.c_str(), "keep-alive") )
	{
		SetRetain();
	}*/
}
Exemplo n.º 10
0
void init(){
  grabber.init(pa("-i"));

  bool c_arg = pa("-c");

  gui << Draw().handle("draw").label("input image")
      << Image().handle("cropped").label("cropped")
      << ( VBox().maxSize(c_arg ? 0 : 12,99).minSize(c_arg ? 0 : 12,1)
           << Button("save as ..").handle("saveAs")
           << Button("overwrite input").handle("overwrite")
           << Combo("0,90,180,270").handle("rot").label("rotation")
           << CheckBox("rectangular",!pa("-r")).handle("rect")
           << Button("Batch crop...").handle("batch")
           << ( HBox().label("rectification size")
                << Spinner(1,4096,640).handle("s1")
                << Label(":")
                << Spinner(1,4096,480).handle("s2")
                )
           << (HBox() 
               << Fps().handle("fps")
               << CamCfg()
               )
           )
      << Show();


  if(!c_arg){
    gui["batch"].registerCallback(batch_crop);
  }
  const ImgBase *image = grabber.grab();
  if(!c_arg){
    mouse_1 = new Mouse1(image->getSize());
    gui["draw"].install(mouse_1);
  }
  mouse_2 = new Mouse2(image->getSize());
  gui["draw"].install(mouse_2);
  
  DrawHandle draw = gui["draw"];
  draw->setImageInfoIndicatorEnabled(false);
  
  if(!c_arg){
    gui["rect"].registerCallback(rectangular_changed);
    rectangular_changed();
    if(*pa("-i",0) != "file" || FileList(*pa("-i",1)).size() != 1){
      gui["overwrite"].disable();
    }else{
      gui["overwrite"].registerCallback(overwrite);
    }
    gui["saveAs"].registerCallback(save_as);
  }

}
Exemplo n.º 11
0
int main(int n, char **args){
  pa_init(n,args,"[m]-input|-i(2) -rectification|-r -create-crop-rect-output-only|-ccroo|-c "
          "-estimate-image-size-only -estimate-image-ar-only "
          "-compute-optimal-scaling-size(target-width) -compute-optimal-scaling-size-input-size(Size=0x0)");
  if(pa("-estimate-image-size-only").as<bool>() || pa("-estimate-image-ar-only").as<bool>() || pa("-compute-optimal-scaling-size").as<bool>()){
    GenericGrabber g(pa("-input"));
    Size s = g.grab()->getSize();
    if(pa("-estimate-image-size-only")){
      std::cout << s << std::endl;
    }
    if(pa("-estimate-image-ar-only")){
      std::cout << float(s.width)/float(s.height) << std::endl;
    }
    if(pa("-compute-optimal-scaling-size")){
      int W = pa("-compute-optimal-scaling-size");
      Size sinput = pa("-compute-optimal-scaling-size-input-size");
      if(sinput == Size(0,0)) sinput = s;
      float f = float(W)/float(sinput.width);
      std::cout << Size(W,round(sinput.height * f)) << std::endl;
    }

    return 0;
  }
  ICLApp app(n,args,"",init,run);
  int result = app.exec();
  std::cout << lastRect << std::endl;
  return result;
}
Exemplo n.º 12
0
void init(){
  gui << Image().handle("image").minSize(16,12);
  gui << ( HBox().maxSize(100,2)
           << Fps(10).handle("fps").maxSize(100,2).minSize(5,2)
           << CamCfg("")
           )
      << Show();

  grabber.init(pa("-i"));
  if(pa("-size")){
    grabber.useDesired<Size>(pa("-size"));
  }

}
Exemplo n.º 13
0
void force_pte(pte_t *pmle, int flags) {
    if (!pte_present(*pmle)) {
        void *npg;
        if (flags & USE_BOOT_ALLOCATE) {
            npg = get_mem(PAGE_SIZE, PAGE_SIZE);
        } else {
            npg = get_page0(0);
        }

        assert(npg != 0);
        assert((pa(npg) & ((1 << 12) - 1)) == 0);

        *pmle = pa(npg) | PTE_PRESENT | PTE_WRITE;
    }
}
Exemplo n.º 14
0
// virtual
void SmallRuler::paintEvent(QPaintEvent *e)
{

    QPainter p(this);
    QRect r = e->rect();
    p.setClipRect(r);

    double f, fend;
    p.setPen(palette().dark().color());

    const int zoneStart = (int)(m_zoneStart * m_scale);
    const int zoneEnd = (int)(m_zoneEnd * m_scale);

    p.fillRect(zoneStart, height() / 2, zoneEnd - zoneStart, height() / 2, m_zoneColor);

    if (r.top() < 9) {
        // draw the little marks
        fend = m_scale * m_small;
        if (fend > 2) for (f = 0; f < width(); f += fend) {
                p.drawLine((int)f, 1, (int)f, 3);
            }

        // draw medium marks
        fend = m_scale * m_medium;
        if (fend > 2) for (f = 0; f < width(); f += fend) {
                p.drawLine((int)f, 1, (int)f, 5);
            }
    }

    // draw pointer
    QPolygon pa(3);
    pa.setPoints(3, m_cursorPosition - 5, 14, m_cursorPosition + 5, 14, m_cursorPosition/*+0*/, 9);
    p.setBrush(palette().dark().color());
    p.drawPolygon(pa);
}
Exemplo n.º 15
0
static void		place(t_env *env, t_sort *s)
{
	pa(env);
	s->j++;
	s->k++;
	set_direction(env, s);
}
Exemplo n.º 16
0
void VariableCapacitor::drawShape(QPainter &p) {
	initPainter(p);

	// Get centre point of component.
	int _y = (int)y();
	int _x = (int)x();

	p.drawRect(_x - 8, _y - 8, 5, 16);
	p.drawRect(_x + 3, _y - 8, 5, 16);

// 	p.drawLine( _x-8, _y, _x-16, _y );
// 	p.drawLine( _x+8, _y, _x+16, _y );

	// Diagonally pointing arrow
	QPointArray pa(3);
	pa[0] = QPoint(-4, 0);
	pa[1] = QPoint(-2, 4);
	pa[2] = QPoint(0, 0);

	pa.translate(_x + 16, _y - 8);
	p.setBrush(p.pen().color());
	p.drawPolygon(pa);

	p.drawLine(_x - 16, _y + 8, _x + 16, _y - 8);

	deinitPainter(p);
}
Exemplo n.º 17
0
int main()
{
    cout << "main()" << endl;
    pointer_fun(3,6);

    std::shared_ptr<short> pa(new short(3));
    std::shared_ptr<short> pb(new short(9));
    short val = greater_val(pa, pb);
    std::cout << "Greater_val test: " << val  << endl;


//    set<string> people;
//    people.insert("Tommy");
//    std::string myname = "Jill";
//    people.insert(myname);
//    people.insert("Johnny");
//    for(set<string>::iterator it=people.begin();
//        it != people.end();
//        ++it){
//        cout << "Person: " << *it << endl;
//    }
//    myname = "Tommy";
//    if(people.find(myname) != people.end()){
//        cout<< "Tommy is a CS/CECS major!" << endl;
//    }
//    else {
//        cout<< "Tommy is the wrong major!" << endl;
//    }
//    myname = "Johnny";
//    people.erase("Johnny");
}
Exemplo n.º 18
0
inline Q3PointArray arrowPoints( int dir )
{
	Q3PointArray pa(3);
	switch ( dir ) {
		case 0:
			pa[0] = QPoint( 3, 0 );
			pa[1] = QPoint( 0, 2 );
			pa[2] = QPoint( 0, -2 );
			break;
		case 180:
			pa[0] = QPoint( -3, 0 );
			pa[1] = QPoint( 0, 2 );
			pa[2] = QPoint( 0, -2 );
			break;
		case 90:
			pa[0] = QPoint( 2, 0 );
			pa[1] = QPoint( -2, 0 );
			pa[2] = QPoint( 0, 3 );
			break;
		case 270:
			pa[0] = QPoint( 2, 0 );
			pa[1] = QPoint( -2, 0 );
			pa[2] = QPoint( 0, -3 );
			break;
	};
	return pa;
}
Exemplo n.º 19
0
void			naive_algo(t_stack *stack)
{
    t_ilist *tmp;
    int		i;
    int		min;

    while (stack->number_in_a)
    {
        i = 0;
        tmp = stack->a_begin;
        min = tmp->data;
        while (tmp)
        {
            min = (min > tmp->data) ? tmp->data : min;
            tmp = tmp->next;
        }
        tmp = stack->a_begin;
        while (tmp && min != tmp->data)
        {
            tmp = tmp->next;
            ++i;
        }
        spam_rotation(stack, i, min);
        pb(stack);
    }
    while (stack->number_in_b)
        pa(stack);
}
Exemplo n.º 20
0
void ScrobWrapper::Start(LPCTSTR artist, LPCTSTR track, LPCTSTR album, LPCTSTR musicbrainzID, INT Length, LPCTSTR path)
{
	if (m_pScrobbler == NULL)
	{
		ASSERT(m_Err == ERR_UnInitialized);
		m_Err = ERR_Success;
		m_pScrobbler = new ScrobSubmitter;
		m_pScrobbler->Init(scrobId, &ScrobWrapper::ScrobCallbackSt, this);
	}
#ifdef UNICODE
	CHAR bf[MAX_PATH * 4]; 
	bf[EncodingUtils::UnicodeToUtf8(artist, (INT)_tcslen(artist), bf, MAX_PATH * 4)]=0;
	std::string ar(bf);
	bf[EncodingUtils::UnicodeToUtf8(track, (INT)_tcslen(track), bf, MAX_PATH * 4)]=0;
	std::string tr(bf);
	bf[EncodingUtils::UnicodeToUtf8(album, (INT)_tcslen(album), bf, MAX_PATH * 4)]=0;
	std::string al(bf);
	bf[EncodingUtils::UnicodeToUtf8(musicbrainzID, (INT)_tcslen(musicbrainzID), bf, MAX_PATH * 4)]=0;
	std::string mb(bf);
	bf[EncodingUtils::UnicodeToUtf8(path, (INT)_tcslen(path), bf, MAX_PATH * 4)]=0;
	std::string pa(bf);
	m_pScrobbler->Start(ar, tr, al, mb, Length, pa);
#else
	m_pScrobbler->Start(artist, track, album, musicbrainzID, Length, path);
#endif

}
Exemplo n.º 21
0
void ConnectorTest::allocatorConstructorTest()
{
	{
		PoolAllocator pa(1, 8 * 1024, 21);
		TestStorageHooks tsh(&pa);

		Connector connector(GetConfig()["SocketConnectSuccessHost"]["ip"].AsString(), GetConfig()["SocketConnectSuccessHost"]["port"].AsLong(), 0L, String(), 0L, true);
		Socket *socket = connector.MakeSocket();

		if ( t_assert( socket != NULL ) && t_assertm(&pa == socket->fAllocator, "allocator should match") ) {
			long socketfd = socket->GetFd();
			t_assert( socketfd > 0 );

			std::iostream *Ios = socket->GetStream();
			t_assert( Ios != NULL);
		}
		delete socket;
	}
	{
		TestStorageHooks tsh(coast::storage::Global());

		Connector connector(GetConfig()["SocketConnectSuccessHost"]["ip"].AsString(), GetConfig()["SocketConnectSuccessHost"]["port"].AsLong(), false);
		Socket *socket = connector.MakeSocket();

		if ( t_assert( socket != NULL ) && t_assertm(coast::storage::Global() == socket->fAllocator, "allocator should match") ) {
			long socketfd = socket->GetFd();
			t_assert( socketfd > 0 );

			std::iostream *Ios = socket->GetStream();
			t_assert( Ios != NULL);
		}
		delete socket;
	}
}
Exemplo n.º 22
0
int
ampi::winPut(void *orgaddr, int orgcnt, MPI_Datatype orgtype, int rank,
             MPI_Aint targdisp, int targcnt, MPI_Datatype targtype, WinStruct win) {
    // Create a Future object
    AmpiMsg *msg = new AmpiMsg();
    CkFutureID ftHandle = CkCreateAttachedFuture((void*)msg);
    AMPI_DEBUG("    Created Future with handle %d\n", ftHandle);

    CProxy_ampi pa(thisArrayID);

    CkDDT_DataType *ddt = getDDT()->getType(orgtype);
    int orgtotalsize = ddt->getSize(orgcnt);
    char* sorgaddr = (char*)new char[orgtotalsize];
    ddt->serialize((char*)orgaddr, (char*)sorgaddr, orgcnt, 1);

    pa[rank].winRemotePut(orgtotalsize, (char*)sorgaddr, orgcnt, orgtype, targdisp, targcnt, targtype,
                          win.index, ftHandle, CkMyPe());

    // Wait on the Future object
    AMPI_DEBUG("    Future [%d] waiting\n", ftHandle);
    msg = (AmpiMsg*)CkWaitFutureID(ftHandle);
    AMPI_DEBUG("    Future [%d] awaken\n", ftHandle);

    delete [] sorgaddr;
    return MPI_SUCCESS;
}
Exemplo n.º 23
0
int
ampi::winAccumulate(void *orgaddr, int orgcnt, MPI_Datatype orgtype, int rank,
                    MPI_Aint targdisp, int targcnt, MPI_Datatype targtype,
                    MPI_Op op, WinStruct win) {
    // Create a Future object
    AmpiMsg *msg = new AmpiMsg();
    CkFutureID ftHandle = CkCreateAttachedFuture((void*)msg);
    AMPI_DEBUG("    Created Future with handle %d\n", ftHandle);

    // Send the request to data and handle of Future to remote side
    CProxy_ampi pa(thisArrayID);

    CkDDT_DataType *ddt = getDDT()->getType(orgtype);
    int orgtotalsize = ddt->getSize(orgcnt);
    char* sorgaddr = (char*)new char[orgtotalsize];
    ddt->serialize((char*)orgaddr, (char*)sorgaddr, orgcnt, 1);

    AMPI_DEBUG("    Rank[%d:%d] invoke Remote accumulate at [%d]\n", thisIndex, myRank, rank);
    pa[rank].winRemoteAccumulate(orgtotalsize, (char*)orgaddr, orgcnt, orgtype, targdisp, targcnt, targtype,  op, win.index, ftHandle, CkMyPe());

    // Wait on the Future object
    AMPI_DEBUG("    Future [%d] waiting\n", ftHandle);
    msg = (AmpiMsg*)CkWaitFutureID(ftHandle);
    AMPI_DEBUG("    Future [%d] awaken\n", ftHandle);

    return MPI_SUCCESS;
}
Exemplo n.º 24
0
int
ampi::winGet(void *orgaddr, int orgcnt, MPI_Datatype orgtype, int rank,
             MPI_Aint targdisp, int targcnt, MPI_Datatype targtype, WinStruct win) {
    // Create a Future object
    AmpiMsg *msg = new AmpiMsg();
    CkFutureID ftHandle = CkCreateAttachedFuture((void*)msg);
    AMPI_DEBUG("    Created Future with handle %d\n", ftHandle);

    // Send the request to data and handle of Future to remote side
    CProxy_ampi pa(thisArrayID);
    AMPI_DEBUG("    Rank[%d:%d] invoke Remote get at [%d]\n", thisIndex, myRank, rank);
    CkDDT_DataType *ddt = getDDT()->getType(orgtype);
    int orgtotalsize = ddt->getSize(orgcnt);
    char* sorgaddr = (char*)new char[orgtotalsize];

    pa[rank].winRemoteGet(orgcnt, orgtype, targdisp, targcnt, targtype, win.index, ftHandle, CkMyPe());

    // Wait on the Future object
    AMPI_DEBUG("    Future [%d] waiting\n", ftHandle);
    msg = (AmpiMsg*)CkWaitFutureID(ftHandle);
    AMPI_DEBUG("    Future [%d] awaken\n", ftHandle);

    // Process the reply message and copy the data into desired memory position
    memcpy(sorgaddr, msg->data, orgtotalsize);
    ddt->serialize((char*)orgaddr, (char*)sorgaddr, orgcnt, (-1));
    AMPI_DEBUG("    Rank[%d] got win  [%d] \n", thisIndex, *(int*)msg->data);
    AMPI_DEBUG("    Rank[%d] got win  [%d] , size %d\n", thisIndex, *(int*)orgaddr, orgcnt);
    delete [] sorgaddr;
    return MPI_SUCCESS;
}
Exemplo n.º 25
0
bool Check2point(POINT p1,POINT p2)
{
	CChessPoint pa(p1) , pb(p2);
	CChessPoint pc(p1),  pb(p2);
	int x,y;
	POINT p3,p4;

	if(p1.y == p2.y)
	{
		if(CheckLine(pa.m_rightPoint ,pb.m_leftPoint))
		//	return true;
		p3 =p1;
		p4 =p2;
		for(y = 0; y<11;y++)
		{
			p3.y  = p4.y -y;
		}
	}

	if(p1.x == p2.x)
	{
		if(CheckLine(pa.m_downPoint ,pb.m_upPoint))
			return true;
	}

	return false;
}
Exemplo n.º 26
0
void		ft_suite_de_merde(unsigned int i, char op, t_swap **ba, t_swap **bb)
{
	if (i % 8 == 5)
	{
		ft_putstr("sb ");
		op ? sb(bb) : 0;
	}
	else if (i % 8 == 6)
	{
		ft_putstr("rb ");
		op ? rb(bb) : 0;
	}
	else if (i % 8 == 7)
	{
		ft_putstr("rrb ");
		op ? rrb(bb) : 0;
	}
	else if (i % 8 == 3)
	{
		ft_putstr("pa ");
		op ? pa(ba, bb) : 0;
	}
	else if (i % 8 == 4)
	{
		ft_putstr("pb ");
		op ? pb(bb, ba) : 0;
	}
}
bool clip(const IsoRectangle& r, Segment& s)
{
    typedef typename Segment::R R;
    typedef typename R::FT FT;
    typedef typename R::Point_2 Point;
    typedef typename R::Vector_2 Vector;

    const Point& p(s.source());
    const Point& q(s.target());
    Vector d(q-p);
    FT a[] = { p.x(), p.y() };
    FT b[] = { q.x(), q.y() };
    FT tmin = 0, tmax = 1;
    for(int i=0; i<2; ++i) {
      if(d[i]==0 && (p[i]<r.min()[i] || p[i]>r.max()[i])) {
        return false;
      } else {
        int j = 1-i, k = (d[i] > 0);
        int l = 1-k;
	FT m[] = {r.min()[i], r.max()[i]}, t;
        t = (m[l]-p[i])/d[i];
        if(t>tmin) { tmin=t; a[i]=m[l];  a[j]=p[j]+t*d[j]; } // a=p+td
        t = (m[k]-p[i])/d[i];
        if(t<tmax) { tmax=t; b[i]=m[k];  b[j]=p[j]+t*d[j]; } // b=p+td
        if(tmax <= tmin) return false;
      }
    }
    Point pa(a[0],a[1]);
    Point pb(b[0],b[1]);
    s = Segment(pa,pb);
    return true;
}
Exemplo n.º 28
0
/*!
  Draw lines from the pole

  \param painter Painter
  \param canvasRect Contents rect of the canvas in painter coordinates
  \param pole Position of the pole in painter coordinates
  \param radius Length of the lines in painter coordinates
  \param azimuthMap Maps azimuth values to values related to 0.0, M_2PI
  \param values Azimuth values, indicating the direction of the lines
*/
void QwtPolarGrid::drawRays(
  QPainter *painter, const QwtDoubleRect &canvasRect,
  const QwtDoublePoint &pole, double radius,
  const QwtScaleMap &azimuthMap, const QwtValueList &values ) const
{
  for ( int i = 0; i < int( values.size() ); i++ )
  {
    double azimuth = azimuthMap.xTransform( values[i] );
    azimuth = ::fmod( azimuth, 2 * M_PI );

    bool skipLine = false;
    if ( testDisplayFlag( SmartScaleDraw ) )
    {
      const QwtAbstractScaleDraw::ScaleComponent bone =
        QwtAbstractScaleDraw::Backbone;
      if ( isClose( azimuth, 0.0 ) )
      {
        const AxisData &axis = d_data->axisData[QwtPolar::AxisRight];
        if ( axis.isVisible && axis.scaleDraw->hasComponent( bone ) )
          skipLine = true;
      }
      else if ( isClose( azimuth, M_PI / 2 ) )
      {
        const AxisData &axis = d_data->axisData[QwtPolar::AxisTop];
        if ( axis.isVisible && axis.scaleDraw->hasComponent( bone ) )
          skipLine = true;
      }
      else if ( isClose( azimuth, M_PI ) )
      {
        const AxisData &axis = d_data->axisData[QwtPolar::AxisLeft];
        if ( axis.isVisible && axis.scaleDraw->hasComponent( bone ) )
          skipLine = true;
      }
      else if ( isClose( azimuth, 3 * M_PI / 2.0 ) )
      {
        const AxisData &axis = d_data->axisData[QwtPolar::AxisBottom];
        if ( axis.isVisible && axis.scaleDraw->hasComponent( bone ) )
          skipLine = true;
      }
    }
    if ( !skipLine )
    {
      const QwtDoublePoint pos = qwtPolar2Pos( pole, radius, azimuth );

      /*
          Qt4 is horrible slow, when painting primitives,
          with coordinates far outside the visible area.
       */

      QwtPolygon pa( 2 );
      pa.setPoint( 0, pole.toPoint() );
      pa.setPoint( 1, pos.toPoint() );

      if ( testDisplayFlag( ClipGridLines ) )
        pa = QwtClipper::clipPolygon( canvasRect.toRect(), pa );

      QwtPainter::drawPolyline( painter, pa );
    }
  }
}
Exemplo n.º 29
0
void Main::addSpline()
{
    const int size = int(canvas.width()/6);

    Q3PointArray pa(12);
    pa[0] = QPoint(0,0);
    pa[1] = QPoint(size/2,0);
    pa[2] = QPoint(size,size/2);
    pa[3] = QPoint(size,size);
    pa[4] = QPoint(size,size*3/2);
    pa[5] = QPoint(size/2,size*2);
    pa[6] = QPoint(0,size*2);
    pa[7] = QPoint(-size/2,size*2);
    pa[8] = QPoint(size/4,size*3/2);
    pa[9] = QPoint(0,size);
    pa[10]= QPoint(-size/4,size/2);
    pa[11]= QPoint(-size/2,0);

    QPainterPath path;
    path.moveTo(pa[0]);
    for (int i = 1; i < pa.size(); i += 3)
        path.cubicTo(pa[i], pa[(i + 1) % pa.size()], pa[(i + 2) % pa.size()]);

    QGraphicsPathItem* item = canvas.addPath(path);
    item->setFlag(QGraphicsItem::ItemIsMovable);
    item->setPen(Qt::NoPen);
    item->setBrush( QColor(qrand()%32*8,qrand()%32*8,qrand()%32*8) );
    item->setPos(qrand()%int(canvas.width()),qrand()%int(canvas.height()));
    item->setZValue(qrand()%256);
}
// TODO: can this algorithm fail for obtuse triangle if both mu & lambda < 0?
//
// rht this function was inlined
int  cisstTriangleClosestPointSolver::FindClosestPointOnTriangle(	const vct3& a, 
																	const vct3& p,
																	const vct3& q,
																	const vct3& r,
																	double distBound, // -1 if ignore
																	vct3& ret)
	{ 
		vct3 pa=a-p; // b(0)=pa.x; b(1)=pa.y; b(2)=pa.z;
		vct3 pq=q-p; // A(0,0)=pq.x; A(1,0)=pq.y; A(2,0)=pq.z;
		vct3 pr=r-p; // A(0,1)=pr.x; A(1,1)=pr.y; A(2,1)=pr.z;
		for (int i=0;i<3;i++) 
			{ b(i)=pa(i); A(i,0)=pq(i); A(i,1)=pr(i); 
			B(i,0)=b(i);  // because using dumb interface to solver
			};		
		LeastSquaresSolver.Solve(A,B);		     // replace with HFTI call when can do so
		double lambda=B(0,0); double mu=B(1,0);	 // ditto
		// nmrAlgorithmHFTI(A,h,P,Tau,g,b,x,0);  // x := lambda and mu		double lambda = x(0);
		// double lambda=x(0);
		// double mu = x(1);
		vct3 c = p+pq*lambda+pr*mu;
		if (distBound >= 0.0) 
		{ double dist = (c-a).Norm();
			if (dist>distBound) 
			{ ret=c; return 0; };
		};
		if (lambda<=0.0)		{ ret =  ProjectOnSegment(c,r,p); return 1; };
		if (mu <=0.0)			{ ret =  ProjectOnSegment(c,p,q); return 2; };
		if (lambda+mu> 1.0 )	{ ret =  ProjectOnSegment(c,q,r); return 3; };
		ret= c; return 4;
  };