Example #1
0
/**
 * Loads the header of a glove data file.
 * This is both for the samples and for the trained files.
 *
 * The header format is:
 *   -Comments -- # starting<br>
 *   - num gestures<br>
 *   -Gesture names<br>
 *   -Gesture samples<br>
 *
 * @param infile A file that is already open and ready for reading.
 *               After running, this routines will leave the file pointer
 *               immedately after the header.
 */
void GloveGesture::loadFileHeader(std::ifstream& infile)
{
    // skip comments
    while(infile.peek() == '#')
        infile.ignore(4096, '\n');    // Ignore the entire line.

    // Get num gestures
    int num_gestures;
    infile >> num_gestures;          // Get the number of gestures

    infile.ignore(4096, '\n');       // Ignore the rest of the line

    // Get gesture names
    int i;
    char gest_name[512];

    mGestureNames = std::vector<std::string>(num_gestures);
    for(i=0; i<num_gestures; i++)
    {
        infile.getline(gest_name,512);
        mGestureNames[i] = std::string(gest_name);
    }

    mGestureExamples = std::vector<GloveData>(num_gestures);

    // Get gesture data
    for(i=0; i<num_gestures; i++)
        mGestureExamples[i].inputAngles(infile);
}
HillPromReaction::HillPromReaction( std::ifstream& file ) {

	for (int i = 0 ; i < NUM_LINE ; i++) {
		switch (i) {
			case I_PROMOTER_LINE:
				file.ignore(256,':');
				file >> _i_promoter;
				break;
			case I_PROMOTED_LINE:
				file.ignore(256,':');
				file >> _i_promoted;
				break;
			case KINETIC_LINE:
				file.ignore(256,':');
				file >> _kinetic;
				break;
			case K_LINE:
				file.ignore(256,':');
				file >> _K;
				break;
			case COOPERATIVITY_LINE:
				file.ignore(256,':');
				file >> _cooperativity;
				break;
			default:
				break;
		}
	}
	
}
/******************************************************************************
	name:        Reservasjon()
	description: Constructor for Reservasjon; creates a reservation from 
	             information read from file.
				 Parameters sent from Rom is a reference tothe file reading object, 
				 date (arrival date), and the room number
	parameters:  std::ifstream &infile, int dato, int roomNr
******************************************************************************/
Reservasjon::Reservasjon(std::ifstream &inFile, int dato, int roomNr) : Num_element(dato)
{
	occupant = new std::string[MAX_PAA_ROM];           // Create a string array
	bills = new List(FIFO);                               // Create a FIFO list
	roomID = roomNr;                                 // Assign roomNr to roomID
	arrival = dato;                                   // Assign dato to arrival
	inFile >> departure >> numberOfDays >> inUse;        // Read data from file
	costPrDay = new float[numberOfDays];                // Create a float array
	inFile.ignore();                            // Ignore and discard character

	                         // Loop through number of days and read from file:
	for (int i = 0; i < numberOfDays; i++)
	{
		inFile >> costPrDay[i]; inFile.ignore();
	}
	inFile >> extraBed >> bedInUse >> numberOfOccupants; // Read data from file
	inFile.ignore();                            // Ignore and discard character

	                                       // Loop through number of occupants:
	for (int i = 1; i <= numberOfOccupants; i++)
	{
		getline(inFile, occupant[i]);
	}
	inFile >> numberOfBills;                  // Read number of bills from file
	inFile.ignore();                            // Ignore and discard character

	                                           // Loop through number of bills:
	for (int i = 1; i <= numberOfBills; i++)
	{
		Regning* reg = new Regning(inFile);      // Create a new regning object
		bills->add(reg);                                        // Add new bill
	}
}
std::tuple<unsigned int, unsigned int, int> parse_ppm_header(std::ifstream &fs)
{
    // Check the PPM magic number is valid
    std::array<char, 2> magic_number{ { 0 } };
    fs >> magic_number[0] >> magic_number[1];
    ARM_COMPUTE_ERROR_ON_MSG(magic_number[0] != 'P' || magic_number[1] != '6', "Invalid file type");
    ARM_COMPUTE_UNUSED(magic_number);

    discard_comments_and_spaces(fs);

    unsigned int width = 0;
    fs >> width;

    discard_comments_and_spaces(fs);

    unsigned int height = 0;
    fs >> height;

    discard_comments_and_spaces(fs);

    int max_val = 0;
    fs >> max_val;

    discard_comments(fs);

    ARM_COMPUTE_ERROR_ON_MSG(isspace(fs.peek()) == 0, "Invalid PPM header");
    fs.ignore(1);

    return std::make_tuple(width, height, max_val);
}
Example #5
0
TypedImage LoadPpm(std::ifstream& bFile)
{
    // Parse header
    std::string ppm_type = "";
    int num_colors = 0;
    int w = 0;
    int h = 0;

    bFile >> ppm_type;
    PpmConsumeWhitespaceAndComments(bFile);
    bFile >> w;
    PpmConsumeWhitespaceAndComments(bFile);
    bFile >> h;
    PpmConsumeWhitespaceAndComments(bFile);
    bFile >> num_colors;
    bFile.ignore(1,'\n');

    if(!bFile.fail() && w > 0 && h > 0) {
        TypedImage img(w, h, PpmFormat(ppm_type, num_colors) );

        // Read in data
        for(size_t r=0; r<img.h; ++r) {
            bFile.read( (char*)img.ptr + r*img.pitch, img.pitch );
        }
        if(!bFile.fail()) {
            return img;
        }
    }

    throw std::runtime_error("Unable to load PPM file.");
}
Example #6
0
void PpmConsumeWhitespaceAndComments(std::ifstream& bFile)
{
    // TODO: Make a little more general / more efficient
    while( bFile.peek() == ' ' )  bFile.get();
    while( bFile.peek() == '\n' ) bFile.get();
    while( bFile.peek() == '#' )  bFile.ignore(4096, '\n');
}
	void ResourceManager::getI2NBlock(std::ifstream &file, 
										 Resource::Mapping &mapping, 
										 bool files, 
										 const std::string &dir, 
										 const std::string &ext)
	{
		uint id;
		const int bufferSize = 80;
		char buffer[bufferSize];
		while (!file.eof() && file.peek() != '#')
		{
			file >> id;
			if (!(file.peek() == '.'))
				return;
			
			file.ignore(2, ' ');
			
			file.getline(buffer, bufferSize);
			fixLineEnd(buffer);
			
			if (files)
			{
				std::string path = dir + '/' + std::string(buffer) + ext;
				Normalize(path);
				mapping[id] = path;
			}
			else
			{
				mapping[id] = std::string(buffer);
			}
		}
	}
