예제 #1
0
void WatchedDirTest::test_method()
{
    QString dirname = _tempDir.absolutePath();
    {
        // Use Case:
        // Empty directory watched
        // Expect readyRead on any new file
        WatchedDir wd(dirname);
        QSignalSpy spy( &wd, SIGNAL( readyRead() ) );
        boost::shared_ptr<QTemporaryFile> file1=addFile(dirname);
        _app->processEvents();
        CPPUNIT_ASSERT_EQUAL( 1, spy.count() );
        CPPUNIT_ASSERT_EQUAL( (int)file1->size() , (int)wd.bytesAvailable() );
        boost::shared_ptr<QTemporaryFile> file2=addFile(dirname);
        _app->processEvents();
        // ensure we can read the data
        // and that the stream at end markers are set only when all files
        // are consumed from the stream
        CPPUNIT_ASSERT_EQUAL( file1->fileName().toStdString(), wd.fileName().toStdString() );
        QByteArray f1 = wd.readFile();
        CPPUNIT_ASSERT( ! wd.atEnd() );
        CPPUNIT_ASSERT_EQUAL( (int)file1->size(), f1.size() );
        CPPUNIT_ASSERT_EQUAL( file2->fileName().toStdString(), wd.fileName().toStdString());
        CPPUNIT_ASSERT_EQUAL( 2, spy.count() ); // emit signal each time we switch files
        CPPUNIT_ASSERT_EQUAL( (int)file2->size() , (int)wd.bytesAvailable() );
        QByteArray f2 = wd.readFile();
        CPPUNIT_ASSERT_EQUAL( (int)file2->size(), (int)f2.size() );
        CPPUNIT_ASSERT_EQUAL( 2, spy.count() );
        CPPUNIT_ASSERT( wd.atEnd() );
    }
}
예제 #2
0
void AnimatedInst::draw(GameState* gs) {
	GameView& view = gs->view();
	if (sprite > -1) {
		GLimage& img = game_sprite_data[sprite].img();

		int w = img.width, h = img.height;
		int xx = x - w / 2, yy = y - h / 2;

		if (!view.within_view(xx, yy, w, h))
			return;
		if (!gs->object_visible_test(this))
			return;

		Colour alphacol(255, 255, 255, 255 * timeleft / animatetime);

		gl_draw_sprite(view, sprite, xx, yy, orientx, orienty, gs->frame(),
				alphacol);
	}
	Colour wd(255 - textcol.r, 255 - textcol.g, 255 - textcol.b);
	if (text.size() > 0) {
		Colour alphacol = textcol;
		if (timeleft > -1) {
			int fade = 100 * timeleft / animatetime;
			alphacol = Colour(textcol.r + fade * wd.r / 100,
					textcol.g + fade * wd.g / 100,
					textcol.b + fade * wd.b / 100, 255 - fade);
		}
		gl_printf(gs->primary_font(), alphacol, x - view.x, y - view.y, "%s",
				text.c_str());
	}
}
예제 #3
0
vec spectrum(const vec &v, const vec &w, int noverlap)
{
  int nfft = w.size();
  it_assert_debug(pow2i(levels2bits(nfft)) == nfft,
                  "The window size must be a power of two in spectrum()!");

  vec P(nfft / 2 + 1), wd(nfft);

  P = 0.0;
  double w_energy = energy(w);

  if (nfft > v.size()) {
    P = sqr(abs(fft(to_cvec(elem_mult(zero_pad(v, nfft), w)))(0, nfft / 2)));
    P /= w_energy;
  }
  else {
    int k = (v.size() - noverlap) / (nfft - noverlap), idx = 0;
    for (int i = 0; i < k; i++) {
      wd = elem_mult(v(idx, idx + nfft - 1), w);
      P += sqr(abs(fft(to_cvec(wd))(0, nfft / 2)));
      idx += nfft - noverlap;
    }
    P /= k * w_energy;
  }

  P.set_size(nfft / 2 + 1, true);
  return P;
}
예제 #4
0
    nth_kday_type
    get_nth_kday_type(stream_itr_type& sitr,
                      stream_itr_type& stream_end,
                      std::ios_base& a_ios,
                      const facet_type& facet) const
    {
      // skip leading whitespace
      while(std::isspace(*sitr) && sitr != stream_end) { ++sitr; }
 
      typename nth_kday_type::week_num wn;
      day_of_week_type wd(0); // no default constructor
      month_type m(1);        // no default constructor

      match_results mr = m_element_strings.match(sitr, stream_end);
      switch(mr.current_match) {
        case first  : { wn = nth_kday_type::first; break; }
        case second : { wn = nth_kday_type::second; break; }
        case third  : { wn = nth_kday_type::third; break; }
        case fourth : { wn = nth_kday_type::fourth; break; }
        case fifth  : { wn = nth_kday_type::fifth; break; }
        default:
        {
          boost::throw_exception(std::ios_base::failure("Parse failed. No match found for '" + mr.cache + "'"));
          BOOST_DATE_TIME_UNREACHABLE_EXPRESSION(wn = nth_kday_type::first);
        }
      }                                         // week num
      facet.get(sitr, stream_end, a_ios, wd);   // day_of_week
      extract_element(sitr, stream_end, of);    // "of" element
      facet.get(sitr, stream_end, a_ios, m);    // month

      return nth_kday_type(wn, wd, m);
    }
