Example #1
0
ListaContato *pop(ListaContato* head, TpContato contato){
	ListaContato *pop = init(),
				 *previous = init(),
				 *next = init();

	pop = find(head,contato);

	if (pop==NULL){
		return head;
	}
	previous = pop->prev;
	next = pop->next;

	if (previous == NULL){
		if (next == NULL) {
			head=init();
		}else{
			next->prev = init();
			head=next;
		}
	}else{
		if (next == NULL) {
			previous->next = NULL;
		}else{
			previous->next = next;
			next->prev = previous;
		}
	}
	free(pop);
	return head;
}
Example #2
0
ListaContato *push(ListaContato* head, char nome[], char fone[]){
	ListaContato 	*this=head,
		 			*previous=init(),
		 			*novo = init();

	novo = (ListaContato *) malloc(sizeof(ListaContato));
	strcpy(novo->contato.nome,nome);
	strcpy(novo->contato.fone,fone);
	
	
	while(this!=NULL){
		previous = this;
		this = this->next;
	}	
	if (previous != NULL){
		if (previous->next != NULL){
			novo->prev = previous;
			novo->next = previous->next;
			previous->next = novo;
			return head;
		}else{
			novo->prev = previous;
			novo->next = init();
			previous->next = novo;
			return head;
		}
	}else if (this==head){
		novo->next = head;
		novo->prev = init();
		return novo;
	}
	return head;
}
Example #3
0
void combSort_lista(ListaContato* head, int tam){
	int gap = tam,
		swap = FALSE,
		n;
	
	ListaContato *i = init(),
				 *j = init();

	TpContato aux;

	while(gap > 1 || swap == TRUE){
		gap = (int) gap / 1.3;
		if (gap < 1) gap = 1;
		swap = FALSE;
		
		i = head;
		j = i;

		for (n=0;n<gap;n++){
			j=j->next;
		}

		for(; j!=NULL; i=i->next, j=j->next){
			if (strcmp(i->contato.nome,j->contato.nome) > 0){
				aux  = i->contato;
				i->contato = j->contato;
				j->contato = aux;
				swap = TRUE;
			}
		}
	}
}
Example #4
0
void FenvikCreate(int nn,fen *t,fen *a)
{
    a->f.assign(nn,0);
 for(int i=0;i<nn;i++)
 {cout<<"Введите элемент: ";
  cin>>a->f[i];

}

init(nn,t,a);
init(t,a);

cout<<"Исходный массив: ";
 for(int i=0;i<nn;i++)
 {
    cout<<a->f[i]<<" ";
 }

cout<<endl<<"Дерево Фенвика: ";
 for(int i=0;i<nn;i++)
 {
    cout<<t->f[i]<<" ";
 }


}
Example #5
0
int main()
{
    load(config);
    load(config.config(), config);

    Module *input = init(config.input());
    Module *output = init(config.output());

    if(config.verbose())
    {
        pretty_print(clog, config);

        v1 = viewer()
             .size(config.width(), config.height())
             .layer(1)
             .name("Distorted points")
             .pen_width(3)
             .pen_color(red)
             ;
        v2 = viewer()
             .layer(2)
             .name("Undistorted points")
             .show(false)
             .pen_color(blue)
             ;
        v3 = viewer()
             .layer(3)
             .name("Proposed points")
             .pen_color(green)
             ;
    }
    for(double x = 0; x < config.width(); x += config.step())
        for(double y = 0; y < config.height(); y += config.step())
        {
            Error e;
            e.p2 << x, y;
            input->init(e);
            output->add(e);

            if(config.verbose())
            {
                Array2d p = e.p3.head<2>().array() * config.focal() + config.center();

                v1.add_point(e.p2.x(), e.p2.y());
                v2.add_line(e.p2.x(), e.p2.y(), p.x(), p.y());
            }
        }
    if(config.verbose())
    {
        v1.update();
        v2.update();
        output->run_verbose();
        v3.title("Done, you can now close this window");
        wait_viewers();
    }
    else
    {
        output->run();
    }
}
Example #6
0
ChangeVisibility::ChangeVisibility(const QVariantMap& data, QObject *parent) :
    Action(data, parent)
{
    QString type("Show");
    if (data.contains("type") && data.value("type").type() == QVariant::String)
        type = data.value("type").toString();

    if (type == "Hide")
        init(false);
    else
        init(true);

    if (data.contains("transitions") && data.value("transitions").type() == QVariant::List ) {
        QVariantList transitions = data.value("transitions").toList();
        for(int i=0; i <transitions.size(); i++ ) {
            if (transitions[i].type() != QVariant::Map)
                continue;
            QVariantMap data = transitions[i].toMap();
            if (data.contains("type") && data.value("type") == "Fade")
                mFadeAction = qobject_cast<Fade*>(ActionInfoManager::typeToAction(data, this));
            if (data.contains("type") && data.value("type") == "Slide")
                mSlideAction = qobject_cast<Slide*>(ActionInfoManager::typeToAction(data, this));
        }
    }
}
void SmoothEscortAI::StartMove()
{
    if (HasEscortState(ESCORT_STATE_PAUSED) || HasEscortState(ESCORT_STATE_NONE) || HasEscortState(ESCORT_STATE_COMBAT))
        return;

    if (currentWP->jump)
    {
        float moveTimeHalf = speedZ / Movement::gravity;
        float max_height = -Movement::computeFallElevation(moveTimeHalf,false,-speedZ);
        Movement::MoveSplineInit init(me);
        init.MoveTo(currentWP->x, currentWP->y, currentWP->z);
        init.SetParabolic(max_height,0);
        init.SetVelocity(speedXY);
        init.Launch();
    }
    else
    {
        Movement::MoveSplineInit init(me);
        init.MoveTo(currentWP->x, currentWP->y, currentWP->z);
        init.SetWalk(!isRunning);
        init.Launch();
    }

    nextMoveTime.Reset(me->GetSplineDuration());
    StartMoveTo(currentWP->x, currentWP->y, currentWP->z);
}
/** maxthread is treated as the "maximum" number of worker threads. */
void InitializeAndTerminate( int maxthread ) {
    for( int i=0; i<200; ++i ) {
        switch( i&3 ) {
            default: {
                tbb::task_scheduler_init init( std::rand() % maxthread + 1 );
                ASSERT(init.is_active(), NULL);
                break;
            }
            case 0: {   
                tbb::task_scheduler_init init;
                ASSERT(init.is_active(), NULL);
                break;
            }
            case 1: {
                tbb::task_scheduler_init init( tbb::task_scheduler_init::automatic );
                ASSERT(init.is_active(), NULL);
                break;
            }
            case 2: {
                tbb::task_scheduler_init init( tbb::task_scheduler_init::deferred );
                ASSERT(!init.is_active(), "init should not be active; initialization was deferred");
                init.initialize( std::rand() % maxthread + 1 );
                ASSERT(init.is_active(), NULL);
                init.terminate();
                ASSERT(!init.is_active(), "init should not be active; it was terminated");
                break;
            }
        }
    }
}
Example #9
0
	void bar_widget::handle_process()
	{
		if(animating_) {
			int end_point_unscaled = animation_end_point_unscaled_ * segment_length_;
			if(animation_end_point_unscaled_ > 0) {
				// gaining segments
				animation_current_position_ += (1.0 / drain_rate_) * segment_length_;
				if(animation_current_position_ >= end_point_unscaled) {
					animation_current_position_ = 0;
					drained_segments_ = drained_segments_after_anim_;
					init();
					animating_ = false;
				}
			} else {
				// loosing segments
				animation_current_position_ -= (1.0 / drain_rate_) * segment_length_;
				if(animation_current_position_ <= end_point_unscaled) {
					animation_current_position_ = 0;
					drained_segments_ = drained_segments_after_anim_;
					init();
					animating_ = false;
				}
			}
		}

		widget::handle_process();
	}