Example #8
0
void readLabels(std::ifstream &file, char delim, const std::string &poslabel, const std::string &neglabel, std::deque<unsigned> &pos, std::deque<unsigned> &neg, bool posvall){
	string chunk;

	unsigned idx=1;
	while(file.good()){

		// read first column
		chunk.clear();
		getline(file,chunk,delim);
		if(chunk.empty())
			break;

		if(chunk.compare(poslabel)==0)
			pos.push_back(idx);
		else if(posvall)
			neg.push_back(idx);
		else if(chunk.compare(neglabel)==0)
			neg.push_back(idx);
//		else
//			exit_with_err(std::string("Encountered unknown label: ")+chunk+" ... missing -posvall flag?");
		// when encountering an unkown label, ignore it and parse rest of the data

		// ignore rest
		file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
		++idx;
	}
}
Example #9
0
inline static void seek_to_line(std::ifstream& file, unsigned line)
{
	file.seekg(std::ios::beg);
	for (int i = 0; i < line - 1; ++i)
	{
		file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
	}
}
Example #10
0
void mesh::read_vertices(std::ifstream &vfile)
{
    for (int i = 0 ; i < nv; ++i)
    {
        vfile >> v[i].no;
        vfile.ignore(100, ':');
        vfile >> v[i].r.x >> v[i].r.y >> v[i].marker;
    }
}
Example #11
0
void AnimatedObjModel::loadDataStructures(std::ifstream& _dataStream, const DataCounts& counts)
{
	std::vector<glm::vec3> tVertices;
	std::vector<glm::vec2> tTexCoords;
	std::vector<glm::vec3> tNormals;
	std::vector<FaceType> tFaces;

	char tInput1;
	
	int tVertexIndex = 0;
	int tTexcoordIndex = 0;
	int tNormalIndex = 0;
	int tFaceIndex = 0;
	int tBoneIndex = 0;

	mModel.resize(counts.faces * 3);

	//Initialize the four data structures.
	tVertices.resize(counts.positions);
	tTexCoords.resize(counts.texCoords);
	tNormals.resize(counts.normals);
	tFaces.resize(counts.faces);
	bones.resize(counts.bones);

	while(_dataStream)
	{
		_dataStream.get(tInput1);

		if (tInput1 == '#')
		{
#undef max
			_dataStream.ignore(std::numeric_limits<int>::max(), '\n');
			continue;
		}

		if(tInput1 == 'v')
		{
			_dataStream.get(tInput1);

			//Read in the vertices.
			if(tInput1 == ' ') 
			{ 
				_dataStream >> tVertices[tVertexIndex].x;
				_dataStream >> tVertices[tVertexIndex].y;
				_dataStream >> tVertices[tVertexIndex].z;
				tVertexIndex++; 
			}

			//Read in the texture uv coordinates.
			if(tInput1 == 't') 
			{ 
				_dataStream >> tTexCoords[tTexcoordIndex].x;
				_dataStream >> tTexCoords[tTexcoordIndex].y;
				tTexcoordIndex++; 
			}
template <class T> void GetNextToken(std::ifstream& Config, T& Data)
{
    if (!Config)
        throw std::runtime_error("Config stream is not open !");

    std::string buffer;
    while (Config.peek() == '#')
    Config.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    
    std::getline(Config, buffer, ' ');
    std::cout << "[DEBUG] : " << buffer << std::endl;
    Data = ToType<T>(buffer);
}
Example #13
0
void mesh::read_sides(std::ifstream &sfile)
{
    for (int i = 0 ; i < ns ; ++i)
    {
        int idx1, idx2;
        sfile >> s[i].no;
        sfile.ignore(100, ':');
        sfile >> idx1 >> idx2;
        s[i].v1 = idx1 == -1 ? NULL : &v[idx1]; s[i].v2 = idx2 == -1 ? NULL : &v[idx2];
        sfile >> idx1 >> idx2;
        s[i].e1 = idx1 == -1 ? NULL : &e[idx1]; s[i].e2 = idx2 == -1 ? NULL : &e[idx2];
        sfile >> s[i].marker;
    }
}
Example #14
0
void sbfMaterialProperties::read(std::ifstream &in)
{
    std::getline(in, name_);
    size_t numTables;
    in >> numTables;
    in.ignore(10, '\n');
    for(size_t ct = 0; ct < numTables; ct++) {
        std::string name;
        std::getline(in, name);
        auto table = new sbfPropertyTable(name);
        table->read(in);
        tables_[name] = table;
    }
}
Example #15
0
void mesh::read_elems(std::ifstream &efile)
{
    for (int i = 0 ; i < ne ; ++i)
    {
        int idx1, idx2, idx3;
        efile >> e[i].no;
        efile.ignore(100, ':');
        efile >> idx1 >> idx2 >> idx3;
        e[i].v1 = idx1 == -1 ? NULL : &v[idx1]; e[i].v2 = idx2 == -1 ? NULL : &v[idx2]; e[i].v3 = idx3 == -1 ? NULL : &v[idx3];
        efile >> idx1 >> idx2 >> idx3;
        e[i].e1 = idx1 == -1 ? NULL : &e[idx1]; e[i].e2 = idx2 == -1 ? NULL : &e[idx2]; e[i].e3 = idx3 == -1 ? NULL : &e[idx3];
        efile >> idx1 >> idx2 >> idx3;
        e[i].s1 = idx1 == -1 ? NULL : &s[idx1]; e[i].s2 = idx2 == -1 ? NULL : &s[idx2]; e[i].s3 = idx3 == -1 ? NULL : &s[idx3];
        efile >> e[i].r.x >> e[i].r.y >> e[i].marker;
    }
}
Example #16
0
   void pnm_read(std::ifstream &file, char *buf)
   {
      char doc[PNM_BUFFER_SIZE];
      char c;

      file >> c;
      while (c == '#') {
         file.getline(doc, PNM_BUFFER_SIZE);
         file >> c;
      }
      file.putback(c);

      file.width(PNM_BUFFER_SIZE);
      file >> buf;
      file.ignore();
   }
Example #17
0
bool Mail::load(std::ifstream &file)
{
	std::string recipient;

	file >> id;

	if (id != "XXX" && !file.fail())
	{
		file >> counter;

		if (!file.fail())
		{
			file >> date;

			if (!file.fail())
			{
				file >> from;

				if (!file.fail())
				{
					for (int i = 0; i < counter - 1; i++)
					{
						file >> recipient;

						recipients.push_back(recipient);
					}
					if (!file.fail())
					{
						file.ignore();
						std::getline(file, subject);

						if (!file.fail())
						{
							std::getline(file, body, '#');

							if (!file.fail()) return true;
							else return false;
						}
						else return false;
					}
					else return false;
				}
				else return false;
Example #18
0
TypedImage LoadPpm(std::ifstream& bFile)
{
    // Parse header
    std::string ppm_type = "";
    int num_colors = 0;
    int w = 0;
    int h = 0;

    bFile >> ppm_type;
    PpmConsumeWhitespaceAndComments(bFile);
    bFile >> w;
    PpmConsumeWhitespaceAndComments(bFile);
    bFile >> h;
    PpmConsumeWhitespaceAndComments(bFile);
    bFile >> num_colors;
    bFile.ignore(1,'\n');
    
    TypedImage img;
    bool success = !bFile.fail() && w > 0 && h > 0;

    if(success) {
        img.Alloc(w, h, PpmFormat(ppm_type, num_colors) );

        // Read in data
        for(size_t r=0; r<img.h; ++r) {
            bFile.read( (char*)img.ptr + r*img.pitch, img.pitch );
        }
        success = !bFile.fail();
    }

    if(!success) {
        img.Dealloc();
    }

    return img;
}
Example #19
0
void Param::lire_int(std::ifstream &fichier, int & x)
{
    fichier.ignore( std::numeric_limits<std::streamsize>::max(), ':');
    fichier >> x;
}
Example #20
0
/**
 * \fn	void Labyrinthe::chargeLabyrinthe(Couleur couleur, std::ifstream &entree)
 * \param[in]	couleur, la couleur du jouer auquel le labyrinthe chargé s'applique
 * \param[in]	entree, fichier contenant la définition du labyrinthe
 */
void Labyrinthe::chargeLabyrinthe(Couleur couleur, std::ifstream &entree)
{

	int nbCols, nbRangs;

	entree >> nbCols >> nbRangs;
	entree.ignore(); //pour consommer le \n (le caractère fin de ligne)

	const int MAX_LIGNE = 1000;
	char ligne[MAX_LIGNE];

	entree.getline(ligne, MAX_LIGNE);
	entree.getline(ligne, MAX_LIGNE);

	std::ostringstream s; //Une chaîne pour écrire dedans, cette chaîne servira pour nommer les pièces du labyrinthe

	for (int i = 0; i < nbCols; i++)
	{
		for (int j = 0; j < nbRangs; j++)
		{
			s << i << "," << j;
			Piece p(s.str());
			s.str("");
			ajoutePieceLabyrinthe(p);
		}
	}

	for (int i = 0; i < nbCols; i++)
	{
		if (ligne[i * 4 + 1] == 'D' || ligne[i * 4 + 1] == 'd')
		{
			std::string nom;
			s << i << ",0";
			nom = s.str();
			s.str("");
			placeDepart(nom);
		}
		if (ligne[i * 4 + 1] == 'F' || ligne[i * 4 + 1] == 'f' || ligne[i * 4 + 1] == 'A' || ligne[i * 4 + 1] == 'a')
		{
			std::string nom;
			s << i << ",0";
			nom = s.str();
			s.str("");
			placeArrivee(nom);
		}
	}

	for (int j = 0; j < nbRangs; j++)
	{
		entree.getline(ligne, MAX_LIGNE);

		for (int i = (j == nbRangs - 1 && (j & 1)) ? 1 : 0; i < nbCols; i++)
		{
			if (j & 1)
			{
				if (j < nbRangs - 2 && ligne[i * 4 + 3] == ' ')
				{
					ajoutePassage(couleur, i, j, i, j + 2);
				}
				if (j < nbRangs - 1 && ligne[i * 4 + 2] == ' ')
				{
					ajoutePassage(couleur, i, j, i, j + 1);
				}
				if (j < nbRangs - 1 && ligne[i * 4 + 0] == ' ')
				{
					ajoutePassage(couleur, i - 1, j, i, j + 1);
				}
				if (j < nbRangs - 1 && (ligne[i * 4 + 1] == 'D' || ligne[i * 4
				                                                         + 1] == 'd'))
				{
					std::string nom;
					s << i << "," << j + 1;
					nom = s.str();
					s.str("");
					placeDepart(nom);
				}
				if (j < nbRangs - 1 && (ligne[i * 4 + 1] == 'F' || ligne[i * 4
				                                                         + 1] == 'f' || ligne[i * 4 + 1] == 'A' || ligne[i * 4
				                                                                                                         + 1] == 'a'))
				{
					std::string nom;
					s << i << "," << j + 1;
					nom = s.str();
					s.str("");
					placeArrivee(nom);
				}
			}
			else
			{
				if (j < nbRangs - 1 && ligne[i * 4 + 0] == ' ')
				{
					ajoutePassage(couleur, i - 1, j + 1, i, j);
				}
				if (j < nbRangs - 2 && ligne[i * 4 + 1] == ' ')
				{
					ajoutePassage(couleur, i, j, i, j + 2);
				}
				if (j < nbRangs - 1 && ligne[i * 4 + 2] == ' ')
				{
					ajoutePassage(couleur, i, j, i, j + 1);
				}
				if (j < nbRangs - 1 && (ligne[i * 4 + 3] == 'D' || ligne[i * 4
				                                                         + 3] == 'd'))
				{
					std::string nom;
					s << i << "," << j + 1;
					nom = s.str();
					s.str("");
					placeDepart(nom);
				}
				if (j < nbRangs - 1 && (ligne[i * 4 + 3] == 'F' || ligne[i * 4
				                                                         + 3] == 'f' || ligne[i * 4 + 3] == 'A' || ligne[i * 4
				                                                                                                         + 3] == 'a'))
				{
					std::string nom;
					s << i << "," << j + 1;
					nom = s.str();
					s.str("");
					placeArrivee(nom);
				}
			}
		}
	}
}
Example #21
0
void Param::lire_couleur(std::ifstream &fichier, int &x, int &y, int &z)
{
    fichier.ignore( std::numeric_limits<std::streamsize>::max(), ':');
    fichier >> x >> y >> z;
}
Example #22
0
HelperMesh JObjectLoader::getMesh(std::ifstream & stream){
    std::string garbage, info;
    if(stream.eof()){
        exit(0);
    }
    
    
    
    std::vector<glm::vec3> positions;
    std::vector<glm::vec3> normals;
    std::vector<glm::vec3> tangents;
    std::vector<glm::vec2> textureCoords;
    std::vector<GLuint> indices;
    
    HelperMesh mesh;
    stream >> mesh.meshName;
    stream.ignore(150,'\n');

    
    
    bool nextMesh =false;
    do{
        stream>> info;
        if(stream.eof())
            break;
        switch(getTypeID(info)){
            case VERTEX:{
                glm::vec3 v;
                stream >> v.x >> v.y >> v.z;
                positions.push_back(v);
                stream.ignore(150,'\n');
                break;
            }case NORMAL:{
                glm::vec3 v;
                stream >> v.x >> v.y >> v.z;
                normals.push_back(v);
                stream.ignore(150,'\n');
                break;
            }case TEX_COORD:{
                glm::vec2 v;
                stream >> v.x >> v.y;
                textureCoords.push_back(v);
                stream.ignore(150,'\n');
                break;
            }case INDEX: {
                std::string s1,s2,s3;
                stream >> s1 >> s2 >> s3;
                addToIndices(s1,s2,s3,indices);
                stream.ignore(150,'\n');
                break;
            }case TANGENT:{
                glm::vec3 v;
                stream >> v.x >> v.y >> v.z;
                tangents.push_back(v);
                stream.ignore(150,'\n');
                break;
            }case MATERIAL:{
                stream >> info;
                mesh.materialName = info;
                stream.ignore(150,'\n');
                stream.ignore(150,'\n');
                break;
            }case OBJECT:{
                nextMesh = true;
                break;
            }case -1:{
                // EOF
                nextMesh =true;
                break;
            }
        }
    }while(!stream.eof() && !nextMesh);
    
    std::vector<glm::vec3> newPos, newNormals, newTangents;
    std::vector<glm::vec2> newTexCoords;
    newPos.reserve(indices.size());
    newNormals.reserve(indices.size());
    newTangents.reserve(indices.size());
 //   newTexCoords.reserve(indices.size()/3);
    
    for(int i =0; i < indices.size(); i+=9){
        newPos.push_back(positions[indices[i]]);
        newPos.push_back(positions[indices[i+3]]);
        newPos.push_back(positions[indices[i+6]]);
   
        
        newTexCoords.push_back(textureCoords[indices[i+1]]);
        newTexCoords.push_back(textureCoords[indices[i+4]]);
        newTexCoords.push_back(textureCoords[indices[i+7]]);
        
        newNormals.push_back(normals[indices[i+2]]);
        newNormals.push_back(normals[indices[i+5]]);
        newNormals.push_back(normals[indices[i+8]]);
    }
    std::vector<GLuint> temp;
    for(int i = 0; i < indices.size()/3; i ++){
        temp.push_back(i);
    }
    mesh.indices = std::move(temp);
    mesh.positions = newPos;
    mesh.textureCoords = newTexCoords;
    mesh.normals = newNormals;
    // ERROR NOT EVEN SETTING VERTEs
    
    
    return mesh;
    
}
Example #23
0
    static void
    read(CrsMatrixType &A, std::ifstream &file) {
      // static_assert( Kokkos::Impl::is_same<
      //                typename CrsMatrixType::space_type,
      //                Kokkos::HostSpace
      //                >::value,
      //                "Space type of the input should be HostSpace" );

      typedef typename CrsMatrixType::value_type   value_type;
      typedef typename CrsMatrixType::ordinal_type ordinal_type;
      typedef typename CrsMatrixType::size_type    size_type;

      // coordinate format
      typedef Coo<ordinal_type,value_type> ijv_type;

      //typedef typename CrsMatrixType::space_type space_type;
      //typedef Kokkos::RangePolicy<space_type,Kokkos::Schedule<Kokkos::Static> > range_policy_type;
      ordinal_type m, n;
      size_type nnz;

      std::vector<ijv_type> mm;
      const ordinal_type mm_base = 1;
      {
        std::string header;
        if (file.is_open()) {
          std::getline(file, header);
          while (file.good()) {
            char c = file.peek();
            if (c == '%' || c == '\n') {
              file.ignore(256, '\n');
              continue;
            }
            break;
          }
        } else {
          TACHO_TEST_FOR_ABORT(true, MSG_INVALID_INPUT(file));
        }

        // check the header
        bool symmetry = (header.find("symmetric") != std::string::npos);

        // read matrix specification
        file >> m >> n >> nnz;

        mm.reserve(nnz*(symmetry ? 2 : 1));
        for (size_type i=0;i<nnz;++i) {
          ordinal_type row, col;
          value_type val;
          file >> row >> col >> val;

          row -= mm_base;
          col -= mm_base;

          mm.push_back(ijv_type(row, col, val));
          if (symmetry && row != col)
            mm.push_back(ijv_type(col, row, val));
        }

        // sort by row major order
        std::sort(mm.begin(), mm.end(), std::less<ijv_type>());
      }

      // change mm to crs
      std::vector<size_type> ap;
      std::vector<ordinal_type> aj;
      std::vector<value_type> ax;

      ap.reserve(m+1);
      aj.reserve(nnz);
      ax.reserve(nnz);

      {
        ordinal_type ii = 0;
        size_type jj = 0;
        ijv_type prev = mm[0];

        ap.push_back(0);
        aj.push_back(prev.Col());
        ax.push_back(prev.Val());

        for (auto //typename std::vector<ijv_type>::const_iterator 
               it=(mm.begin()+1);it<mm.end();++it) {
          ijv_type aij = (*it);
          
          // row index
          if (aij.Row() != prev.Row()) 
            ap.push_back(aj.size());
          
          if (aij == prev) {
            aj.back()  = aij.Col();
            ax.back() += aij.Val();
          } else {
            aj.push_back(aij.Col());
            ax.push_back(aij.Val());
          }

          prev = aij;
        }
        
        // add the last index to terminate the storage
        ap.push_back(aj.size());
        nnz = aj.size();
      }

      // create crs matrix view
      A.create(m, n, nnz);
      for (ordinal_type i=0;i<m;++i) {
        A.RowPtrBegin(i) = ap.at(i);
        A.RowPtrEnd(i) = ap.at(i+1);
      }
      for (ordinal_type k=0;k<nnz;++k) {
        A.Col(k) = aj.at(k);
        A.Value(k) = ax.at(k);
      }
    }
Example #24
0
void Param::lire_string(std::ifstream &fichier, std::string &destination)
{
    fichier.ignore( std::numeric_limits<std::streamsize>::max(), ':');
    std::getline(fichier, destination);
    destination.erase(0,1);
}
void MD5Helper::ignoreLine(std::ifstream& file, int length)
{
	file.ignore(length, '\n');
}
Example #26
0
void Param::lire_position(std::ifstream &fichier, int & x, int & y)
{
    fichier.ignore( std::numeric_limits<std::streamsize>::max(), ':');
    fichier >> x >> y;
}
Example #27
0
inline void skipnl(std::ifstream& f) {
    f.ignore(numeric_limits<streamsize>::max(),'‘\n’');
}
Example #28
0
void TextureAtlasLoader::ProcessComment (std::ifstream& file)
{
	file.ignore (std::numeric_limits<std::streamsize>::max(), '\n');	
}
Example #29
0
void test_a_conversion(char cmd, tlm_generic_payload &txn, std::ifstream & fin) {

  if(cmd == 'R') txn.set_read();
  else txn.set_write();

  fin.ignore(10000,'=');
  uint64 a;
  fin >> a;
  txn.set_address(a);

  fin.ignore(10000,'=');
  int l;
  fin >> l;
  txn.set_data_length(l);

  int bus_width;
  fin.ignore(10000,'=');  fin >> bus_width;

  int data_width;
  fin.ignore(10000,'=');  fin >> data_width;

  int initiator_offset;
  fin.ignore(10000,'=');  fin >> initiator_offset;

  unsigned char *original_byte_enable = 0;
  unsigned char *byte_enable_legible =
    new unsigned char[txn.get_data_length() + 1];
  memset(byte_enable_legible, 0, txn.get_data_length() + 1);
  fin.ignore(10000,'=');
  for(unsigned b=0; b<txn.get_data_length(); b++) {
    char tmp; fin >> tmp;
    if((tmp=='0')||(tmp=='1')||(tmp=='x')) byte_enable_legible[b]=tmp;
    else break;
  }
  if((byte_enable_legible[0] == '1') || (byte_enable_legible[0] == '0')) {
    txn.set_byte_enable_ptr(new unsigned char[txn.get_data_length()]);
    txn.set_byte_enable_length(txn.get_data_length());
    original_byte_enable = txn.get_byte_enable_ptr();
    for(unsigned int i=0; i<txn.get_data_length(); i++) {
      if(byte_enable_legible[i] == '0') {
        txn.get_byte_enable_ptr()[i] = TLM_BYTE_DISABLED;
      } else if(byte_enable_legible[i] == '1') {
        txn.get_byte_enable_ptr()[i] = TLM_BYTE_ENABLED;
      } else {
        // not enough byte enables
        txn.set_byte_enable_length(i);
        break;
      }
    }
  } else {
    txn.set_byte_enable_ptr(0);
    txn.set_byte_enable_length(0);
  }

  int stream_width;
  fin.ignore(10000,'=');  fin >> stream_width;
  txn.set_streaming_width(stream_width);

  cout << "enter initiator memory state = ("<< BUFFER_SIZE << " characters)\n";
  unsigned char initiator_mem[BUFFER_SIZE+1];
  memset(initiator_mem, 0, BUFFER_SIZE+1);
  fin.ignore(10000,'=');  fin >> initiator_mem;

  txn.set_data_ptr(initiator_mem + initiator_offset);

  cout << "enter target memory state = ("<< BUFFER_SIZE << " characters)\n";
  unsigned char target_mem[BUFFER_SIZE+1];
  memset(target_mem, 0, BUFFER_SIZE+1);
  fin.ignore(10000,'=');  fin >> target_mem;

  cout << "enter converter choice = (0 => generic, 1 => word, 2 => aligned, 3 => single)\n";
  int converter;
  fin.ignore(10000,'=');  fin >> converter;

  cout << "Initiator Intent\n";
  cout << "  Cmd = " << cmd << endl;
  cout << "  Addr = " << txn.get_address() << endl;
  cout << "  Len = " << txn.get_data_length() << endl;
  cout << "  Bus Width = " << bus_width << endl;
  cout << "  Data Word = " << data_width << endl;
#ifdef VERBOSE
  cout << "  Initiator offset and txn data pointer = " << initiator_offset << ", " << int(txn.get_data_ptr()) << endl;
  cout << "  Byte enables and byte enable pointer = " << byte_enable_legible << ", " << int(txn.get_byte_enable_ptr()) << endl;
#else
  cout << "  Initiator offset = " << initiator_offset << endl;
  cout << "  Byte enables = " << byte_enable_legible << endl;
#endif
  cout << "  Byte enable length = " << txn.get_byte_enable_length() << endl;
  cout << "  Streaming width = " << txn.get_streaming_width() << endl;
  cout << "  Initiator memory = " << initiator_mem << endl;
  cout << "  Target memory = " << target_mem << endl;
  cout << "  Converter = " << converter << endl << endl;

  // initiator //
  switch(converter) {
    case 0:  convert(tlm_to_hostendian_generic); break;
    case 1:  convert(tlm_to_hostendian_word); break;
    case 2:  convert(tlm_to_hostendian_aligned); break;
    case 3:  convert(tlm_to_hostendian_single); break;
    case 4:  convert(local_single_tohe); break;
    default:  cout << "no such converter as " << converter << endl;
    exit(1);
  }

  cout << "Converted Transaction\n";
  cout << "  Addr = " << txn.get_address() << endl;
  cout << "  Len = " << txn.get_data_length() << endl;
#ifdef VERBOSE
  cout << "  Txn data pointer = " << int(txn.get_data_ptr()) << endl;
  if(txn.get_byte_enable_ptr() != 0) {
    cout << "  Byte enables and byte enable pointer = ";
    for(unsigned int i=0; i<txn.get_data_length(); i++)
      cout << (txn.get_byte_enable_ptr()[i] ? '1' : '0');
    cout << ", " << int(txn.get_byte_enable_ptr()) << endl;
  }
#else
  cout << "  Txn data pointer = " <<
    (txn.get_data_ptr() == initiator_mem+initiator_offset ? "unchanged" : "changed") << endl;
  if(txn.get_byte_enable_ptr() != 0) {
    cout << "  Byte enables and byte enable pointer = ";
    for(unsigned int i=0; i<txn.get_data_length(); i++)
      cout << (txn.get_byte_enable_ptr()[i] ? '1' : '0');
    cout << ", " <<
     (txn.get_byte_enable_ptr() == original_byte_enable ? "unchanged" : "changed") << endl;
  }
#endif
  cout << "  Byte enable length = " << txn.get_byte_enable_length() << endl;
  cout << "  Streaming width = " << txn.get_streaming_width() << endl;
  cout << endl;

  // target //
  int sw = txn.get_streaming_width();
  if((txn.get_data_length()/sw)*sw != txn.get_data_length()) {
    cout << "ERROR: Data length not a multiple of streaming width\n";
    exit(1);
  }
  for(unsigned int ss = 0; ss < txn.get_data_length(); ss += sw) {
    if(txn.get_byte_enable_ptr() == 0) {
      // simple transaction can be processed by mem-copy
      if(txn.is_read())
        memcpy(ss+txn.get_data_ptr(), target_mem+txn.get_address(), sw);
      else
        memcpy(target_mem+txn.get_address(), ss+txn.get_data_ptr(), sw);
    } else {
      // complex transaction, byte enables, maybe shorter than data
      int bel = txn.get_byte_enable_length();
      if(txn.is_read()) {
        for(int j=0; j<sw; j++) {
          if(txn.get_byte_enable_ptr()[(ss+j) % bel])
            (txn.get_data_ptr())[ss+j] = target_mem[j+txn.get_address()];
        }
      } else {
        for(int j=0; j<sw; j++) {
          if(txn.get_byte_enable_ptr()[(ss+j) % bel])
            target_mem[j+txn.get_address()] = (txn.get_data_ptr())[ss+j];
        }
      }
    }
  }

  // initiator again //
  if((rand() & 0x100) && (converter < 4)) {
#ifdef VERBOSE
    cout << "using single entry point for response\n";
#endif
    tlm_from_hostendian(&txn);
  } else {
#ifdef VERBOSE
    cout << "using specific entry point for response\n";
#endif
    switch(converter) {
      case 0:  convert(tlm_from_hostendian_generic); break;
      case 1:  convert(tlm_from_hostendian_word); break;
      case 2:  convert(tlm_from_hostendian_aligned); break;
      case 3:  convert(tlm_from_hostendian_single); break;
      case 4:  convert(local_single_fromhe); break;
      default:  cout << "no such converter as " << converter << endl;
      exit(1);
    }
  }

  // print the results //
  cout << "Memory States after Transaction\n";
  cout << "  initiator = " << initiator_mem << endl;
  cout << "  target = " << target_mem << endl << endl;

  // clean up
  delete [] byte_enable_legible;
  if(original_byte_enable != 0) delete [] original_byte_enable;
}
Example #30
0
		virtual size_t skip(size_t num) {
		    std::unique_lock<std::mutex> lock(m_mutex); // Released when out of scope
			ensureStream();
			m_stream.ignore(num);
			return m_stream.gcount();
		}