예제 #5
0
int main(int argc, char* argv[])
      {
#if 0
      logFile.setFileName("mtest.log");
      if (!logFile.open(QIODevice::WriteOnly)) {
            fprintf(stderr, "mtest: cannot open log file <mtest.log>\n");
            exit(-1);
            }
#endif
      QDir wd(QDir::current());
#ifdef Q_OS_MAC
      wd.cdUp();
#endif

#if 0
      scanDir(wd);
#else
      for (const char* s : tests)
            process(s);
#endif

      printf("\n");
      printf("================\n");
      printf("  processed %d  -- failed %d\n", processed, failed);
      printf("================\n");
      return 0;
      }
예제 #6
0
void ComputeMgr::updateComputes2(CkQdMsg *msg)
{
    delete msg;

    CProxy_WorkDistrib wd(CkpvAccess(BOCclass_group).workDistrib);
    WorkDistrib  *workDistrib = wd.ckLocalBranch();
    workDistrib->saveComputeMapChanges(CkIndex_ComputeMgr::updateComputes3(),thisgroup);
}
예제 #7
0
bool OpenGLContext::makeCurrentWithWindow(agpu_pointer window)
{
    WithX11Display wd(display);
    auto res = glXMakeCurrent(display, (Window)window, context) == True;
    if(res)
        currentGLContext = this;
    return res;
}
예제 #8
0
 virtual void visit(const ConstElementPtr& e)
 {
   if (e->getElementType() == ElementType::Way)
   {
     WayDiscretizer wd(_map->shared_from_this(), dynamic_pointer_cast<const Way>(e));
     wd.discretize(_spacing, _result);
   }
 }