Example #10
0
int
main(int argc, char **argv)
{

	space(0,0,4096,4096);
	init(&xd);
	init(&yd);
	xd.xsize = yd.xsize = 1.;
	xx = (struct val *)malloc((unsigned)sizeof(struct val));
	labsarr = malloc(1);
	labsarr[labsiz++] = 0;
	setopt(argc,argv);
	if(erasf)
		erase();
	readin();
	transpose();
	scale(&xd,(struct val *)&xx->xv);
	scale(&yd,(struct val *)&xx->yv);
	axes();
	title();
	plot();
	move(1,1);
	closevt();
	return(0);
}
Example #11
0
void io_stream_t::init() {
	netaddr_t const &netaddr = bind_addr();

	fd = socket(netaddr.sa->sa_family, SOCK_STREAM, 0);
	if(fd < 0)
		throw exception_sys_t(log::error, errno, "socket: %m");

	try {
		bq_fd_setup(fd);
		fd_setup(fd);

		if(reuse_addr) {
			int i = 1;
			if(setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i)) < 0)
				throw exception_sys_t(log::error, errno, "setsockopt, SO_REUSEADDR, 1: %m");
		}

		if(::bind(fd, netaddr.sa, netaddr.sa_len) < 0)
			throw exception_sys_t(log::error, errno, "bind: %m");

		if(::listen(fd, listen_backlog) < 0)
			throw exception_sys_t(log::error, errno, "listen: %m");

	}
	catch(...) {
		::close(fd);
		fd = -1;
		throw;
	}

	stat.init();
	proto.init(name);
}
Example #12
0
bool Video::seek(double seconds)
{
	// get the destination in pts
	FrameIndex destination = static_cast<FrameIndex>(round(seconds / _streamTimeBase + _startPts));
	if (DEBUGOUT) std::cout << "##### seek(" << seconds << ") => pts: " << destination << std::endl;

	// if we are very close to the begin, we close and re-open the video sequence
	if (seconds <= 1.25 * ffpp::InputFormatContext::SAFE_SEEK_SECONDS) {
		if (DEBUGOUT) std::cout << "# re-opening video sequence" << std::endl;
		cleanup();
		init();
	}
	else {
		try {
			//_inFormatCtx->Seek(static_cast<float>(seconds + _startPts * _streamTimeBase));
			_inFormatCtx->Seek(*_inStream, destination);
		}
		catch (std::exception& e) {
			if (DEBUGOUT) std::cout << "# re-opening video sequence and seeking frame-by-frame" << std::endl;
			cleanup();
			init();
			return advance(seconds);
		}
	}

	// if we seeked to the first frame, we don't need to call advance :)
	if (fuzzyGreaterEqual(0.0, seconds))
		return true;

	// call advance to go frame by frame to the correct position
	return advance(seconds, true);
}
Example #13
0
File: font.cpp Project: Try/Tempest
Tempest::FontElement::FontElement() {
#ifdef __ANDROID__
  init("/system/fonts/DroidSans", 16);
#else
  init("./data/arial", 16);
#endif
  }
