示例#1
0
文件: main.cpp 项目: CCJY/coliru
void foo( const char* current_tag ) // uses boost pool library
{
    std::unique_ptr<A> pa1( new A ) ;
    std::unique_ptr<A> pa2( new A ) ;

    A* pa3 = new A ;
    A* pa4 = new A ;

    std::cout << "objects are at: " << pa1.get() << ' ' << pa2.get() << ' '
               << pa3 << ' ' << pa4 << '\n' ;
    
    // verify that the same memory is being reused: check if the object still contains 
    // the char data that we stored into it the last time the function was called
    std::cout << "current tag: \"" << current_tag << '"' ;
    static bool first_time = true ;
    if( !first_time) std::cout << "  old tag: \"" << pa4->tag() << '"' ;
    std::cout << '\n' ;
    first_time = false ;

    std::vector< A, boost::pool_allocator<A> > seq(1000) ;
    std::cout << "objects in vector are at: " << &seq.front()
               << " to " << &seq.back() << "\n\n" ;

    pa1->tag(current_tag) ;
    pa2->tag(current_tag) ;
    pa3->tag(current_tag) ;
    pa4->tag(current_tag) ;

    delete pa4 ;
    delete pa3 ;
}
示例#2
0
 // stub
 boost::shared_ptr<Solid> Repository::newSolid(SolidEnum type) {
     switch(type) {
         case ROCK: {
          	BitmapImage rockImage("images/rock.bmp");
          	NewtonianMass * pm = new NewtonianMass(1000,2000,20,Vector2d(120,120),Vector2d(0,.1),0.,.1);
             boost::shared_ptr<Solid> rock ( new SimpleSolid( pm, new BitmapImage(rockImage) ) );
             return rock;
         }
         case BIG_ROCK: {
          	BitmapImage rockImage("images/rock.bmp");
          	NewtonianMass * pm = new NewtonianMass(5000,10000,35,Vector2d(720,320),Vector2d(0,-.1),0.,.03);
             boost::shared_ptr<Solid> rock ( new SimpleSolid( pm, new BitmapImage(rockImage) ) );
             return rock;
         }   
         case ALIEN: {
             boost::shared_ptr<Image> pa1( new BitmapImage("images/alien1-1.bmp") );
             boost::shared_ptr<Image> pa2( new BitmapImage("images/alien1-2.bmp") );
             boost::shared_ptr<Image> pa3( new BitmapImage("images/alien1-3.bmp") );
             AnimatedImage * pa( new AnimatedImage(pa1,5) );
             pa->add(pa2);
             pa->add(pa3);
          	NewtonianMass * pm = new NewtonianMass(100,2000,12,Vector2d(500,300), Vector2d(-.1,0),0,0) ;
             boost::shared_ptr<Mass> pBaseAlienMass( pm );
             Mass * alienMass = new DamageMass(pBaseAlienMass, 1000);
             boost::shared_ptr<Solid> alien(new SimpleSolid( alienMass, pa) );   
             return alien;
         }
         default:
             throw(0);
     }
 }
