예제 #1
0
파일: main.cpp 프로젝트: Eldar7/OOPcpp
int main()
{
	XList<int> list;
	XList<int>::iterator it;
	XList<int>::reverse_iterator rit;
	
	list.push_back(11);
	list.push_front(8);
	list.push_back(12);
	list.push_back(13);
	list.push_back(14);

	list.print();
	std::cout<<list.size()<<std::endl;

	it = list.begin();
	std::cout<<*(++it)<<std::endl;

	for (it = list.begin(); it != list.end(); ++it)
		std::cout<<*it<<" ";
	std::cout<<std::endl;

	for (rit = list.rbegin(); rit != list.rend(); ++rit)
		std::cout<<*rit<<" ";
	std::cout<<std::endl;

	it = list.end();

	return 0;
}
예제 #2
0
파일: main.cpp 프로젝트: kakty3/kostov-oop
int main(){
    XList<Shape*> shapes;
    Point * point1 = new Point(0., 2., "point_1");
    shapes.push_back(point1);
    Point * point2 = new Point(2., 2., "point_2");
    shapes.push_back(point2);
    Point * point3 = new Point(2., 0., "point_3");
    shapes.push_back(point3);
    Point * point4 = new Point(0., 0., "point_4");
    shapes.push_back(point4);

    Circle * circle = new Circle(point4, 10., "circle_1");
    shapes.push_back(circle);

    Rect * rect = new Rect(point1, point2, point3, point4, "rectangle");
    shapes.push_back(rect);

    try {
        Square * square = new Square(point1, point2, point3, point4, "square");
        shapes.push_back(square);
    } catch (const char* error){
        // std::cout << "EXCEPTION RAISED: " << error << std::endl;
    }


    Polyline * polyline = new Polyline("polyline");
    polyline->AddPoint(point1);
    polyline->AddPoint(point2);
    polyline->AddPoint(point3);
    polyline->AddPoint(point4);
    shapes.push_back(polyline);

    for (XList<Shape*>::iterator it = shapes.begin(); it != NULL; ++it) {
        std::cout << *it;
    }
    printf("Number of shapes = %d\n", Shape::GetCount());
    for (XList<Shape*>::iterator it = shapes.begin(); it != NULL; ++it) {
        delete *it;
    }
    printf("Number of shapes = %d\n", Shape::GetCount());
    return 0;
}
예제 #3
0
파일: main.cpp 프로젝트: Eldar7/OOPcpp
int main()
{
	std::cout<<Shape::GetCount()<<std::endl; //0

	XList<Shape*>* shlist = new XList<Shape*>;
	Point* point0 = new Point("simple_point");
	Point* point1 = new Point(1,1);
	Point* point2 = new Point(-2.2, 2);
	Circle* circle = new Circle("bublic", *point0,5);
	Rect* rect1 = new Rect(*point1, *point2);
	Square* square = new Square(*point0, *point1);
	Rect* rect2 = new Rect(*square);
	Polyline* pl = new Polyline;
	pl->AddPoint(*point0);
	pl->AddPoint(*point1);
	pl->AddPoint(*point2);
	Square* sq = NULL;
	try
	{
		sq = new Square("ABBA", *point1, *point2);
		shlist->push_front(sq);
	}
	catch (std::exception& e)
	{
		std::cout << e.what() << std::endl;
	}
	try
	{
		sq = new Square("ABBA2", *point1, *point0);
		shlist->push_front(sq);
	}
	catch (std::exception& e)
	{
		std::cout << e.what() << std::endl;
	}

	circle->Print();

	std::cout<<Shape::GetCount()<<std::endl; //21

	shlist->push_back(point0);
	shlist->push_back(rect2);
	shlist->push_back(circle);
	shlist->push_front(rect1);
	shlist->push_back(square);
	shlist->push_back(pl);
	shlist->push_back(point2);
	shlist->push_front(point1);
	

	std::cout<<Shape::GetCount()<<std::endl; //21

	for (XList<Shape*>::iterator it = shlist->begin(); it != shlist->end(); ++it)
	{
		std::cout<<**it<<std::endl;
	}
	std::cout<<Shape::GetCount()<<std::endl; //21
	
	for (XList<Shape*>::iterator it = shlist->begin(); it != shlist->end(); ++it)
	{
		delete *it;
	}
	std::cout<<Shape::GetCount()<<std::endl; //0

	delete shlist;

	std::cout<<Shape::GetCount()<<std::endl; //0
	Named *myshape = new Point(0, 0);
	delete myshape;
	std::cout<<Shape::GetCount()<<std::endl; //0
	return 0;
}
예제 #4
0
int main(int argc, char ** argv) {

	vector<pthread_t> reader, writer, updater ,remover;
	if (argc == 5) {
		cout << "number of reader thread(s):" << argv[1] << 
			" writer thread(s):" << argv[2] << 
			" updater thread(s):" << argv[3] << 
			" remover thread(s):" << argv[4] << endl;
		reader.resize(atoi(argv[1]));
		writer.resize(atoi(argv[2]));
		updater.resize(atoi(argv[3]));
		remover.resize(atoi(argv[4]));
	} else {
		cout << "number of reader thread(s):" << READER_THREADS 
			<< " writer thread(s):"	<< WRITER_THREADS 
			<< " updater thread(s):" << UPDATER_THREADS
		       	<< " remover thread(s):" << REMOVER_THREADS << endl; 
		reader.resize(READER_THREADS);
		writer.resize(WRITER_THREADS);
		updater.resize(UPDATER_THREADS);
		remover.resize(REMOVER_THREADS);
	}

	//define mutex
	mutex mtx;
	//define Xlist
	XList<int> xlist;
	for (int j = 0; j < 10; j++) {
		xlist.push_back(j);
	}

	list_struct<int> list;
	list.list = &xlist;
	list.mtx = &mtx;

	signal_struct<int> sig;
	sig.list = &xlist;
	int s;
	sigset_t set;
	
	pthread_t thread;
	sigemptyset(&set);
        sigaddset(&set, SIGQUIT);
	sigaddset(&set, SIGUSR1);
	sigaddset(&set, SIGALRM);
        s = pthread_sigmask(SIG_BLOCK, &set, NULL);
        if (s != 0)
        	handle_error_en(s, "pthread_sigmask");
	sig.set = &set;
        s = pthread_create(&thread, NULL, sig_handler<int>, (void *) &sig);
        if (s != 0)
                handle_error_en(s, "pthread_create");

	//create reader threads
	int rc = 0;
	for (vector<pthread_t>::iterator it = reader.begin(); 
			it != reader.end(); ++it) {
		cout << "list_read(): creating thread, " << endl;
                rc = pthread_create(&*it, NULL, list_read<int>, 
				(void *) &xlist);
                if (rc) {
                	cout<< "Error:unable to create read thread, " << endl;
			exit(-1);
		}
	}

	for (vector<pthread_t>::iterator it = writer.begin(); 
			it != writer.end(); ++it) {
        	cout << "list_write(): creating thread, " << endl;
		rc = pthread_create(&*it, NULL, list_write<int>,
			       	(void *) &list);
                if (rc) {
                	cout<< "Error:unable to create write thread, " << endl;
			exit(-1);
		}
	}

	for (vector<pthread_t>::iterator it = updater.begin();
		       	it != updater.end(); ++it) {
        	cout << "list_update(): creating thread, " << endl;
                rc = pthread_create(&*it, NULL, list_update<int>,
			       	(void *) &xlist);
		if(rc){
			cout<< "Error:unable to create read thread, " << endl;
			exit(-1);
		}
	}

	for (vector<pthread_t>::iterator it = remover.begin();
		       	it != remover.end(); ++it) {
        	cout << "list_remove(): creating thread, " << endl;
		rc = pthread_create(&*it, NULL, list_remove<int>, 
				(void *) &list);
                if (rc) {
                	cout<< "Error:unable to create read thread, " << endl;
			exit(-1);
		}
	}

	void *status;
	for (vector<pthread_t>::iterator it = reader.begin();
		       	it != reader.end(); ++it) {
	      	rc = pthread_join(*it, &status);		
		if (rc) {
	      		cout << "Error:unable to join reader," << rc << endl;
			exit(-1);
		}
   	}

	for (vector<pthread_t>::iterator it = writer.begin();
			it != writer.end(); ++it) {
	      	rc = pthread_join(*it, &status);		
		if (rc) {
	      		cout << "Error:unable to join writer," << rc << endl;
			exit(-1);
		}
   	}

	for (vector<pthread_t>::iterator it = updater.begin();
		       	it != updater.end(); ++it) {
	      	rc = pthread_join(*it, &status);		
		if (rc) {
	      		cout << "Error:unable to join updater," << rc << endl;
			exit(-1);
		}
   	}

	for (vector<pthread_t>::iterator it = remover.begin();
		       	it != remover.end(); ++it) {
	      	rc = pthread_join(*it, &status);		
		if (rc) {
	      		cout << "Error:unable to join remover," << rc << endl;
			exit(-1);
		}
   	}

   	cout << "Main: program exiting." << endl;
	pthread_exit(NULL);
	return 0;
}