Ejemplo n.º 1
0
//如果乘法可能爆long long的话, 使用下面的板子
ll mul(ll a,ll b){
    return ((a*b-ll(((long double)a)/mod*b+1e-3)*mod)%mod+mod)%mod;
}
Ejemplo n.º 2
0
TEST(GeoLib, SurfaceIsPointInSurface)
{
    std::vector<std::function<double(double, double)>> surface_functions;
    surface_functions.emplace_back(constant);
    surface_functions.emplace_back(coscos);

    for (const auto& f : surface_functions) {
        std::random_device rd;

        std::string name("Surface");
        // generate ll and ur in random way
        std::mt19937 random_engine_mt19937(rd());
        std::normal_distribution<> normal_dist_ll(-10, 2);
        std::normal_distribution<> normal_dist_ur(10, 2);
        MathLib::Point3d ll(std::array<double,3>({{
            normal_dist_ll(random_engine_mt19937),
            normal_dist_ll(random_engine_mt19937),
            0.0}}));
        MathLib::Point3d ur(std::array<double,3>({{
            normal_dist_ur(random_engine_mt19937),
            normal_dist_ur(random_engine_mt19937),
            0.0}}));
        for (std::size_t k(0); k<3; ++k)
            if (ll[k] > ur[k])
                std::swap(ll[k], ur[k]);

        // random discretization of the domain
        std::default_random_engine re(rd());
        std::uniform_int_distribution<std::size_t> uniform_dist(2, 25);
        std::array<std::size_t,2> n_steps = {{uniform_dist(re),uniform_dist(re)}};

        std::unique_ptr<MeshLib::Mesh> sfc_mesh(
            MeshLib::MeshGenerator::createSurfaceMesh(
                name, ll, ur, n_steps, f
            )
        );

        // random rotation angles
        std::normal_distribution<> normal_dist_angles(
            0, boost::math::double_constants::two_pi);
        std::array<double,3> euler_angles = {{
            normal_dist_angles(random_engine_mt19937),
            normal_dist_angles(random_engine_mt19937),
            normal_dist_angles(random_engine_mt19937)
            }};

        MathLib::DenseMatrix<double, std::size_t> rot_mat(getRotMat(
            euler_angles[0], euler_angles[1], euler_angles[2]));

        std::vector<MeshLib::Node*> const& nodes(sfc_mesh->getNodes());
        GeoLib::rotatePoints<MeshLib::Node>(rot_mat, nodes);

        MathLib::Vector3 const normal(0,0,1.0);
        MathLib::Vector3 const surface_normal(rot_mat * normal);
        double const scaling(1e-6);
        MathLib::Vector3 const displacement(scaling * surface_normal);

        GeoLib::GEOObjects geometries;
        MeshLib::convertMeshToGeo(*sfc_mesh, geometries);

        std::vector<GeoLib::Surface*> const& sfcs(*geometries.getSurfaceVec(name));
        GeoLib::Surface const*const sfc(sfcs.front());
        std::vector<GeoLib::Point*> const& pnts(*geometries.getPointVec(name));

        double const eps(std::numeric_limits<double>::epsilon());

        // test triangle edge point of the surface triangles
        for (auto const p : pnts) {
            EXPECT_TRUE(sfc->isPntInSfc(*p, eps));
            MathLib::Point3d q(*p);
            for (std::size_t k(0); k<3; ++k)
                q[k] += displacement[k];
            EXPECT_FALSE(sfc->isPntInSfc(q, eps));
        }
        // test edge middle points of the triangles
        for (std::size_t k(0); k<sfc->getNumberOfTriangles(); ++k) {
            MathLib::Point3d p, q, r;
            std::tie(p,q,r) = getEdgeMiddlePoints(*(*sfc)[k]);
            EXPECT_TRUE(sfc->isPntInSfc(p, eps));
            EXPECT_TRUE(sfc->isPntInSfc(q, eps));
            EXPECT_TRUE(sfc->isPntInSfc(r, eps));
        }
    }
}
string DirectoryListing::loadXML(const string& xml, bool updating) {
	ListLoader ll(this, getRoot(), updating);
	SimpleXMLReader(&ll).fromXML(xml);
	return ll.getBase();
}
Ejemplo n.º 4
0
/*funkcja główna*/
int main(int argc, char *argv[], char *envp[])
{
printf("***************************************************************** \n");
printf("*                 Powlokę wykonali:                             * \n");
printf("*                 Piotr Rzęzawa Grupa 11D Nr Albumu 2177        * \n");
printf("*                 Aleksandra Bykowska Grupa 11E Nr Albumu 2230  * \n");
printf("*                 Sebastian Ostrowski Grupa 11D Nr Albumu 2389  * \n");
printf("*                 Grzegorz Kur Grupa 11D Nr Albumu 2351         * \n");
printf("***************************************************************** \n");
printf("*                 Polecenia Powloki:                            * \n");
printf("*                 pwd- wyświetla w jakim katalogu jesteśmy      * \n");
printf("*                 cd- cd+[nazwa katalogu]- przejście do katalogu* \n");
printf("*    ls- wyświetla zawartość katalogu ls+[nazwa katalogu]       * \n");
printf("*    ll - wyświetla zawartośc katalogu i uprawnienia            * \n");
printf("*    execl -uruchomienie programu                               * \n");
printf("*    env- wyświetla zmienne środowiskowe                        * \n");
printf("*    exit- wyjście                                              * \n");
printf("***************************************************************** \n");
   
    char buffer[BUFFER_SIZE]; // rozmiar buffora
    char *args[ARR_SIZE]; //rozmiar tablicy

    int *ret_status;
    size_t nargs;
    pid_t pid;
    
    while(1){
        printf("powloka~$ "); //prompt
        fgets(buffer, BUFFER_SIZE, stdin);
        parse_args(buffer, args, ARR_SIZE, &nargs);
        if (nargs==0) continue;
        if (!strcmp(args[0], "exit" )) exit(0); //wbudowane polecenie exit
        if (!strcmp(args[0], "cd" )) { //wbudowane polecenie cd 
                        chdir(args[1]);

                        continue;
                        }
/*wywołanie funkcji pwd*/
if (!strcmp(args[0], "pwd" ))
{

pwd();
continue; 
}
/*wywołanie funkcji ls*/
if (!strcmp(args[0], "ls" ))
{
if(args[1]==NULL)
{
ls(argc, argv);
}
if(args[1]!=NULL){
	char miejsce[256]; //deklaracja tablicy o wielkości 256 znaków  
	getcwd(miejsce, 256); //getcwd podaje aktualny katalog roboczy w tym wypadku przypisujemy go do tablicy miejsce 
	chdir(args[1]); 
	ls(argc, argv); //wywołanie funkcji ls 
	chdir(miejsce); //zmiana katalogu domowego na miejsce podane przez użytkownika
}
continue; 
}
/*wywołanie funkcji exec */
if (!strcmp(args[0], "execl"))
{

exec ();  ;
continue; 
}
/*wywołanie funkcji ll*/
if (!strcmp(args[0], "ll" ))
{

ll(argc, argv);
continue; 
}


if (!strcmp(args[0],"env")){
    int i = 0;
    for (i = 0; i < 4; i++)
        if (args[i] == NULL) {
            printf("Missing argument %d. \n Usage: setenv [Name] [value] [flag]\n", i);
            return 0;
        }
	printf("Ustawiłem zmienną %s na %s z flagą %s \n",args[1],args[2],args[3]);
     	setenv(args[1], args[2], (int) args[3]);
continue;

}

if (!strcmp(args[0],"getEnv")){

printf("Env %s, %s \n",args[1],getenv(args[1]));
continue;
}


/*forkowanie*/
      pid = fork();
        if (pid){
            pid = wait(ret_status);
        } else {
            if(execvp(args[0], args)) {
                puts(strerror(errno));
                exit(127);

           }
        }
    }
    return 0;
}
Ejemplo n.º 5
0
int main()
{
    {
        std::locale l;
        {
            typedef std::ctype_byname<char> F;
            std::locale ll(l, new F(LOCALE_en_US_UTF_8));
            const F& f = std::use_facet<F>(ll);
            std::string in("c A\x07.a1");

            assert(f.toupper(&in[0], in.data() + in.size()) == in.data() + in.size());
            assert(in[0] == 'C');
            assert(in[1] == ' ');
            assert(in[2] == 'A');
            assert(in[3] == '\x07');
            assert(in[4] == '.');
            assert(in[5] == 'A');
            assert(in[6] == '1');
        }
    }
    {
        std::locale l;
        {
            typedef std::ctype_byname<char> F;
            std::locale ll(l, new F("C"));
            const F& f = std::use_facet<F>(ll);
            std::string in("\xFA A\x07.a1");

            assert(f.toupper(&in[0], in.data() + in.size()) == in.data() + in.size());
            assert(in[0] == '\xFA');
            assert(in[1] == ' ');
            assert(in[2] == 'A');
            assert(in[3] == '\x07');
            assert(in[4] == '.');
            assert(in[5] == 'A');
            assert(in[6] == '1');
        }
    }
    {
        std::locale l;
        {
            typedef std::ctype_byname<wchar_t> F;
            std::locale ll(l, new F(LOCALE_en_US_UTF_8));
            const F& f = std::use_facet<F>(ll);
            std::wstring in(L"\xFA A\x07.a1");

            assert(f.toupper(&in[0], in.data() + in.size()) == in.data() + in.size());
            assert(in[0] == L'\xDA');
            assert(in[1] == L' ');
            assert(in[2] == L'A');
            assert(in[3] == L'\x07');
            assert(in[4] == L'.');
            assert(in[5] == L'A');
            assert(in[6] == L'1');
        }
    }
    {
        std::locale l;
        {
            typedef std::ctype_byname<wchar_t> F;
            std::locale ll(l, new F("C"));
            const F& f = std::use_facet<F>(ll);
            std::wstring in(L"\u00FA A\x07.a1");

            assert(f.toupper(&in[0], in.data() + in.size()) == in.data() + in.size());
            assert(in[0] == L'\u00FA');
            assert(in[1] == L' ');
            assert(in[2] == L'A');
            assert(in[3] == L'\x07');
            assert(in[4] == L'.');
            assert(in[5] == L'A');
            assert(in[6] == L'1');
        }
    }
}
Ejemplo n.º 6
0
int CFfAudioDecoder::Create( int x_nCodec, int x_nFmt, int x_nChannels, int x_nSampleRate, int x_nBps )
{_STT();

	oexAutoLock ll( _g_ffmpeg_lock );
	if ( !ll.IsLocked() ) return 0;

	// Lose previous codec
	Destroy();

	m_pCodec = avcodec_find_decoder( (CodecID)x_nCodec );
	if ( !m_pCodec )
	{	oexERROR( 0, oexMks( oexT( "avcodec_find_decoder() failed : " ),
					 (int)x_nCodec, oexT( " - " ), LookupCodecName( x_nCodec ).c_str() ) );
		return 0;
	} // end if

	// Allocate context
	m_pCodecContext = avcodec_alloc_context();
	if ( !m_pCodecContext )
	{	oexERROR( 0, oexT( "avcodec_alloc_context() failed" ) );
		Destroy();
		return 0;
	} // end if

//	avcodec_get_context_defaults( m_pCodecContext );
	avcodec_get_context_defaults2( m_pCodecContext, AVMEDIA_TYPE_AUDIO );

    m_pCodecContext->codec_id = (CodecID)x_nCodec;
    m_pCodecContext->codec_type = AVMEDIA_TYPE_AUDIO;

#	define CNVTYPE( t, v ) case oex::obj::t : m_pCodecContext->sample_fmt = v; break;
	switch( x_nFmt )
	{	CNVTYPE( tUInt8, AV_SAMPLE_FMT_U8 );
		CNVTYPE( tInt16, AV_SAMPLE_FMT_S16 );
		CNVTYPE( tInt32, AV_SAMPLE_FMT_S32 );
		CNVTYPE( tFloat, AV_SAMPLE_FMT_FLT );
		CNVTYPE( tDouble, AV_SAMPLE_FMT_DBL );
		default : m_pCodecContext->sample_fmt = AV_SAMPLE_FMT_NONE; break;
	} // end switch

    m_pCodecContext->channels = x_nChannels;
	m_pCodecContext->sample_rate = x_nSampleRate;
    m_pCodecContext->bits_per_coded_sample = x_nBps;
    m_pCodecContext->bit_rate = m_pCodecContext->sample_rate * m_pCodecContext->channels * 8;
    m_pCodecContext->block_align = 0;

//    m_pCodecContext->strict_std_compliance = ( ( m && m->isset( oexT( "cmp" ) ) ) ? (*m)[ oexT( "cmp" ) ].toint() : 0 );

	if( 0 != ( m_pCodec->capabilities & CODEC_CAP_TRUNCATED ) )
		m_pCodecContext->flags |= CODEC_FLAG_TRUNCATED;

	// Codec context
	if ( m_extra.getUsed() )
	{	m_pCodecContext->extradata_size = m_extra.getUsed();
		m_pCodecContext->extradata = (uint8_t*)m_extra._Ptr();
		m_pCodecContext->flags |= CODEC_FLAG_GLOBAL_HEADER;
	} // end if

	int res = avcodec_open( m_pCodecContext, m_pCodec );
	if ( 0 > res )
	{	oexERROR( res, oexT( "avcodec_open() failed" ) );
		m_pCodecContext = oexNULL;
		Destroy();
		return 0;
	} // end if

	return 1;
}
Ejemplo n.º 7
0
void ConditionalHistogramCanvas::ResizeSelectableShps(int virtual_scrn_w,
														int virtual_scrn_h)
{
	// NOTE: we do not support both fixed_aspect_ratio_mode
	//    and fit_to_window_mode being false currently.
	//LOG_MSG("Entering ConditionalHistogramCanvas::ResizeSelectableShps");
	int vs_w=virtual_scrn_w, vs_h=virtual_scrn_h;
	if (vs_w <= 0 && vs_h <= 0) GetVirtualSize(&vs_w, &vs_h);
	
	double image_width, image_height;
	bool ftwm = GetFitToWindowMode();
	
	// last_scale_trans is only used in calls made to ApplyLastResizeToShp
	// which are made in ScaterNewPlotView
	GdaScaleTrans **st;
	st = new GdaScaleTrans*[vert_num_cats];
	for (int i=0; i<vert_num_cats; i++) {
		st[i] = new GdaScaleTrans[horiz_num_cats];
	}
	
	// Total width height:  vs_w   vs_h
	// Working area margins: virtual_screen_marg_top,
	//  virtual_screen_marg_bottom,
	//  virtual_screen_marg_left,
	//  virtual_screen_marg_right
	// We need to increase these as needed for each tile area
	
	double scn_w = vs_w;
	double scn_h = vs_h;
	
	double min_pad = 10;
	if (show_axes) {
		min_pad += 38;
	}
	
	// pixels between columns/rows
	double fac = 0.01;
	//if (vert_num_cats >= 4 || horiz_num_cats >=4) fac = 0.05;
	double pad_w = scn_w * fac;
	double pad_h = scn_h * fac;
	if (pad_w < 1) pad_w = 0;
	if (pad_h < 1) pad_h = 0;
	double pad_bump = GenUtils::min<double>(pad_w, pad_h);
	double pad = min_pad + pad_bump;
	
	double marg_top = virtual_screen_marg_top;
	double marg_bottom = virtual_screen_marg_bottom;
	double marg_left = virtual_screen_marg_left;
	double marg_right = virtual_screen_marg_right;
	
	double d_rows = vert_num_cats;
	double d_cols = horiz_num_cats;
	
	double tot_width = scn_w - ((d_cols-1)*pad + marg_left + marg_right);
	double tot_height = scn_h - ((d_rows-1)*pad + marg_top + marg_bottom);
	double del_width = tot_width / d_cols;
	double del_height = tot_height / d_rows;
	
	bin_extents.resize(boost::extents[vert_num_cats][horiz_num_cats]);
	for (int row=0; row<vert_num_cats; row++) {
		double drow = row;
		for (int col=0; col<horiz_num_cats; col++) {
			double dcol = col;
			double ml = marg_left + col*(pad+del_width);
			double mr = marg_right + ((d_cols-1)-col)*(pad+del_width);
			double mt = marg_top + row*(pad+del_height);
			double mb = marg_bottom + ((d_rows-1)-row)*(pad+del_height);
			
			double s_x, s_y, t_x, t_y;
			GdaScaleTrans::calcAffineParams(shps_orig_xmin, shps_orig_ymin,
										   shps_orig_xmax, shps_orig_ymax,
										   mt, mb, ml, mr,
										   vs_w, vs_h, fixed_aspect_ratio_mode,
										   ftwm,
										   &s_x, &s_y, &t_x, &t_y,
										   ftwm ? 0 : current_shps_width,
										   ftwm ? 0 : current_shps_height,
										   &image_width, &image_height);
			st[(vert_num_cats-1)-row][col].scale_x = s_x;
			st[(vert_num_cats-1)-row][col].scale_y = s_y;
			st[(vert_num_cats-1)-row][col].trans_x = t_x;
			st[(vert_num_cats-1)-row][col].trans_y = t_y;
			st[(vert_num_cats-1)-row][col].max_scale =
			GenUtils::max<double>(s_x, s_y);
			
			wxRealPoint ll(shps_orig_xmin, shps_orig_ymin);
			wxRealPoint ur(shps_orig_xmax, shps_orig_ymax);
			bin_extents[(vert_num_cats-1)-row][col] = GdaRectangle(ll, ur);
			bin_extents[(vert_num_cats-1)-row][col].applyScaleTrans(
											st[(vert_num_cats-1)-row][col]);
		}
	}
	
	int i=0;
	for (int r=0; r<vert_num_cats; r++) {
		for (int c=0; c<horiz_num_cats; c++) {
			for (int ival=0; ival<cur_intervals; ival++) {
				selectable_shps[i]->applyScaleTrans(st[r][c]);
				i++;
			}
		}
	}
	
	BOOST_FOREACH( GdaShape* shp, background_shps ) { delete shp; }
	background_shps.clear();
	
	GdaShape* s;
	if (show_axes) {
		for (int r=0; r<vert_num_cats; r++) {
			for (int c=0; c<horiz_num_cats; c++) {
				s = new GdaAxis(*x_axis);
				s->applyScaleTrans(st[r][c]);
				background_shps.push_front(s);
				s = new GdaAxis(*y_axis);
				s->applyScaleTrans(st[r][c]);
				background_shps.push_front(s);
			}
		}
	}
	
	double bg_xmin = marg_left;
	double bg_xmax = scn_w-marg_right;
	double bg_ymin = marg_bottom;
	double bg_ymax = scn_h-marg_top;
	
	std::vector<wxRealPoint> v_brk_ref(vert_num_cats-1);
	std::vector<wxRealPoint> h_brk_ref(horiz_num_cats-1);
	
	for (int row=0; row<vert_num_cats-1; row++) {
		double y = (bin_extents[row][0].lower_left.y +
					bin_extents[row+1][0].upper_right.y)/2.0;
		v_brk_ref[row].x = bg_xmin;
		v_brk_ref[row].y = scn_h-y;
	}
	
	for (int col=0; col<horiz_num_cats-1; col++) {
		double x = (bin_extents[0][col].upper_right.x +
					bin_extents[0][col+1].lower_left.x)/2.0;
		h_brk_ref[col].x = x;
		h_brk_ref[col].y = bg_ymin;
	}
	
	int bg_shp_cnt = 0;
	int label_offset = 25;
	if (show_axes) label_offset += 25;
	int vt = var_info[VERT_VAR].time;
	for (int row=0; row<vert_num_cats-1; row++) {
		double b;
		if (cat_classif_def_vert.cat_classif_type != CatClassification::custom){
			if (!vert_cat_data.HasBreakVal(vt, row)) continue;
			b = vert_cat_data.GetBreakVal(vt, row);
		} else {
			b = cat_classif_def_vert.breaks[row];
		}
		wxString t(GenUtils::DblToStr(b));
		s = new GdaShapeText(t, *GdaConst::small_font, v_brk_ref[row], 90,
					   GdaShapeText::h_center, GdaShapeText::bottom, -label_offset, 0);
		background_shps.push_front(s);
		bg_shp_cnt++;
	}
	if (GetCatType(VERT_VAR) != CatClassification::no_theme) {
		wxString vert_label;
		if (GetCatType(VERT_VAR) == CatClassification::custom) {
			vert_label << cat_classif_def_vert.title;
		} else {
			vert_label << CatClassification::CatClassifTypeToString(
														GetCatType(VERT_VAR));
		}
		vert_label << " vert cat var: ";
		vert_label << GetNameWithTime(VERT_VAR);
		s = new GdaShapeText(vert_label, *GdaConst::small_font,
					   wxRealPoint(bg_xmin, bg_ymin+(bg_ymax-bg_ymin)/2.0), 90,
					   GdaShapeText::h_center, GdaShapeText::bottom, -(label_offset+15), 0);
		background_shps.push_front(s);
		bg_shp_cnt++;
	}
	
	int ht = var_info[HOR_VAR].time;
	for (int col=0; col<horiz_num_cats-1; col++) {
		double b;
		if (cat_classif_def_horiz.cat_classif_type!= CatClassification::custom){
			if (!horiz_cat_data.HasBreakVal(ht, col)) continue;
			b = horiz_cat_data.GetBreakVal(ht, col);
		} else {
			b = cat_classif_def_horiz.breaks[col];
		}
		wxString t(GenUtils::DblToStr(b));
		s = new GdaShapeText(t, *GdaConst::small_font, h_brk_ref[col], 0,
					   GdaShapeText::h_center, GdaShapeText::top, 0, label_offset);
		background_shps.push_front(s);
		bg_shp_cnt++;
	}
	if (GetCatType(HOR_VAR) != CatClassification::no_theme) {
		wxString horiz_label;
		if (GetCatType(HOR_VAR) == CatClassification::custom) {
			horiz_label << cat_classif_def_horiz.title;
		} else {
			horiz_label << CatClassification::CatClassifTypeToString(
														GetCatType(HOR_VAR));
		}
		horiz_label << " horiz cat var: ";
		horiz_label << GetNameWithTime(HOR_VAR);
		s = new GdaShapeText(horiz_label, *GdaConst::small_font,
					   wxRealPoint(bg_xmin+(bg_xmax-bg_xmin)/2.0, bg_ymin), 0,
					   GdaShapeText::h_center, GdaShapeText::top, 0, (label_offset+15));
		background_shps.push_front(s);
		bg_shp_cnt++;
	}
	
	GdaScaleTrans::calcAffineParams(marg_left, marg_bottom,
								   scn_w-marg_right,
								   scn_h-marg_top,
								   marg_top, marg_bottom,
								   marg_left, marg_right,
								   vs_w, vs_h,
								   fixed_aspect_ratio_mode,
								   fit_to_window_mode,
								   &last_scale_trans.scale_x,
								   &last_scale_trans.scale_y,
								   &last_scale_trans.trans_x,
								   &last_scale_trans.trans_y,
								   0, 0, &image_width, &image_height);
	last_scale_trans.max_scale =
	GenUtils::max<double>(last_scale_trans.scale_x,
						  last_scale_trans.scale_y);
	
	int bg_shp_i = 0;
	for (std::list<GdaShape*>::iterator it=background_shps.begin();
		 bg_shp_i < bg_shp_cnt && it != background_shps.end();
		 bg_shp_i++, it++) {
		(*it)->applyScaleTrans(last_scale_trans);
	}
	
	layer0_valid = false;
	Refresh();
	
	for (int i=0; i<vert_num_cats; i++) delete [] st[i];
	delete [] st;
	
	//LOG_MSG("Exiting ConditionalHistogramCanvas::ResizeSelectableShps");
}
Ejemplo n.º 8
0
void QgsMapOverviewCanvas::drawExtentRect()
{
  const QgsRectangle& extent = mMapCanvas->extent();

  // show only when valid extent is set
  if ( extent.isEmpty() )
  {
    mPanningWidget->hide();
    return;
  }

  const QgsMapToPixel* cXf = mMapRenderer->coordinateTransform();
  QgsPoint ll( extent.xMinimum(), extent.yMinimum() );
  QgsPoint ur( extent.xMaximum(), extent.yMaximum() );
  if ( cXf )
  {
    // transform the points before drawing
    cXf->transform( &ll );
    cXf->transform( &ur );
  }

#if 0
  // test whether panning widget should be drawn
  bool show = false;
  if ( ur.x() >= 0 && ur.x() < width() )
    show = true;
  if ( ll.x() >= 0 && ll.x() < width() )
    show = true;
  if ( ur.y() >= 0 && ur.y() < height() )
    show = true;
  if ( ll.y() >= 0 && ll.y() < height() )
    show = true;
  if ( !show )
  {
    QgsDebugMsg( "panning: extent out of overview area" );
    mPanningWidget->hide();
    return;
  }
#endif

  // round values
  int x1 = static_cast<int>( ur.x() + 0.5 ), x2 = static_cast<int>( ll.x() + 0.5 );
  int y1 = static_cast<int>( ur.y() + 0.5 ), y2 = static_cast<int>( ll.y() + 0.5 );

  if ( x1 > x2 )
    std::swap( x1, x2 );
  if ( y1 > y2 )
    std::swap( y1, y2 );

#ifdef Q_WS_MAC
  // setGeometry (Qt 4.2) is causing Mac window corruption (decorations
  // are drawn at odd locations) if both coords are at limit. This may
  // have something to do with Qt calculating dimensions as x2 - x1 + 1.
  // (INT_MAX - INT_MIN + 1 is UINT_MAX + 1)
  if ( x1 == INT_MIN && x2 == INT_MAX )
    x1 += 1;  // x2 -= 1 works too
  if ( y1 == INT_MIN && y2 == INT_MAX )
    y1 += 1;
#endif

  QRect r( x1, y1, x2 - x1 + 1, y2 - y1 + 1 );

  // allow for 5 pixel minimum widget size
  if ( r.width() < 5 && x1 > INT_MIN + 2 ) // make sure no underflow occurs (2 is largest adjustment)
  {
    r.setX( r.x() - (( 5 - r.width() ) / 2 ) );  // adjust x  by 1/2 the difference of calculated and min. width
    r.setWidth( 5 );
  }
  if ( r.height() < 5 && y1 > INT_MIN + 2 )
  {
    r.setY( r.y() - (( 5 - r.height() ) / 2 ) );  // adjust y
    r.setHeight( 5 );
  }

  QgsDebugMsg( QString( "panning: extent to widget: [%1,%2] [%3x%4]" ).arg( x1 ).arg( y1 ).arg( r.width() ).arg( r.height() ) );

  mPanningWidget->setGeometry( r );
  mPanningWidget->show(); // show if hidden
}
Ejemplo n.º 9
0
//void at(int pos) {
  ////argument check
  //if (pos > 0 && < 10) {
    //arr[pos];
  //}
  //throw std::length_error("pos 超出范围");
