Пример #1
0
int hpx_main(boost::program_options::variables_map& vm)
{
    std::size_t size = 1;
    for (std::size_t i = 0; i != 20; ++i) {
        // create argument for action
        std::vector<double> data1;
        data1.resize(size << i);

        hpx::serialization::serialize_buffer<double> buffer1(data1.data(), data1.size(),
            hpx::serialization::serialize_buffer<double>::reference);

        test_normal_serialization<test_action1>(buffer1);
        test_zero_copy_serialization<test_action1>(buffer1);

        std::vector<int> data2;
        data2.resize(size << i);

        hpx::serialization::serialize_buffer<int> buffer2(data2.data(), data2.size(),
            hpx::serialization::serialize_buffer<int>::reference);

        test_normal_serialization(buffer1, buffer2);
        test_zero_copy_serialization(buffer1, buffer2);
        test_normal_serialization(42.0, buffer1, "42.0", 42, buffer2);
        test_zero_copy_serialization(42.0, buffer1, "42.0", 42, buffer2);

        data_buffer<double> buffer3(size << i);
        test_normal_serialization<test_action4>(buffer3);
        test_zero_copy_serialization<test_action4>(buffer3);
    }

    return hpx::finalize();
}
Пример #2
0
int main() {

    Buffer buffer1(10);
    Buffer buffer2(10);
    LeftToRight l2r(&buffer1, &buffer2);
    RightToLeft r2l(&buffer1, &buffer2);

    pthread_t threads[2];
    
    pid_t pid = getpid();
    printf("main pid=%d\n", pid);
    int rc = pthread_create(&threads[0], 0, startThread, (void *)&l2r);
    if (rc) {
        printf("ERROR; return code from pthread_create() is %d\n", rc);
        exit(1);
    }
    rc = pthread_create(&threads[1], 0, startThread, (void *)&r2l);
    if (rc) {
        printf("ERROR; return code from pthread_create() is %d\n", rc);
        exit(1);
    }

    pthread_join(threads[0], 0);
    threads[0] = 0;
    pthread_join(threads[1], 0);
    threads[1] = 0;

    return 0;
}
Пример #3
0
UString UDES3::signData(const char* fmt, ...)
{
   U_TRACE(0, "UDES3::signData(%S)", fmt)

   uint32_t sz1;
   UString buffer1(U_CAPACITY), buffer2(U_CAPACITY), signed_data(U_CAPACITY);

   va_list argp;
   va_start(argp, fmt);

   buffer1.vsnprintf(fmt, argp);

   va_end(argp);

   sz1 = buffer1.size();

   if (sz1 <= 512) encode((const unsigned char*)buffer1.data(), sz1, buffer2);
   else
      {
      UString data = UStringExt::compress(buffer1.data(), sz1);
      uint32_t sz2 = data.size();

      if (sz2 < (sz1 - (sz1 / 4))) encode((const unsigned char*)   data.data(), sz2, buffer2);
      else                         encode((const unsigned char*)buffer1.data(), sz1, buffer2);
      }

   UBase64::encode(buffer2, signed_data);

   U_RETURN_STRING(signed_data);
}
Пример #4
0
TEST(Channel, write_Buffers) {
  Buffer buffer2(Buffer::getpagesize());
  buffer2.put(NULL, Buffer::getpagesize() / 4);
  Buffer buffer1(Buffer::getpagesize());
  buffer1.put(NULL, Buffer::getpagesize() / 4);
  buffer1.set_next_buffer(buffer2.inc_ref());
  ssize_t write_ret = MockChannel().write(buffer1);
  ASSERT_EQ(write_ret, static_cast<ssize_t>(Buffer::getpagesize() / 2));
}
Пример #5
0
TEST(Channel, read_Buffers) {
  Buffer buffer2(Buffer::getpagesize());
  Buffer buffer1(Buffer::getpagesize());
  buffer1.set_next_buffer(buffer2.inc_ref());
  ssize_t read_ret = MockChannel().read(buffer1);
  ASSERT_EQ(read_ret, static_cast<ssize_t>(Buffer::getpagesize() / 2));
  ASSERT_EQ(buffer1.size(), Buffer::getpagesize() / 2);
  ASSERT_EQ(buffer2.size(), 0);
}
Пример #6
0
void Parser::update(const std::string& delims, const std::string& buffer)
{
this->delims=delims;
token.clear();
std::string buffer1(buffer,0,buffer.size());
char* stoken=strtok((char*)buffer1.c_str(),this->delims.c_str());
while (stoken!=NULL)
	{
	token.push_back(stoken);
	stoken=strtok(NULL,this->delims.c_str());
	}
}
Пример #7
0
Parser::Parser(const std::string& delims, const std::string& buffer)
{
this->delims=delims;
//per non modificare la stringa
std::string buffer1(buffer,0,buffer.size());
//per non modificare la stringa
char* stoken=strtok((char*)buffer1.c_str(),this->delims.c_str());
while (stoken!=NULL)
	{
	token.push_back(stoken);
	stoken=strtok(NULL,this->delims.c_str());
	}
}
Пример #8
0
bool LineSegment::colinear(const LineSegment& l) const   // lines are colinear if their slopes are the same AND if there is a point they both pass through
{
  if(l.slope() != slope()) return false;

  // assert: lines are the same slope
 
  LineSegment buffer1(l); // to preserve const
  LineSegment buffer2(*this);
  
  if( findIntersection(buffer1, buffer2, true) == noCoord) // check for a point lying on both lines
    return false;

  // assert: we found a point that lies on both lines  
  return true;
}
Пример #9
0
TEST(CBuffer2D, Arithmetic)
{
  const int64_t cols = 16;
  const int64_t rows = 8;

  CBuffer2D buffer1(cols, rows, Complex(3.0,  4.0));
  CBuffer2D buffer2(cols, rows, Complex(3.0, -4.0));

  CBuffer2D bufferSum1(cols, rows);
  bufferSum1.assign(buffer1 + buffer2);
  for (int64_t y = 0; y < rows; ++y)
    for (int64_t x = 0; x < cols; ++x)
      EXPECT_EQ(Complex(6.0, 0.0), bufferSum1.pixel(x, y));

  CBuffer2D bufferSum2(cols, rows);
  bufferSum2.assign(buffer1);
  bufferSum2 += buffer2;
  for (int64_t y = 0; y < rows; ++y)
    for (int64_t x = 0; x < cols; ++x)
      EXPECT_EQ(Complex(6.0, 0.0), bufferSum2.pixel(x, y));

  CBuffer2D bufferProduct1(cols, rows);
  bufferProduct1.assign(buffer1 * buffer2);
  for (int64_t y = 0; y < rows; ++y)
    for (int64_t x = 0; x < cols; ++x)
      EXPECT_EQ(Complex(25.0, 0.0), bufferProduct1.pixel(x, y));

  CBuffer2D bufferProduct2(cols, rows);
  bufferProduct2.assign(buffer1);
  bufferProduct2 *= buffer2;
  for (int64_t y = 0; y < rows; ++y)
    for (int64_t x = 0; x < cols; ++x)
      EXPECT_EQ(Complex(25.0, 0.0), bufferProduct2.pixel(x, y));

  CBuffer2D bufferScale1(cols, rows);
  bufferScale1.assign(2.0 * buffer1);
  for (int64_t y = 0; y < rows; ++y)
    for (int64_t x = 0; x < cols; ++x)
      EXPECT_EQ(Complex(6.0, 8.0), bufferScale1.pixel(x, y));

  CBuffer2D bufferScale2(cols, rows);
  bufferScale2.assign(buffer1);
  bufferScale2 *= 0.5;
  for (int64_t y = 0; y < rows; ++y)
    for (int64_t x = 0; x < cols; ++x)
      EXPECT_EQ(Complex(1.5, 2.0), bufferScale2.pixel(x, y));
}
void dng_image::GetEdge (dng_pixel_buffer &buffer,
					     edge_option edgeOption,
				         const dng_rect &srcArea,
				         const dng_rect &dstArea) const
	{
	
	switch (edgeOption)
		{
		
		case edge_zero:
			{
			
			buffer.SetZero (dstArea,
							buffer.fPlane,
							buffer.fPlanes);
							
			break;
			
			}
			
		case edge_repeat:
			{
			
			GetRepeat (buffer,
					   srcArea,
					   dstArea);
					   
			break;
						
			}
			
		case edge_repeat_zero_last:
			{
			
			if (buffer.fPlanes > 1)
				{
			
				dng_pixel_buffer buffer1 (buffer);
				
				buffer1.fPlanes--;
				
				GetEdge (buffer1,
						 edge_repeat,
						 srcArea,
						 dstArea);
						 
				}
				
			dng_pixel_buffer buffer2 (buffer);
			
			buffer2.fPlane  = buffer.fPlanes - 1;
			buffer2.fPlanes = 1;
			
			buffer2.fData = buffer.DirtyPixel (buffer2.fArea.t,
										  	   buffer2.fArea.l,
										  	   buffer2.fPlane);
										  
			GetEdge (buffer2,
					 edge_zero,
					 srcArea,
					 dstArea);
					 
			break;
			
			}
			
		default:
			{
			
			ThrowProgramError ();
			
			}
			
		}
	
	}