Example #14
0
// Called when a key is pressed. x, y is the current mouse position.
void callbackKeyboard(unsigned char key, int x, int y)
{
    switch(key)
    {
    case 'q':
    case 'Q':
    case 27:
        exit(0);
        break;
    case '1':
        showGasket = 1;
        Color = 0;
        init();
        break;
    case '2':
        showGasket = 1;
        Color = 1;
        init();
        break;
    case '3':
        showGasket = 0;
        init();
        break;
    case 'r':
    case 'R':
        Theta += 30;
        break;
    }
}
void QMQTT::ClientPrivate::init(const QString& hostName, const quint16 port, const bool ssl,
                                const bool ignoreSelfSigned)
{
    _hostName = hostName;
    _port = port;
    if (ssl)
    {
#ifndef QT_NO_SSL
        QSslConfiguration sslConf = QSslConfiguration::defaultConfiguration();
        QList<QSslCertificate> certs = QSslCertificate::fromPath(QStringLiteral("./cert.crt"));
        if (!certs.isEmpty())
            sslConf.setLocalCertificate(certs.first());
        QFile file(QStringLiteral("./cert.key"));
        if (file.open(QIODevice::ReadOnly)) {
            sslConf.setPrivateKey(QSslKey(file.readAll(), QSsl::Rsa));
        }
        sslConf.setPeerVerifyMode(QSslSocket::VerifyNone);
#if QT_VERSION < 0x050000
        sslConf.setProtocol(QSsl::TlsV1);
#endif
        init(hostName, port, sslConf, ignoreSelfSigned);
#else
        Q_UNUSED(ignoreSelfSigned)
        qCritical() << "SSL not supported in this QT build";
#endif // QT_NO_SSL
    }
    else
    {
        init(new Network);
    }
}
Example #16
0
int main(int argc,char *argv[])
{

	init();

	struct sembuf sops[2];
	
	sops[0].sem_num = 0;
	sops[0].sem_op = -1;
	sops[0].sem_flg = 0;

	sops[1].sem_num = 1;
	sops[1].sem_op = 1;
	sops[1].sem_flg = 0;

	init();
	

	printf("this is customer\n");
	while(1)
	{
		printf("\n\nbefore consume:\n");
		printf("productor is %d\n",semctl(sem_id,0,GETVAL));
		printf("space  is %d\n",semctl(sem_id,1,GETVAL));
		
		semop(sem_id,(struct sembuf *)&sops[0],1);		//get the productor to cusume
		printf("now consuming......\n");
		semop(sem_id,(struct sembuf *)&sops[1],1);		//now tell the productor can bu produce
		
		printf("\nafter consume\n");
		printf("products number is %d\n",semctl(sem_id,0,GETVAL));
		printf("space number is %d\n",semctl(sem_id,1,GETVAL));
		sleep(3);
	}
}
Example #17
0
void keyboard(unsigned char key, int x, int y)
{
    switch (key) {
        case 27:
            break;
        case 'q':
            exit(0);
            break;
        case '0':		// draw polygons as outlines
            lineDrawing = 1;
            lighting = 0;
            smoothShading = 0;
            init();
            display();
            break;
        case '1':		// diffuse and specular lighting, flat shading, swap textures
            lineDrawing = 0;
            lighting = 1;
            smoothShading = 1;
            
            currentTextureID++;
            if(currentTextureID >= NUMBER_OF_TEXTURES){
                currentTextureID = 0;
            }
            
            init();
            display();
            break;
    }
}
Example #18
0
void QBspTree::init(const QRect &area, int depth, NodeType type, int index)
{
    Node::Type t = Node::None; // t should never have this value
    if (type == Node::Both) // if both planes are specified, use 2d bsp
        t = (depth & 1) ? Node::HorizontalPlane : Node::VerticalPlane;
    else
        t = type;
    QPoint center = area.center();
    nodes[index].pos = (t == Node::VerticalPlane ? center.x() : center.y());
    nodes[index].type = t;

    QRect front = area;
    QRect back = area;

    if (t == Node::VerticalPlane) {
        front.setLeft(center.x());
        back.setRight(center.x() - 1); // front includes the center
    } else { // t == Node::HorizontalPlane
        front.setTop(center.y());
        back.setBottom(center.y() - 1);
    }

    int idx = firstChildIndex(index);
    if (--depth) {
        init(back, depth, type, idx);
        init(front, depth, type, idx + 1);
    }
}
Example #19
0
bool PListParser::init_with_path(string const& path)
{
    if (!fs::exists(path))
        return false;

#if defined(USE_BPLIST)
    utility::parser::PropertyList bplist;
    if (bplist.open(path))
    {
        m_stream << bplist.to_xml();
        return init();
    }
#endif

    ifstream ifs(path.c_str(), ios_base::binary);
    if (!ifs.is_open())
        return false;

    auto   size = size_t(fs::file_size(path));
    auto buffer = new char[size];
    ifs.read(buffer, size);
    stringstream ss;
    ss.write(buffer, size);
    delete [] buffer;

    return init(ss);
}
void MoveSpline::init_spline(MoveSplineInitArgs const& args)
{
    static SplineBase::EvaluationMode const modes[2] = { SplineBase::ModeLinear, SplineBase::ModeCatmullrom };
    if (args.flags.cyclic)
    {
        uint32 cyclic_point = 0;
        // MoveSplineFlag::Enter_Cycle support dropped
        //if (splineflags & SPLINEFLAG_ENTER_CYCLE)
        //cyclic_point = 1;   // shouldn't be modified, came from client
        spline.init_cyclic_spline(&args.path[0], args.path.size(), modes[args.flags.isSmooth()], cyclic_point, args.initialOrientation);
    }
    else
        spline.init_spline(&args.path[0], args.path.size(), modes[args.flags.isSmooth()], args.initialOrientation);

    // init spline timestamps
    if (splineflags.falling)
    {
        FallInitializer init(spline.getPoint(spline.first()).z);
        spline.initLengths(init);
    }
    else
    {
        CommonInitializer init(args.velocity);
        spline.initLengths(init);
    }

    /// @todo what to do in such cases? problem is in input data (all points are at same coords)
    if (spline.length() < minimal_duration)
    {
        TC_LOG_DEBUG("misc", "MoveSpline::init_spline: zero length spline, wrong input data?");
        spline.set_length(spline.last(), spline.isCyclic() ? 1000 : 1);
    }
    point_Idx = spline.first();
}
Example #21
0
int main(int argc, char **argv)
{
    //Initialize and create GLUT window
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_ALPHA);
    glutInitWindowPosition(0,0);
    glutInitWindowSize(500,300);
    mainWindow = glutCreateWindow("Lighthouse3D - GLUT Tutorial");

	// callbacks for main window
	glutDisplayFunc(renderScene0);
	glutReshapeFunc(reshape);
	glutIdleFunc(renderSceneAll);
	init();

	// sub windows
	subWindow1 = glutCreateSubWindow(mainWindow, border,border,width-2*border, height/2 - border*3/2);
	glutDisplayFunc(renderScenesw1);
	init();

	subWindow2 = glutCreateSubWindow(mainWindow, border,(height+border)/2,width/2-border*3/2, height/2 - border*3/2);
	glutDisplayFunc(renderScenesw2);
	init();

	subWindow3 = glutCreateSubWindow(mainWindow, (width+border)/2,(height+border)/2,width/2-border*3/2,height/2 - border*3/2);
	glutDisplayFunc(renderScenesw3);
	init();

    PlaySound("starwars.wav", NULL, SND_ASYNC|SND_FILENAME|SND_LOOP);

    //GLUT event processing loop
    glutMainLoop();
    return 1;
}
int main(int argc, char **argv)
{
    if (argc != 5) {
        std::cerr << "usage: " << argv[0] << " DIM_X DIM_Y DIM_Z REPEATS\n";
        return 1;
    }
    std::stringstream buf;
    for (int i = 1; i < argc; ++i) {
        buf << argv[i] << " ";
    }
    int dimX, dimY, dimZ, repeats;
    buf >> dimX;
    buf >> dimY;
    buf >> dimZ;
    buf >> repeats;

    int size = dimX * dimY * dimZ;
    std::vector<double> gridOld(size);
    std::vector<double> gridNew(size);
    init(&gridOld[0], dimX, dimY, dimZ);
    init(&gridNew[0], dimX, dimY, dimZ);

    benchmark(&gridOld, &gridNew, dimX, dimY, dimZ, repeats);

    print(&gridOld[0], dimX, dimY, dimZ);
}
Example #23
0
void back() {

     int is,hs;

     level = 2;

     init();

     while(level > 0) {

           hs = 1; is = 0;

           while(hs && !is) {

                 hs = successor();

                 if( hs ) is = valid();  
           } 

           if(hs) {

              if(solution()) {print();break;}

                   else 
                            {level++;init();}

           } else level--;
           
     }
}
Example #24
0
int main()
{
    init();
    struct sembuf sops[2];
    sops[0].sem_num = 0;
    sops[0].sem_op = -1; // product number
    sops[0].sem_flg = 0;
    sops[1].sem_num = 1;
    sops[1].sem_op = 1;	 // space number
    sops[1].sem_flg = 0;
    init();
    printf("this is customer\n");
    while(1) {
        printf("\nbefore custome:\n");
        printf("productor is %d\n",semctl(sem_id, 0, GETVAL));
        printf("space is %d\n",semctl(sem_id, 1, GETVAL));
        semop(sem_id, (struct sembuf *)&sops[0], 1);
        printf("after custome\n");
        semop(sem_id, (struct sembuf *)&sops[1], 1);
        printf("now tell productor\n");
        printf("productor is %d\n",semctl(sem_id, 0, GETVAL));
        printf("space is %d\n",semctl(sem_id, 1, GETVAL));
        sleep(3);
    }
}
void bt() {

     int hs, is;

     stack[1] = start_node;
  
     level = 2;

     init();

     while(level > 0) {

           hs = 1; is = 0;

           while(hs && !is) {

                 hs = succ();

                 if(hs) is = valid();
           } 

           if(hs) {

             if(sol()) print();

                else   {level++;init();}
 
           } else level--;
      
     }
     
};
Example #26
0
MessageMultiply::MessageMultiply(PdMessage *initMessage, PdGraph *graph) : MessageObject(2, 1, graph) {
  if (initMessage->getNumElements() > 0 &&
      initMessage->getElement(0)->getType() == FLOAT) {
    init(initMessage->getElement(0)->getFloat());
  } else {
    init(0.0f);
  }
}
Example #27
0
PulseAudio::PulseAudio() :
	Module("PulseAudio")
{
	moduleImg = QImage(":/PulseAudio");

	init("WriterEnabled", true);
	init("Delay", 0.1);
}
void init(int p,int s,int e){
int mid=(s+e)/2;
ps[p]=s;
pe[p]=e;
if(s==e)return;
init(p*2+1,s,mid);
init(p*2+2,mid+1,e);
}
Example #29
0
struct Thread_info *  ListThreads(HANDLE heap)
{
	HANDLE hThreadSnap = INVALID_HANDLE_VALUE,hProcess,hThread; 
	THREADENTRY32 te32; 
	MEMORY_BASIC_INFORMATION mbi;
	struct Thread_info *tinfo,*Start;
	