//}
int main(int argc, char *argv[])
{
  //printf("12:%d, yy: %d \n", arr[12], y);
  std::exception e;
  printf("%s\n", e.what());

  std::logic_error le("logic xxxx");
  printf("logic_error.what: %s\n", le.what());

  std::out_of_range oe("out_of_range");
  printf("oe: %p\n", &oe);
  show(oe);
  int i =3;
  show(i);



  std::invalid_argument ia("null pointer");
  printf("invalid_argument.what: %s\n", ia.what());

  std::length_error ll("length error");
  printf("length_error.what: %s\n", ll.what());

  std::range_error re("range_error");
  printf("range_error.what: %s\n", re.what());
  //std::system_error se(EDOM, std::system_category());
  std::system_error se(ECHILD, std::system_category());
  printf("system_error.what: %s error:%d\n", 
         se.what(), se.code().value());

  try {
    xx();
  }catch(std::invalid_argument &e) {
    printf("caller catch inva:%s\n", e.what());
  }

  //try {
    //ee(2);
  //}
  //catch(int i) {
    //printf("catch int :%d\n", i);
  //}
  //catch(std::out_of_range &e) {
    //printf("catch out:%s\n", e.what());
  //}
  ////catch(std::invalid_argument &e) {
    ////printf("catch inva:%s\n", e.what());
  ////}
  ////catch(double i) {
    ////printf("catch int :%g\n", i);
  ////}
  //catch(...) {
    //printf("catch unknown exception\n");
    //throw;
  //}
  //;

  printf("xxx\n");
  
  return 0;
}
Ejemplo n.º 10
0
BOOL CNetCmd::vMsg( const GUID *pNode, const GUID *pClass, DWORD dwFunction, CReg *pParams, DWORD dwBuffers, LPVOID *pArgs )
{_STT();
	// Verify we have authority to send this message
	if ( !OnTxAuthenticate( pNode, pClass, dwFunction ) )
		return FALSE;

	// Get destination
	CNetCom *pNc = GetNode( pNode );
	if ( pNc == NULL || !pNc->IsValid() ) 
		return FALSE;

	// Copy message data
	CNetMsg::SMsg msg;
	ZeroMemory( &msg, sizeof( msg ) );
	msg.dwFunction = dwFunction;
	
	// Encode params
	CPipe params;
	if ( pParams ) pParams->SaveRegFile( &params, NULL, "" );

	// Calculate the total size needed
	DWORD dwBlocks = 3; if ( params.GetBufferSize() ) dwBlocks++;
	DWORD dwTotalSize = ( sizeof( CNetMsg::SAddress ) * 2 ) +  
						sizeof( CNetMsg::SMsg ) +
						params.GetBufferSize();

	DWORD i;
	LPVOID *ptrExtra = pArgs;
	for ( i = 0; i < dwBuffers; i++ )
	{	RULIB_TRY 
		{	DWORD	dwType = *(LPDWORD)( ptrExtra );
			LPBYTE	pPtr = *(LPBYTE*)( ptrExtra + 1 );
			DWORD 	dwSize = *(LPDWORD)( ptrExtra + 2 );
			dwBlocks++;

			// Zero means NULL terminated
			if ( dwSize == 0 && pPtr != NULL ) dwSize = strlen( (LPCTSTR)pPtr );

			dwTotalSize += dwSize;

			ptrExtra += 3;
		} // end try
		RULIB_CATCH_ALL { return FALSE; }
	} // end for

	// Lock the tx buffer
	CTlLocalLock ll( *pNc->Tx() );
	if ( !ll.IsLocked() ) return FALSE;

	// Initialze the packet
	pNc->Tx()->InitPacket( NETMSG_PACKETTYPE, dwBlocks, dwTotalSize );

	CNetMsg::SAddress addr;

	// Destination information	
	memcpy( &addr.guidNode, pNc->Rx()->Address(), sizeof( GUID ) );
	if ( pClass ) memcpy( &addr.guidClass, pClass, sizeof( GUID ) );
	else ZeroMemory( &addr.guidClass, sizeof( addr.guidClass ) );
	pNc->Tx()->AddPacketData( NETMSGDT_DSTADDRESS, &addr, sizeof( addr ) );
	
	// Source information	
	memcpy( &addr.guidNode, pNc->Tx()->Address(), sizeof( GUID ) );
	ZeroMemory( &addr.guidClass, sizeof( addr.guidClass ) );
	pNc->Tx()->AddPacketData( NETMSGDT_SRCADDRESS, &addr, sizeof( addr ) );

	// Add message
	pNc->Tx()->AddPacketData( NETMSGDT_MSG, &msg, sizeof( msg ) );

	// Add params if any
	if ( params.GetBufferSize() )
		pNc->Tx()->AddPacketData( NETMSGDT_PARAMS, params.GetBuffer(), params.GetBufferSize() );

	// Add the data to the packet
	ptrExtra = pArgs;
	for ( i = 0; i < dwBuffers; i++ )
	{	RULIB_TRY 
		{	DWORD	dwType = *(LPDWORD)( ptrExtra );
			LPBYTE	pPtr = *(LPBYTE*)( ptrExtra + 1 );
			DWORD 	dwSize = *(LPDWORD)( ptrExtra + 2 );

			// Zero means NULL terminated
			if ( dwSize == 0 && pPtr != NULL ) dwSize = strlen( (LPCTSTR)pPtr );

			// Add packet data block
			pNc->Tx()->AddPacketData( dwType, pPtr, dwSize );

			ptrExtra += 3;
		} // end try
		RULIB_CATCH_ALL { return FALSE; }
	} // end for

	// Make it official
	return pNc->Tx()->EndPacket();
}