Пример #11
0
void testCMarginBuffer()
{
  const int64_t cols     = 23;
  const int64_t rows        = 54;
  const int64_t numPixels   = cols * rows;
  const int64_t numElements = (cols + 2 * margin) * (rows + 2 * margin);

  CMarginBuffer2D<margin> buffer1(cols, rows);

  EXPECT_EQ(cols, buffer1.cols());
  EXPECT_EQ(rows, buffer1.rows());
  EXPECT_EQ(numPixels, buffer1.numPixels());
  EXPECT_EQ(numElements, buffer1.numElements());

  // generate test data
  generateTestData(buffer1);

  // check the data in the buffer
  for (int64_t y = 0; y < rows; ++y)
  {
    for (int64_t x = 0; x < cols; ++x)
    {
      EXPECT_EQ(Complex(std::sin(static_cast<Real>(y)), static_cast<Real>(x)),
                buffer1.pixel(x, y));
    }
  }

  // create a compatible buffer
  auto buffer2 = buffer1.createCompatibleBuffer();

  EXPECT_EQ(cols, buffer1.cols());
  EXPECT_EQ(rows, buffer2.rows());
  EXPECT_EQ(numPixels, buffer2.numPixels());
  EXPECT_EQ(numElements, buffer2.numElements());
  EXPECT_TRUE(buffer1.compatible(buffer2));
  EXPECT_TRUE(buffer2.compatible(buffer1));

  // copy the data in the new buffer
  buffer2.assign(buffer1);

  // clear the first buffer
  const Complex clearValue(42.0, -8.0);
  buffer1.setValue(clearValue);

  // check the data in the first buffer
  for (int64_t y = 0; y < rows; ++y)
    for (int64_t x = 0; x < cols; ++x)
      EXPECT_EQ(clearValue, buffer1.pixel(x, y));

  // check the data in the second buffer
  for (int64_t y = 0; y < rows; ++y)
  {
    for (int64_t x = 0; x < cols; ++x)
    {
       EXPECT_EQ(Complex(std::sin(static_cast<Real>(y)), static_cast<Real>(x)),
                 buffer2.pixel(x, y));
    }
  }

  // test addAssign
  buffer1.setValue(Complex(1.0, -1.0));
  generateTestData(buffer2);
  buffer1 += buffer2;
  for (int64_t y = 0; y < rows; ++y)
  {
    for (int64_t x = 0; x < cols; ++x)
    {
      EXPECT_EQ(Complex(std::sin(static_cast<Real>(y)) + R(1.0),
                        static_cast<Real>(x) - R(1.0)),
                        buffer1.pixel(x, y));
    }
  }

  // test multiplyAssign(CMarginBuffer)
  buffer1.setValue(Complex(1.0, -1.0));
  generateTestData(buffer2);
  buffer1 *= buffer2;
  for (int64_t y = 0; y < rows; ++y)
  {
    for (int64_t x = 0; x < cols; ++x)
    {
      EXPECT_EQ(Complex(std::sin(static_cast<Real>(y)) + static_cast<Real>(x),
                        -std::sin(static_cast<Real>(y)) + static_cast<Real>(x)),
                        buffer1.pixel(x, y));
     }
  }

  // test multiplyAssign(Complex)
  generateTestData(buffer1);
  buffer1 *= Complex(1.0, -1.0);
  for (int64_t y = 0; y < rows; ++y)
  {
    for (int64_t x = 0; x < cols; ++x)
    {
      EXPECT_EQ(Complex(std::sin(static_cast<Real>(y)) + static_cast<Real>(x),
                        -std::sin(static_cast<Real>(y)) + static_cast<Real>(x)),
                        buffer1.pixel(x, y));
     }
  }

  // test multiplyAssign(Real)
  generateTestData(buffer1);
  buffer1 *= 5.0;
  for (int64_t y = 0; y < rows; ++y)
  {
    for (int64_t x = 0; x < cols; ++x)
    {
      EXPECT_EQ(Complex(std::sin(static_cast<Real>(y)) * R(5.0),
                        static_cast<Real>(x) * R(5.0)),
                        buffer1.pixel(x, y));
     }
  }

  // create a third buffer
  const Complex initialValue(-49.0, 7.0);
  CMarginBuffer2D<margin> buffer3(cols + 1, rows, initialValue);
  EXPECT_FALSE(buffer3.compatible(buffer1));
  EXPECT_FALSE(buffer1.compatible(buffer3));

  for (int64_t y = 0; y < rows; ++y)
    for (int64_t x = 0; x < cols; ++x)
      EXPECT_EQ(initialValue, buffer3.pixel(x, y));

  std::mt19937 generator;
  std::uniform_real_distribution<Real> distribution(0.0, Math::twoPi);
  for (int64_t y = 0; y < rows; ++y)
    for (int64_t x = 0; x < cols + 1; ++x)
      buffer3.pixel(x, y) = fromArg(distribution(generator));

  EXPECT_EQ(buffer3.numPixels(), buffer3.absSqrReduce());

  // todo: test multiplyAssign
  // todo: test info
}
Пример #12
0
void
DownloadProgressView::_UpdateStatusText()
{
	fInfoView->SetText("");
	BString buffer;
	if (sShowSpeed && fBytesPerSecond != 0.0) {
		// Draw speed info
		char sizeBuffer[128];
		buffer = "(";
		// Get strings for current and expected size and remove the unit
		// from the current size string if it's the same as the expected
		// size unit.
		BString currentSize = string_for_size((double)fCurrentSize, sizeBuffer,
			sizeof(sizeBuffer));
		BString expectedSize = string_for_size((double)fExpectedSize, sizeBuffer,
			sizeof(sizeBuffer));
		int currentSizeUnitPos = currentSize.FindLast(' ');
		int expectedSizeUnitPos = expectedSize.FindLast(' ');
		if (currentSizeUnitPos >= 0 && expectedSizeUnitPos >= 0
			&& strcmp(currentSize.String() + currentSizeUnitPos,
				expectedSize.String() + expectedSizeUnitPos) == 0) {
			currentSize.Truncate(currentSizeUnitPos);
		}
		buffer << currentSize;
		buffer << " of ";
		buffer << expectedSize;
		buffer << ", ";
		buffer << string_for_size(fBytesPerSecond, sizeBuffer,
			sizeof(sizeBuffer));
		buffer << "/s)";
		float stringWidth = fInfoView->StringWidth(buffer.String());
		if (stringWidth < fInfoView->Bounds().Width())
			fInfoView->SetText(buffer.String());
		else {
			// complete string too wide, try with shorter version
			buffer << string_for_size(fBytesPerSecond, sizeBuffer,
				sizeof(sizeBuffer));
			buffer << "/s";
			stringWidth = fInfoView->StringWidth(buffer.String());
			if (stringWidth < fInfoView->Bounds().Width())
				fInfoView->SetText(buffer.String());
		}
	} else if (!sShowSpeed && fCurrentSize < fExpectedSize) {
		double totalBytesPerSecond = (double)(fCurrentSize
				- fEstimatedFinishReferenceSize)
			* 1000000LL / (system_time() - fEstimatedFinishReferenceTime);
		double secondsRemaining = (fExpectedSize - fCurrentSize)
			/ totalBytesPerSecond;
		time_t now = (time_t)real_time_clock();
		time_t finishTime = (time_t)(now + secondsRemaining);

		tm _time;
		tm* time = localtime_r(&finishTime, &_time);
		int32 year = time->tm_year + 1900;

		char timeText[32];
		time_t secondsPerDay = 24 * 60 * 60;
		// TODO: Localization of time string...
		if (now < finishTime - secondsPerDay) {
			// process is going to take more than a day!
			sprintf(timeText, "%0*d:%0*d %0*d/%0*d/%ld",
				2, time->tm_hour, 2, time->tm_min,
				2, time->tm_mon + 1, 2, time->tm_mday, year);
		} else {
			sprintf(timeText, "%0*d:%0*d",
				2, time->tm_hour, 2, time->tm_min);
		}

		BString buffer1("Finish: ");
		buffer1 << timeText;
		finishTime -= now;
		time = gmtime(&finishTime);

		BString buffer2;
		if (finishTime > secondsPerDay) {
			int64 days = finishTime / secondsPerDay;
			if (days == 1)
				buffer2 << "Over 1 day";
			else
				buffer2 << "Over " << days << " days";
		} else if (finishTime > 60 * 60) {
			int64 hours = finishTime / (60 * 60);
			if (hours == 1)
				buffer2 << "Over 1 hour";
			else
				buffer2 << "Over " << hours << " hours";
		} else if (finishTime > 60) {
			int64 minutes = finishTime / 60;
			if (minutes == 1)
				buffer2 << "Over 1 minute";
			else
				buffer2 << minutes << " minutes";
		} else {
			if (finishTime == 1)
				buffer2 << "1 second";
			else
				buffer2 << finishTime << " seconds";
		}

		buffer2 << " left";

		buffer = "(";
		buffer << buffer1 << " - " << buffer2 << ")";

		float stringWidth = fInfoView->StringWidth(buffer.String());
		if (stringWidth < fInfoView->Bounds().Width())
			fInfoView->SetText(buffer.String());
		else {
			// complete string too wide, try with shorter version
			buffer = "(";
			buffer << buffer1 << ")";
			stringWidth = fInfoView->StringWidth(buffer.String());
			if (stringWidth < fInfoView->Bounds().Width())
				fInfoView->SetText(buffer.String());
		}
	}
}
Пример #13
0
void ThemeCreationWizard::onFinished(int status)
{
    if (status == 0)
        return;
    try
    {
        StfsPackage *theme = new StfsPackage(ui->lblSavePath->text().toStdString(), StfsPackageCreate);

        // create a new file
        theme->metaData->magic = CON;
        theme->metaData->certificate.ownerConsoleType = consoleType;
        theme->metaData->certificate.consoleTypeFlags = (ConsoleTypeFlags)0;

        theme->metaData->contentType = Theme;
        theme->metaData->metaDataVersion = 2;
        theme->metaData->titleID = 0xFFFE07D1;

        // had to do some glitch hacks in order to get this to work. If I don't do this, the OS gives an 'Unknown Signal'
        std::wstring *w = new std::wstring(ui->txtName->text().toStdWString());
        memcpy(&theme->metaData->displayName, w, sizeof(std::wstring));

        theme->metaData->transferFlags = 0x40;

        // set gamerpicture
        QByteArray ba1;
        QBuffer buffer1(&ba1);
        buffer1.open(QIODevice::WriteOnly);
        ui->imgThumbnail->pixmap()->save(&buffer1, "PNG");
        theme->metaData->thumbnailImage = (BYTE*)ba1.data();
        theme->metaData->thumbnailImageSize = ba1.length();

        // set title thumbnail image
        QByteArray ba2;
        QBuffer buffer2(&ba2);
        buffer2.open(QIODevice::WriteOnly);
        QPixmap(":/Images/defaultTitleImage.png").save(&buffer2, "PNG");
        theme->metaData->titleThumbnailImage = (BYTE*)ba2.data();
        theme->metaData->titleThumbnailImageSize = ba2.length();

        theme->metaData->WriteMetaData();
        theme->Rehash();

        // inject the wallpapers
        injectImage(theme, &wallpaper1, "Wallpaper1");
        injectImage(theme, &wallpaper2, "Wallpaper2");
        injectImage(theme, &wallpaper3, "Wallpaper3");
        injectImage(theme, &wallpaper4, "Wallpaper4");

        // create the parameters.ini file
        QString paramsFilePath = QDir::tempPath() + "/" + QUuid::createUuid().toString().replace("{", "").replace("}", "").replace("-", "");
        QFile params(paramsFilePath);
        params.open(QIODevice::Truncate | QIODevice::WriteOnly);

        // Write the correct information to it
        QTextStream txtStream(&params);
        txtStream << "SphereColor=" << ui->cmbxSphereColor->currentIndex() << "\r\nAvatarLightingDirectional=0,0,0,0\r\nAvatarLightingAmbient=0\r\n";

        // close the file
        txtStream.flush();
        params.close();

        // inject the params file to the theme package
        theme->InjectFile(paramsFilePath.toStdString(), "parameters.ini");

        // create the dash style file
        QString dashStyleFilePath = QDir::tempPath() + "/" + QUuid::createUuid().toString().replace("{", "").replace("}", "").replace("-", "");
        FileIO ioD(dashStyleFilePath.toStdString(), true);
        ioD.Write((DWORD)0);
        ioD.Close();

        // inject the file
        theme->InjectFile(dashStyleFilePath.toStdString(), "DashStyle");

        // fix the package
        theme->Rehash();
        theme->Resign(QtHelpers::GetKVPath(theme->metaData->certificate.ownerConsoleType, this));

        // delete the temp files
        QFile::remove(paramsFilePath);
        QFile::remove(dashStyleFilePath);

        statusBar->showMessage("Theme created successfully", 3000);

        delete theme;
    }
    catch (string error)
    {
        QMessageBox::critical(this, "Error", "An error occured while creating the theme.\n\n" + QString::fromStdString(error));
    }
}