예제 #9
0
bool wxAppBase::SafeYield(wxWindow *win, bool onlyIfNeeded)
{
    wxWindowDisabler wd(win);

    wxEventLoopBase * const loop = wxEventLoopBase::GetActive();

    return loop && loop->Yield(onlyIfNeeded);
}
예제 #10
0
bool wxAppBase::SafeYieldFor(wxWindow *win, long eventsToProcess)
{
    wxWindowDisabler wd(win);

    wxEventLoopBase * const loop = wxEventLoopBase::GetActive();

    return loop && loop->YieldFor(eventsToProcess);
}
예제 #11
0
void ShaderBoldLineGen::set_width(float32 w)
{
	QOpenGLFunctions* ogl = QOpenGLContext::currentContext()->functions();
	GLint viewport[4];
	ogl->glGetIntegerv(GL_VIEWPORT, viewport);
	QSizeF wd(w / float32(viewport[2]), w / float32(viewport[3]));
	prg_.setUniformValue(unif_width_, wd);
}
예제 #12
0
bool OpenGLContext::makeCurrent()
{
    WithX11Display wd(display);
    auto res = glXMakeCurrent(display, window, context) == True;
    if(res)
        currentGLContext = this;
    return res;
}
예제 #13
0
 void tst1() {
     std::cerr << singleton(10) << "\n";
     std::cerr << all() << "\n";
     std::cerr << l(-10) << "\n";
     std::cerr << r(10) << "\n";
     std::cerr << l(-10, true) << "\n";
     std::cerr << r(10, true) << "\n";
     std::cerr << b(2, 10) << "\n";
     std::cerr << wd(b(-5, 5, true, false, 1, 2) * b(-5, 5, false, true, 3, 4)) << "\n";
     std::cerr << wd(l(2, false, 1) / b(2, 6, false, false, 2, 3)) << "\n";
     std::cerr << wd(expt(b(-2, 3, true, false, 1, 2), 2)) << "\n";
     std::cerr << wd(expt(b(-4, 3, true, false, 1, 2), 2)) << "\n";
     std::cerr << wd(expt(b(2, 4, true, false, 1, 2), 2)) << "\n";
     std::cerr << wd(expt(b(0, 3, true, false, 1, 2), 2)) << "\n";
     std::cerr << wd(expt(b(-4, -2, true, false, 1, 2), 2)) << "\n";
     std::cerr << b(2, 10, false, false, 1, 2) << " * " << l(10, false, 3).inv() << " = " << wd(b(2, 10, false, false, 1, 2) / l(10, false, 3)) << "\n";
     std::cerr << b(-2, -1, false, true) << " * " << b(-3,0) << " = "; std::cerr.flush();
     std::cerr << (b(-2, -1, false, true) * b(-3,0)) << "\n";
     std::cerr << b(1, 2, true, false) << " * " << b(0,3) << " = "; std::cerr.flush();
     std::cerr << (b(1, 2, true, false) * b(0,3)) << "\n";
     std::cerr << b(1, 2, true, true) << " * " << b(-3,0) << " = "; std::cerr.flush();
     std::cerr << (b(1, 2, true, true) * b(-3,0)) << "\n";
     std::cerr << b(10,20) << " / " << b(0,1,true,false) << " = "; std::cerr.flush();
     std::cerr << (b(10,20)/b(0,1,true,false)) << "\n";
     std::cerr << (b(10,20)/b(0,2,true,false)) << "\n";
 }