	hThreadSnap = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, 0 ); 
	if( hThreadSnap == INVALID_HANDLE_VALUE ) 
		return( FALSE ); 
	te32.dwSize = sizeof(THREADENTRY32 );
	if( !Thread32First( hThreadSnap, &te32 ) ) 
	{
		CloseHandle( hThreadSnap );     // Must clean up the snapshot object!
		return( FALSE );
	}	
	Start = init(heap);
	if(Start == 0)
	return 0;
	tinfo = Start;
	
	do
	{
		if(te32.th32ThreadID == GetCurrentThreadId())
		continue;
		
		
		tinfo->Tid = te32.th32ThreadID;
		tinfo->Pid = te32.th32OwnerProcessID;
		
		hThread = OpenThread(THREAD_ALL_ACCESS,0,tinfo->Tid);
		hProcess = OpenProcess(PROCESS_ALL_ACCESS,0,tinfo->Pid);
		
		if(hThread && hProcess)
		{
			tinfo->OEP = GetThreadStartAddress(hThread,hProcess);
			if(tinfo->OEP)
			{
				VirtualQueryEx(hProcess,tinfo->OEP,&mbi,sizeof(MEMORY_BASIC_INFORMATION));
				tinfo->ImageType = mbi.Type;
				tinfo->AllocationType = mbi.AllocationProtect;
			}
		}
		
		CloseHandle(hProcess);
		CloseHandle(hThread);
		
		
		tinfo->next = init(heap);
		if(tinfo->next == NULL)
		return 0;
		tinfo = tinfo->next;
	} while( Thread32Next(hThreadSnap, &te32 ) );
	CloseHandle( hThreadSnap );
	tinfo->Pid =-1;
	tinfo->Tid =-1;
	return Start;
}
Example #30
0
AudioCD::AudioCD() :
	Module("AudioCD"),
	cdioDestroyTimer(new CDIODestroyTimer)
{
	moduleImg = QImage(":/AudioCD");

	init("AudioCD/CDDB", true);
	init("AudioCD/CDTEXT", true);
}