Esempio n. 1
0
  TEST(Group, Serialization)
  {
    QVector<PublicIdentity> gr;
    for(int idx = 0; idx < 100; idx++) {
      AddMember(gr);
    }

    Group group_in(gr);

    QByteArray msg;
    QDataStream stream_in(&msg, QIODevice::WriteOnly);

    stream_in << group_in;

    QDataStream stream_out(msg);
    Group group_out;
    stream_out >> group_out;

    EXPECT_EQ(group_in, group_out);
    EXPECT_EQ(gr[0], gr[0]);
    EXPECT_NE(gr[1], gr[0]);

    foreach(const PublicIdentity &gc, group_in) {
      EXPECT_TRUE(group_out.Contains(gc.GetId()));
    }
Esempio n. 2
0
File: crypt.c Progetto: vap0r/wraith
void Decrypt_File(char *infile, char *outfile)
{
  const char salt1[] = SALT1;
  bd::Stream stream_out;
  EncryptedStream stream_in(salt1);

  stream_in.loadFile(infile);
  stream_out << bd::String(stream_in);
  stream_out.writeFile(outfile);
}
Esempio n. 3
0
void
EBSDMesh::readEBSDHeader()
{
  std::ifstream stream_in(_filename.c_str());

  if (!stream_in)
    mooseError("Can't open EBSD file: " << _filename);

  // Labels to look for in the header
  std::vector<std::string> labels;
  labels.push_back("x_step"); // 0
  labels.push_back("x_dim");
  labels.push_back("y_step"); // 2
  labels.push_back("y_dim");
  labels.push_back("z_step"); // 4
  labels.push_back("z_dim");
  labels.push_back("x_min");  // 6
  labels.push_back("y_min");
  labels.push_back("z_min");

  // Dimension variables to store once they are found in the header
  // X_step, X_Dim, Y_step, Y_Dim, Z_step, Z_Dim
  // We use Reals even though the Dim values should all be integers...
  std::vector<Real> label_vals(labels.size(), 0.0);

  std::string line;
  while (std::getline(stream_in, line))
  {
    // We need to process the comment lines that have:
    // X_step, X_Dim
    // Y_step, Y_Dim
    // Z_step, Z_Dim
    // in them. The labels are case insensitive.
    if (line.find("#") == 0)
    {
      // Process lines that start with a comment character (comments and meta data)
      std::transform(line.begin(), line.end(), line.begin(), ::tolower);

      for (unsigned i=0; i<labels.size(); ++i)
        if (line.find(labels[i]) != std::string::npos)
        {
          std::string dummy;
          std::istringstream iss(line);
          iss >> dummy >> dummy >> label_vals[i];

          // One label per line, break out of for loop over labels
          break;
        }
    }
void repl(std::ostream& out)
{
    Lexer lexer(0, &out);
    ResultType result;
    Parser parser(lexer, result);
    while (true)
    {
        auto request = input();
        if (request == "exit") break;
        std::stringstream stream_in(request);
        lexer.restart(stream_in);
        if (0 == parser.parse())
        {
            std::cout << result << std::endl;
        }
    }    
}
Esempio n. 5
0
void BitStreamCompressor::decompressBytes(byte* in, byte* out, size_t count) {
	MemoryBitStream<true> stream_in(in);
	for (size_t i = 0; i < count; ++i) {
		out[i] = stream_in.readBits(kBits);
	}
}
Esempio n. 6
0
void
EBSDReader::initialSetup()
{
  // No need to re-read data upon recovery
  if (_app.isRecovering())
    return;

  // Fetch and check mesh
  EBSDMesh * mesh = dynamic_cast<EBSDMesh *>(&_mesh);
  if (mesh == NULL)
    mooseError("Please use an EBSDMesh in your simulation.");

  std::ifstream stream_in(mesh->getEBSDFilename().c_str());
  if (!stream_in)
    mooseError("Can't open EBSD file: " << mesh->getEBSDFilename());

  const EBSDMesh::EBSDMeshGeometry & g = mesh->getEBSDGeometry();

  // Copy file header data from the EBSDMesh
  _dx = g.d[0];
  _nx = g.n[0];
  _minx = g.min[0];
  _maxx = _minx + _dx * _nx;

  _dy = g.d[1];
  _ny = g.n[1];
  _miny = g.min[1];
  _maxy = _miny + _dy * _ny;

  _dz = g.d[2];
  _nz = g.n[2];
  _minz = g.min[2];
  _maxz = _minz + _dz * _nz;

  // Resize the _data array
  unsigned total_size = g.dim < 3 ? _nx*_ny : _nx*_ny*_nz;
  _data.resize(total_size);

  std::string line;
  while (std::getline(stream_in, line))
  {
    if (line.find("#") != 0)
    {
      // Temporary variables to read in on each line
      EBSDPointData d;
      Real x, y, z;

      std::istringstream iss(line);
      iss >> d.phi1 >> d.phi >> d.phi2 >> x >> y >> z >> d.grain >> d.phase >> d.symmetry;

      if (x < _minx || y < _miny || x > _maxx || y > _maxy || (g.dim == 3 && (z < _minz || z > _maxz)))
        mooseError("EBSD Data ouside of the domain declared in the header ([" << _minx << ':' << _maxx << "], [" << _miny << ':' << _maxy << "], [" << _minz << ':' << _maxz << "]) dim=" << g.dim << "\n" << line);

      d.p = Point(x,y,z);

      // determine number of grains in the dataset
      if (d.grain > _feature_num) _feature_num = d.grain;

      // The Order parameter is not yet assigned.
      // We initialize it to zero in order not to have undefined values that break the testing.
      d.op = 0;

      unsigned global_index = indexFromPoint(Point(x, y, z));
      _data[global_index] = d;
    }
  }