예제 #14
0
// fill mode 3 background with a color
void m3_fill(COLOR clr)
{
	int ii;
	u32 *dst = (u32*)vid_mem;
	u32 wd (clr<<16) | clr;

	for (ii = 0; ii < M3_SIZE / 4; ii++)
		*dst++ = wd;
}
예제 #15
0
int main(int argc, char *argv[]){
	srand((unsigned int)time(0));

	WorldDrawer wd(argc, argv, 800, 600, 200, 200, std::string("Tema 3: Labyrinth"));
	wd.init();
	wd.run();
	
	return 0;
}
예제 #16
0
bool wipe_directory(const std::string &mountpoint, bool wipe_media)
{
    struct stat sb;
    if (stat(mountpoint.c_str(), &sb) < 0 && errno == ENOENT) {
        // Don't fail if directory does not exist
        return true;
    }

    WipeDirectory wd(mountpoint, wipe_media);
    return wd.run();
}
예제 #17
0
bool
ChartBase::
finalPunc(const char* wrd)
{
  ECString wd(wrd);
  ECStringsIter ei = Term::Colons.begin();
  for( ; ei!= Term::Colons.end() ; ei++) if(wrd == *ei) return true;
  ei = Term::Finals.begin();
  for( ; ei!= Term::Finals.end() ; ei++) if(wrd == *ei) return true;
  return false;
}
예제 #18
0
int main(int argc, char** argv)
{
	std::unique_ptr<WeatherData> wd (new WeatherData);
	std::unique_ptr<CurrentConditionsDisplay> ccd (new CurrentConditionsDisplay(*wd));
	
	wd->registerObserver(ccd.get());
	wd->setParameters(1,2,3);
	ccd->display();

	return 0;
}
예제 #19
0
void GUIYield()
{
  wxEventLoopBase *const eventLoop = wxEventLoopBase::GetActive();
  wxASSERT(eventLoop != NULL);

  if (!eventLoop->IsYielding())
  {
    wxWindowDisabler wd((wxWindow*)NULL);
    eventLoop->YieldFor(wxEVT_CATEGORY_NATIVE_EVENTS | wxEVT_CATEGORY_TIMER);
  }
}
예제 #20
0
void EditSolutionDialog::on_aw_clicked()
{
    QString wine = ui->aw->property("wine").toString();
    WineDialog wd(wine, mWineModel, this);
    if (wd.exec() == WineDialog::Accepted)
    {
        setWine(ui->aw, wd.wine());
        if (ui->lockBtn->isChecked())
            setWine(ui->bw, ui->aw->property("wine"));
    }
}
예제 #21
0
파일: utilscmn.cpp 프로젝트: 252525fb/rpcs3
// Yield to other apps/messages and disable user input to all windows except
// the given one
bool wxSafeYield(wxWindow *win, bool onlyIfNeeded)
{
    wxWindowDisabler wd(win);

    bool rc;
    if (onlyIfNeeded)
        rc = wxYieldIfNeeded();
    else
        rc = wxYield();

    return rc;
}
예제 #22
0
int wxGUIAppTraits::WaitForChild(wxExecuteData& execData)
{
    // prepare to wait for the child termination: show to the user that we're
    // busy and refuse all input unless explicitly told otherwise
    wxBusyCursor bc;
    wxWindowDisabler wd(!(execData.flags & wxEXEC_NODISABLE));

    // Allocate an event loop that will be used to wait for the process
    // to terminate, will handle stdout, stderr, and any other events and pass
    // it to the common (to console and GUI) code which will run it.
    wxGUIEventLoop loop;
    return RunLoopUntilChildExit(execData, loop);
}
예제 #23
0
/**
 * Check the working directory for a weather model data directory
 *
 */