示例#3
0
/*
引数例:
"C:\\users\\tmp.0001.txt"
"../..//users///tmp.0001.txt"
"C://users///tmp.0001.txt"
"C:\\users"	"/home"
"C:\\users/"	"/home/"
"C:\\users\\tmp.0001.txt"	"/home/tmp.0001.txt"
"C:/Users/public/Desktop/一時的フォルダ→すぐ削除する"
*/
int main(int argc ,const char* argv[])
{
	if (argc == 1) {
		usage_(argv[0]);
		return 0;
	}
	else if (argc == 2) {
		/* 注:パスはutf8で格納する */
#ifdef _WIN32
		cppl::file_system_path pa(osapi::utf8_from_cp932(argv[1]));
#else
		cppl::file_system_path pa(argv[1]);
#endif
//		cppl::file_system_path pa(argv[1]);
		return check_file_or_dir_( pa );
	}
	else if (argc == 3 && std::string("-md") == argv[1]) {
		/* 注:パスはutf8で格納する */
#ifdef _WIN32
		cppl::file_system_path pa(osapi::utf8_from_cp932(argv[2]));
#else
		cppl::file_system_path pa(argv[2]);
#endif
		return mkdir_( pa );
	}
	else if (argc == 4 && std::string("-rn") == argv[1]) {
		/* 注:パスはutf8で格納する */
#ifdef _WIN32
		cppl::file_system_path pa1(osapi::utf8_from_cp932(argv[2]));
		cppl::file_system_path pa2(osapi::utf8_from_cp932(argv[3]));
#else
		cppl::file_system_path pa1(argv[2]);
		cppl::file_system_path pa2(argv[3]);
#endif
		return rename_( pa1 , pa2 );
	}

	std::cerr << "Error:Bad argument.\n";
	return 1;
}
// --------------------------------------------------------------------------------------
void HttpRequest::AddCookie(const std::string& str)
{
	m_cookies.add( str );
	Parse pa(str, ";");
	std::string lstr = pa.getword();
	while (!lstr.empty())
	{
		Parse pa2(lstr, "=");
		std::string name = pa2.getword();
		m_cookie[name] = lstr;
DEB(fprintf(stderr, " *** AddCookie '%s' = '%s'\n", name.c_str(), lstr.c_str());)
		lstr = pa.getword();
	}
示例#5
0
  // This method is called for every replicated ciphertext: in the i'th time
  // that it is called, the cipehrtext will have in all the slots the content
  // of the i'th input slot. In this test program we only decrypt and check
  // the result, in a real program it will do something with the cipehrtext.
  virtual void handle(const Ctxt& ctxt) {

    double t_new = GetTime();
    double t_elapsed = t_new - t_last;
    t_total += t_elapsed;

    // Decrypt and check
    PlaintextArray pa1 = pa;
    pa1.replicate(pos);
    PlaintextArray pa2(ea);

    ea.decrypt(ctxt, sKey, pa2);
    if (!pa1.equals(pa2)) error = true; // record the error, if any
    t_last = GetTime();

    pos++;
    if (B > 0 && pos >= B) throw StopReplicate();
  }
int main(void){
    pa0();
    vezerlo_valtozo=1;
    korabbi_dontesek_szama=0;
    while(vezerlo_valtozo)
        switch(vezerlo_valtozo){
            case 1: if (ft1()){
                        pa8();
                        vezerlo_valtozo=0;
                      }
                      else if (ft2()) if ((valasztasi_lehetosegek_szama=fa1())){
                                          pa2();
                                          aktualis_lehetoseg_sorszama=0;
                                          vezerlo_valtozo=3;
                                         }
                                         else vezerlo_valtozo=2;
                              else vezerlo_valtozo=2;
                    break;
            case 2: if (korabbi_dontesek_szama){
                        korabbi_dontesek_szama--;
                        pa4();
                        if (aktualis_lehetoseg_sorszama<valasztasi_lehetosegek_szama-1){
                            aktualis_lehetoseg_sorszama++;
                            vezerlo_valtozo=3;
                           }
                           else vezerlo_valtozo=2;
                       }
                       else {
                           printf("A graf nem szinezheto %d szinnel!\n",MAX_color);
                           vezerlo_valtozo=0;
                       }
                    break;
            case 3: pa6();
                    pa7();
                    korabbi_dontesek_szama++;
                    vezerlo_valtozo=1;
        }
		getchar();
    return 0;

}
void tst_QScopedPointer::comparison()
{
    QCOMPARE( int(RefCounted::instanceCount), 0 );

    {
        RefCounted *a = new RefCounted;
        RefCounted *b = new RefCounted;

        QCOMPARE( int(RefCounted::instanceCount), 2 );

        QScopedPointer<RefCounted> pa1(a);
        QScopedPointer<RefCounted> pa2(a);
        QScopedPointer<RefCounted> pb(b);

        scopedPointerComparisonTest(pa1, pa1, pb);
        scopedPointerComparisonTest(pa2, pa2, pb);
        scopedPointerComparisonTest(pa1, pa2, pb);

        pa2.take();

        QCOMPARE( int(RefCounted::instanceCount), 2 );
    }

    QCOMPARE( int(RefCounted::instanceCount), 0 );

    {
        RefCounted *a = new RefCounted[42];
        RefCounted *b = new RefCounted[43];

        QCOMPARE( int(RefCounted::instanceCount), 85 );

        QScopedArrayPointer<RefCounted> pa1(a);
        QScopedArrayPointer<RefCounted> pa2(a);
        QScopedArrayPointer<RefCounted> pb(b);

        scopedPointerComparisonTest(pa1, pa2, pb);

        pa2.take();

        QCOMPARE( int(RefCounted::instanceCount), 85 );
    }

    QCOMPARE( int(RefCounted::instanceCount), 0 );

    {
        // QScopedSharedPointer is an internal helper class -- it is unsupported!

        RefCounted *a = new RefCounted;
        RefCounted *b = new RefCounted;

        QCOMPARE( int(RefCounted::instanceCount), 2 );

        QSharedDataPointer<RefCounted> pa1(a);
        QSharedDataPointer<RefCounted> pa2(a);
        QSharedDataPointer<RefCounted> pb(b);

        QCOMPARE( int(a->ref), 2 );
        QCOMPARE( int(b->ref), 1 );
        QCOMPARE( int(RefCounted::instanceCount), 2 );

        scopedPointerComparisonTest(pa1, pa2, pb);

        QCOMPARE( int(RefCounted::instanceCount), 2 );
    }

    QCOMPARE( int(RefCounted::instanceCount), 0 );
}
bool hitboxCollision(int a_x,int a_y,int a_width,int a_height,float a_angle,
              int b_x,int b_y,int b_width,int b_height,float b_angle)
{
    Point pa1(a_x,
              a_y);

    Point pa2(a_x + cos (a_angle*PI/180) * a_width
             ,a_y - sin (a_angle*PI/180) * a_width);

    Point pa3(a_x + cos (a_angle*PI/180) * a_width + sin (a_angle*PI/180) * a_height,
              a_y - sin (a_angle*PI/180) * a_width + cos (a_angle*PI/180) * a_height);

    Point pa4(a_x + sin (a_angle*PI/180) * a_height,
              a_y + cos (a_angle*PI/180) * a_height);


    Point pb1(b_x,
              b_y);

    Point pb2(b_x + cos (b_angle*PI/180) * b_width
             ,b_y - sin (b_angle*PI/180) * b_width);

    Point pb3(b_x + cos (b_angle*PI/180) * b_width + sin (b_angle*PI/180) * b_height,
              b_y - sin (b_angle*PI/180) * b_width + cos (b_angle*PI/180) * b_height);

    Point pb4(b_x + sin (b_angle*PI/180) * b_height,
              b_y + cos (b_angle*PI/180) * b_height);

    Line la1(pa1,pa2);
    Line la2(pa2,pa3);
    Line la3(pa3,pa4);
    Line la4(pa4,pa1);

    Line lb1(pb1,pb2);
    Line lb2(pb2,pb3);
    Line lb3(pb3,pb4);
    Line lb4(pb4,pb1);

    if(segmentIntersection(la1,lb1))
        return true;
    if(segmentIntersection(la1,lb2))
        return true;
    if(segmentIntersection(la1,lb3))
        return true;
    if(segmentIntersection(la1,lb4))
        return true;

    if(segmentIntersection(la2,lb1))
        return true;
    if(segmentIntersection(la2,lb2))
        return true;
    if(segmentIntersection(la2,lb3))
        return true;
    if(segmentIntersection(la2,lb4))
        return true;

    if(segmentIntersection(la3,lb1))
        return true;
    if(segmentIntersection(la3,lb2))
        return true;
    if(segmentIntersection(la3,lb3))
        return true;
    if(segmentIntersection(la3,lb4))
        return true;

    if(segmentIntersection(la4,lb1))
        return true;
    if(segmentIntersection(la4,lb2))
        return true;
    if(segmentIntersection(la4,lb3))
        return true;
    if(segmentIntersection(la4,lb4))
        return true;

    return false;


/*

    vector<Point*>intersections;
    intersections.push_back(lineIntersection(la1,lb1));
    intersections.push_back(lineIntersection(la1,lb2));
    intersections.push_back(lineIntersection(la1,lb3));
    intersections.push_back(lineIntersection(la1,lb4));

    intersections.push_back(lineIntersection(la2,lb1));
    intersections.push_back(lineIntersection(la2,lb2));
    intersections.push_back(lineIntersection(la2,lb3));
    intersections.push_back(lineIntersection(la2,lb4));

    intersections.push_back(lineIntersection(la3,lb1));
    intersections.push_back(lineIntersection(la3,lb2));
    intersections.push_back(lineIntersection(la3,lb3));
    intersections.push_back(lineIntersection(la3,lb4));

    intersections.push_back(lineIntersection(la4,lb1));
    intersections.push_back(lineIntersection(la4,lb2));
    intersections.push_back(lineIntersection(la4,lb3));
    intersections.push_back(lineIntersection(la4,lb4));


    int x_min=0;int x_max=0;
    int y_max=0;int y_min=0;

    if(a_width*a_height>b_width*b_height)
    {
        x_min = pa1.x;
        x_min=min(x_min,pa2.x);
        x_min=min(x_min,pa3.x);
        x_min=min(x_min,pa4.x);
        x_max = pa1.x;
        x_max=max(x_max,pa2.x);
        x_max=max(x_max,pa3.x);
        x_max=max(x_max,pa4.x);

        y_min = pa1.y;
        y_min=min(y_min,pa2.y);
        y_min=min(y_min,pa3.y);
        y_min=min(y_min,pa4.y);
        y_max = pa1.y;
        y_max=max(y_max,pa2.y);
        y_max=max(y_max,pa3.y);
        y_max=max(y_max,pa4.y);
    }else
    {
        x_min = pb1.x;
        x_min=min(x_min,pb2.x);
        x_min=min(x_min,pb3.x);
        x_min=min(x_min,pb4.x);
        x_max = pb1.x;
        x_max=max(x_max,pb2.x);
        x_max=max(x_max,pb3.x);
        x_max=max(x_max,pb4.x);

        y_min = pb1.y;
        y_min=min(y_min,pb2.y);
        y_min=min(y_min,pb3.y);
        y_min=min(y_min,pb4.y);
        y_max = pb1.y;
        y_max=max(y_max,pb2.y);
        y_max=max(y_max,pb3.y);
        y_max=max(y_max,pb4.y);
    }

    int cont=0;

    for(int i=0;i<(int)intersections.size();i++)
    {
        Point* point=intersections[i];
        if(point!=NULL)
        {
            if(point->x > x_min
               && point->x < x_max
               && point->y > y_min
               && point->y < y_max)
            {
                cont++;
            }
        }
    }

    vector<Point*>::iterator i;
    for ( i = intersections.begin() ; i < intersections.end(); i++ )
    {
        delete * i;
    }


    if(cont>=8)
        return true;
*/
    return false;
}
示例#9
0
static void filter_self_intersection( const GeometrySet<Dim>& input, GeometrySet<Dim>& output )
{
    {
        typedef std::list< CollectionElement<typename Point_d<Dim>::Type> > PointList;
        PointList points;

        std::copy( input.points().begin(), input.points().end(), std::back_inserter( points ) );

        typename PointList::iterator it = points.begin();

        while ( it != points.end() ) {
            bool intersectsA = false;

            for ( typename PointList::iterator it2 = points.begin(); it2 != points.end(); ++it2 ) {
                if ( it == it2 ) {
                    continue;
                }

                PrimitiveHandle<Dim> pa1( &it->primitive() );
                PrimitiveHandle<Dim> pa2( &it2->primitive() );

                if ( CGAL::do_overlap( it->primitive().bbox(), it2->primitive().bbox() ) &&
                        algorithm::intersects( pa1, pa2 ) ) {
                    intersectsA = true;
                    GeometrySet<Dim> temp;
                    algorithm::intersection( pa1, pa2, temp );
                    std::copy( temp.points().begin(), temp.points().end(), std::back_inserter( points ) );
                    // erase it2
                    points.erase( it2 );
                    break;
                }
            }

            if ( ! intersectsA ) {
                output.addPrimitive( it->primitive() );
            }

            // suppress A
            it = points.erase( it );
        }
    }
    {
        typedef std::list< CollectionElement<typename Segment_d<Dim>::Type> > SegmentList;
        SegmentList segments;

        std::copy( input.segments().begin(), input.segments().end(), std::back_inserter( segments ) );

        typename SegmentList::iterator it = segments.begin();

        while ( it != segments.end() ) {
            bool intersectsA = false;

            for ( typename SegmentList::iterator it2 = segments.begin(); it2 != segments.end(); ++it2 ) {
                if ( it == it2 ) {
                    continue;
                }

                PrimitiveHandle<Dim> pa1( &it->primitive() );
                PrimitiveHandle<Dim> pa2( &it2->primitive() );

                if ( CGAL::do_overlap( it->primitive().bbox(), it2->primitive().bbox() ) &&
                        algorithm::intersects( pa1, pa2 ) ) {
                    intersectsA = true;
                    GeometrySet<Dim> temp;
                    algorithm::intersection( pa1, pa2, temp );
                    std::copy( temp.segments().begin(), temp.segments().end(), std::back_inserter( segments ) );
                    // erase it2
                    segments.erase( it2 );
                    break;
                }
            }

            if ( ! intersectsA ) {
                output.addPrimitive( it->primitive() );
            }

            // suppress A
            it = segments.erase( it );
        }
    }
}