void weatherModel::checkForModelData()
{
    QDir wd(cwd);

    QStringList filters;
    /* ndfd */
    filters << QString::fromStdString( ndfd.getForecastIdentifier() )
               + "-" + QFileInfo( inputFile ).fileName();
    /* nam suface */
    filters << QString::fromStdString( nam.getForecastIdentifier() )
               + "-" + QFileInfo( inputFile ).fileName();
    /* rap surface */
    filters << QString::fromStdString( rap.getForecastIdentifier() )
            + "-" + QFileInfo( inputFile ).fileName();
    /* dgex surface */
    //filters << QString::fromStdString( dgex.getForecastIdentifier() )
    //	+ "-" + QFileInfo( inputFile ).fileName();
    /* nam alaska surface */
    filters << QString::fromStdString( namAk.getForecastIdentifier() )
               + "-" + QFileInfo( inputFile ).fileName();
    /* gfs */
    filters << QString::fromStdString( gfs.getForecastIdentifier() )
               + "-" + QFileInfo( inputFile ).fileName();

#ifdef WITH_NOMADS_SUPPORT
    int i;
    for( i = 0; i < nNomadsCount; i++ )
    {
        filters << 
            (QString::fromStdString(papoNomads[i]->getForecastReadable('-') )
                    + "-" + QFileInfo( inputFile ).fileName()).toUpper();
    }
    filters << "20*.zip";
#endif
    //filter to see the folder in utc time
    filters << "20*T*";
    filters << "*.nc";
    model->setNameFilters(filters);
    model->setFilter(QDir::Files | QDir::Dirs);
    treeView->setRootIndex(model->index(wd.absolutePath()));
    treeView->resizeColumnToContents(0);
    statusLabel->setText( "" );

    unselectForecast(false);
    // QModelIndex index = treeView->indexBelow( treeView->rootIndex() );
    // treeView->setExpanded( index, true );
    // index = treeView->indexBelow( index );
    // treeView->setExpanded( index, true );
}
예제 #24
0
int main(int argc, char *argv[])
{
	dict_elem_t *head_p;
	int total;
	char *value;

	dict_elem_t *elem_fund;

	FILE *fp_b;

	switch(argc) {
		case 2: //
			if (strcmp(argv[1], "-test1") == 0) {
				wd();
			} else if (strcmp(argv[1], "-test2") == 0){
				if ((fp_b = fopen("dict.dat","rb")) == NULL) {
						total = get_elem_count("dict.txt");
						head_p = malloc(total * sizeof(*head_p));
						head_p = read_to_mem_from_txt("dict.txt", head_p, total);

						if ((value = bd_fwrite(head_p, total, "dict.dat")) == NULL)
						{
							printf("error in bd_fwrite() \n");
							return NULL;
						}

				} else {
					fread(&total, sizeof(total), 1, fp_b);
					head_p = malloc(total * sizeof(*head_p));
					head_p = bd_fread(head_p, total);
				}
				print_data(head_p, total);
			} else {
				printf("please input right args");
				return -1;
			}
			break;
		case 4:
			break;
		default :
				printf("please input right args");
				return -1;
	}



	return 0;
}
static  void ICACHE_FLASH_ATTR pollThermostatCb(void * arg)
{
		unsigned long epoch = sntp_time+(sntp_tz*3600);
		int year=get_year(&epoch);
		int month=get_month(&epoch,year);
		int day=day=1+(epoch/86400);
		int dow=wd(year,month,day);
		epoch=epoch%86400;
		unsigned int hour=epoch/3600;
		epoch%=3600;
		unsigned int min=epoch/60;
		int minadj = (min*100/60);
		int currtime = hour*100+minadj;
				
		if(sysCfg.thermostat1state == 0) {
			os_printf("Thermostat switched off, abandoning routine.\n");
			return;
		}
		
		long Treading=-9999;
		
		if(sysCfg.sensor_dht22_enable) { 
			struct sensor_reading* result = readDHT();
			if(result->success) {
				Treading=result->temperature*100;
				if(sysCfg.thermostat1_input==2) // Humidistat
					Treading=result->humidity*100;
			}			
		}
		else { if(sysCfg.sensor_ds18b20_enable && sysCfg.thermostat1_input==0 ) { 
			struct sensor_reading* result = read_ds18b20();
			if(result->success) {
			    int SignBit, Whole, Fract;
				Treading = result->temperature;
				
				SignBit = Treading & 0x8000;  // test most sig bit
				if (SignBit) // negative
				Treading = (Treading ^ 0xffff) + 1; // 2's comp
	
				Whole = Treading >> 4;  // separate off the whole and fractional portions
				Fract = (Treading & 0xf) * 100 / 16;

				if (SignBit) // negative
					Whole*=-1;
				Treading=Whole*100+Fract;
			}
		}//ds8b20 enabled
		}
예제 #26
0
bool wipe_directory(const std::string &directory,
                    const std::vector<std::string> &exclusions)
{
    struct stat sb;
    if (stat(directory.c_str(), &sb) < 0 && errno == ENOENT) {
        // Don't fail if directory does not exist
        return true;
    }

    std::vector<std::string> new_exclusions{ "multiboot" };
    new_exclusions.insert(new_exclusions.end(),
                          exclusions.begin(), exclusions.end());

    WipeDirectory wd(directory, std::move(new_exclusions));
    return wd.run();
}
예제 #27
0
    kday_after_type
    get_kday_after_type(stream_itr_type& sitr,
                        stream_itr_type& stream_end,
                        std::ios_base& a_ios,
                        const facet_type& facet) const
    {
      // skip leading whitespace
      while(std::isspace(*sitr) && sitr != stream_end) { ++sitr; }

      day_of_week_type wd(0); // no default constructor

      facet.get(sitr, stream_end, a_ios, wd);   // day_of_week
      extract_element(sitr, stream_end, after); // "after" element

      return kday_after_type(wd);
    }
예제 #28
0
 void removePrefix(const QString &prefixHash, QWidget *parent)
 {
     WaitDialog wd(parent);
     QObject *worker = new QObject;
     worker->moveToThread(new QThread);
     wd.connect(worker->thread(), &QThread::started, worker, [worker, prefixHash]()
     {
         prefix(prefixHash).removeRecursively();
         worker->deleteLater();
     });
     wd.connect(worker, &QObject::destroyed, worker->thread(), &QThread::quit);
     wd.connect(worker->thread(), &QThread::finished, worker->thread(), &QThread::deleteLater);
     wd.connect(worker->thread(), &QThread::destroyed, &wd, &WaitDialog::accept);
     worker->thread()->start();
     wd.exec();
 }
예제 #29
0
double ProbabilityOfMatch::distanceScore(const ConstOsmMapPtr& map, const shared_ptr<const Way>& w1,
  const shared_ptr<const LineString>& ls2, Meters circularError)
{
  Meters distanceSum = 0.0;

  vector<Coordinate> v;
  WayDiscretizer wd(map, w1);
  wd.discretize(2.0, v);

  _dMax = 0.0;

  for (size_t i = 0; i < v.size(); i++)
  {
    Point* point(GeometryFactory::getDefaultInstance()->createPoint(v[i]));
    if (debug)
    {
      cout << "distance " << ls2->distance(point) << endl;
    }
    double d = ls2->distance(point);
    distanceSum += d;
    _dMax = max(d, _dMax);
    delete point;
  }

  _dMax /= (circularError + w1->getCircularError());

  Meters distanceMean = distanceSum / v.size();

  /// @todo Make me better.
  // E.g. if s1 = 50 & s2 = 50, then sigma = 70.
  // This is a placeholder for the probability. Mike Porter will help me out w/ a better
  // approximation later.
  double s1 = w1->getCircularError() / 2.0;
  double s2 = circularError / 2.0;
  double sigma = sqrt(s1 * s1 + s2 * s2);

  // The rational here is that we can calculate the
  double p = 1 - (Normal::phi(distanceMean, sigma) - 0.5) * 2.0;

  if (debug)
  {
    LOG_INFO("" << "distanceMean: " << distanceMean);
    LOG_INFO("" << "  s1: " << s1 << " s2: " << s2 << " sigma: " << sigma << " p: " << p);
  }

  return p;
}
예제 #30
0
int main(int argc, char ** argv)
{
  ros::init(argc, argv, "fcu");
  ros::NodeHandle nh("fcu");


  std::string port, portRX, portTX;
  int baudrate;
  ros::NodeHandle pnh("~");
  CommPtr comm(new Comm);

  bool connected = false;

  pnh.param("baudrate", baudrate, HLI_DEFAULT_BAUDRATE);

  if (pnh.getParam("serial_port_rx", portRX) && pnh.getParam("serial_port_tx", portTX))
  {
    connected = comm->connect(portRX, portTX, baudrate);
  }
  else
  {
    pnh.param("serial_port", port, std::string("/dev/ttyUSB0"));
    connected = comm->connect(port, port, baudrate);
  }

  if (!connected)
  {
    ROS_ERROR("unable to connect");
    ros::Duration(2).sleep();
    return -1;
  }

  HLInterface asctecInterface(nh, comm);
  SSDKInterface ssdk_if(nh, comm);
  EKFInterface ekf_if(nh, comm);

  printTopicInfo();

  Watchdog wd(comm);

  ros::spin();


  return 0;
}