Esempio n. 1
1
void get_next_line(std::ifstream& file, std::string& line)
{
	bool comment=false;
	do {
		getline(file,line);
		if (file.good() && line.size()>0)
			if (line[0]=='#')
				comment=true;
			else
				comment=false;
	} while (file.good() && comment);
}
Esempio n. 2
0
bool ContainerRecord::loadFromStream(std::ifstream& inStream)
{
  if (!inStream.good())
  {
    DuskLog() << "ContainerRecord::loadFromStream: ERROR: stream contains errors!\n";
    return false;
  }
  uint32_t len = 0;
  inStream.read((char*) &len, sizeof(uint32_t));
  if (len != cHeaderCont)
  {
    DuskLog() << "ContainerRecord::loadFromStream: ERROR: stream contains unexpected header!\n";
    return false;
  }
  char ID_Buffer[256];
  memset(ID_Buffer, 0, 256);
  //read ID
  len = 0;
  inStream.read((char*) &len, sizeof(uint32_t));
  if (len>255)
  {
    DuskLog() << "ContainerRecord::loadFromStream: ERROR: ID is "
              << "longer than 255 characters!\n";
    return false;
  }
  inStream.read(ID_Buffer, len);
  if (!inStream.good())
  {
    DuskLog() << "ContainerRecord::loadFromStream: ERROR while "
              << "reading ID from stream!\n";
    return false;
  }
  //read Mesh
  char Mesh_Buffer[256];
  memset(Mesh_Buffer, 0, 256);
  len = 0;
  inStream.read((char*) &len, sizeof(uint32_t));
  if (len>255)
  {
    DuskLog() << "ContainerRecord::loadFromStream: ERROR: mesh path "
              << "is longer than 255 characters!\n";
    return false;
  }
  inStream.read(Mesh_Buffer, len);
  if (!inStream.good())
  {
    DuskLog() << "ContainerRecord::loadFromStream: ERROR while "
              << "reading mesh path from stream!\n";
    return false;
  }
  Inventory temp;
  if (!temp.loadFromStream(inStream))
  {
    DuskLog() << "ContainerRecord::loadFromStream: ERROR while "
              << "reading inventory contens from stream!\n";
    return false;
  }
  //all right so far
  return inStream.good();
}
Esempio n. 3
0
void getNextWord(std::ifstream& inFile, std::string& token, std::string tokenizer, int64_t endOffSet)
{
   token.clear();
   char byte[1];

  while(inFile.good())
  {
     if(inFile.tellg() >= endOffSet)
       return;

     byte[0] =inFile.peek();
     if(byte[0]=='\n' || byte[0] == tokenizer.c_str()[0]){
       inFile.get();
     }else{
       break;
     }
  }


  while(inFile.good()){
   byte[0] = inFile.get();   
   if(byte[0]=='\n' || byte[0] == tokenizer.c_str()[0]){
     return;
   }
    token.append(byte,1);
   }
}
Esempio n. 4
0
srzMetaDataStruct loadGlobalSerializationMetadata(std::ifstream& f) {

	srzMetaDataStruct md;

	// isk version
	f.read((char *) &(md.iskVersion), sizeof(int));
	if (!f.good()) {
		cerr << "ERROR bad file while reading isk version" << endl;
		return md;
	}

	// binding language
	f.read((char *) &(md.bindingLang), sizeof(int));
	if (!f.good()) {
		cerr << "ERROR bad file while reading lang" << endl;
		return md;
	}

    // trial or full
    if (md.iskVersion < SRZ_V0_7_0) {
    	f.read((char *) &(md.isTrial), sizeof(int));
    }

	// platform
	f.read((char *) &(md.compilePlat), sizeof(int));
	if (!f.good()) {
		cerr << "ERROR bad file while reading platf" << endl;
		return md;
	}

	// ok, I have some valid metadata
	md.isValidMetadata = 1;

	return md;
}
Esempio n. 5
0
std::string CppLogger::getVar(std::ifstream& file)
{
	std::string result = "";

	while (file.good())
	{
		char c = file.get();
		if (c == '=' || c == '\n')
		{
			break;
		}
		else if (c == '#')
		{
			while (file.good() && file.get() != '\n')
			{
			}
			break;
		}
		else if (c == ' ')
		{
			continue;
		}

		result += c;
	}

	return result;
}
Esempio n. 6
0
bool BSAFolderRecord::loadFromStream(std::ifstream& in_File)
{
  if (!in_File.good())
  {
    std::cout << "BSAFolderRecord::loadFromStream: Error: bad stream given!\n";
    return false;
  }
  //read folder record's stuff
  in_File.read((char*) &nameHash, sizeof(BSAHash));
  if (!in_File.good())
  {
    std::cout << "BSAFolderRecord::loadFromStream: Error: could not read hash!\n";
    return false;
  }
  //rest of it
  in_File.read((char*) &count, 4);
  in_File.read((char*) &offset, 4);
  if (!in_File.good())
  {
    std::cout << "BSAFolderRecord::loadFromStream: Error while reading data!\n";
    return false;
  }
  //all's well
  return true;
}
Esempio n. 7
0
		bool XTextureFileName::ParseFromFStream(std::ifstream& in)
		{
			std::streampos pos;
			char separator;

			if (!in.good())
			{
				return false;
			}

			in.clear();
			pos = in.tellg();

			if (!FileName.ParseFromFStream(in))
			{
				in.clear();
				in.seekg(pos);
				return false;
			}

			in >> separator;

			if (!in.good() || separator != ';')
			{
				in.clear();
				in.seekg(pos);
				return false;
			}

			return true;
		}
Esempio n. 8
0
void Profile::read(std::ifstream& fin) {
	std::string line;
	while (getline(fin, line)) {
		if (line.substr(0, 8) == "#Profile") break;
	}
	assert(fin.good());

	int tmp_prolen, tmp_ncodes;
	fin>> tmp_prolen>> tmp_ncodes;
	assert(fin.good() && (tmp_ncodes == NCODES));

	if (tmp_prolen != proLen) {
		delete[] p;
		proLen = tmp_prolen;
		size = proLen * NCODES * NCODES;
		p = new double[proLen][NCODES][NCODES];
		memset(p, 0, sizeof(double) * size);
	}
	
	for (int i = 0; i < proLen; ++i)
		for (int j = 0; j < NCODES; ++j)
			for (int k = 0; k < NCODES; ++k)
	assert(fin>> p[i][j][k]);

	getline(fin, line);
}
Esempio n. 9
0
CircularNanoparticle::CircularNanoparticle(std::ifstream & stream) : Nanoparticle(stream, Nanoparticle::CIRCLE)
{
	/* FORMAT
	*  <parent_data><mRadius><mBoundary>
	*
	*/

	//we not set badState here as parent constructor may of set it to bad

	stream.read( (char*) &mRadius,sizeof(int));

	if(!stream.good())
	{
		cerr << "Error: Couldn't create CircularNanoparticle. Failed to read mRadius" << endl;
		badState=true;
	}

	stream.read( (char*) &mBoundary,sizeof(enum boundary));

	if(!stream.good())
	{
		cerr << "Error: Couldn't create CircularNanoparticle. Failed to read mBoundary" << endl;
		badState=true;
	}

}
Esempio n. 10
0
ossim_uint32 ossimRpfToc::getNumberOfFrames(std::ifstream& dotRpfStr) const
{
   ossim_uint32 result = 0;

   if ( !dotRpfStr.good() )
   {
      // see if we can clear it.  Someone might have hit end of file(eof).
      dotRpfStr.clear();
   }

   dotRpfStr.seekg(0, ios_base::beg);

   // Eat the first line which is the bounding rect.
   std::string line;
   std::getline(dotRpfStr, line);
   
   while( dotRpfStr.good() )
   {
      std::getline(dotRpfStr, line);

      if ( dotRpfStr.good() )
      {
         ++result;
      }
   }

   dotRpfStr.clear();
   dotRpfStr.seekg(0, ios_base::beg);

   return result;
}
Esempio n. 11
0
		bool XAnimationKey::ParseFromFStream(std::ifstream& in)
		{
			std::streampos pos;
			char separator;

			if (!in.good())
			{
				return false;
			}

			in.clear();
			pos = in.tellg();

			if (!KeyType.ParseFromFStream(in))
			{
				in.clear();
				in.seekg(pos);
				return false;
			}

			in >> separator;
			if (!in.good() || separator != ';')
			{
				in.clear();
				in.seekg(pos);
				return false;
			}

			if (!NKeys.ParseFromFStream(in))
			{
				in.clear();
				in.seekg(pos);
				return false;
			}

			in >> separator;
			if (!in.good() || separator != ';')
			{
				in.clear();
				in.seekg(pos);
				return false;
			}

			if (!Keys.ParseFromFStream(in, NKeys))
			{
				in.clear();
				in.seekg(pos);
				return false;
			}

			in >> separator;
			if (!in.good() || separator != ';')
			{
				in.clear();
				in.seekg(pos);
				return false;
			}

			return true;
		}
Esempio n. 12
0
bool LccrFeaturizer::ReadOneSentence(std::ifstream &src,
                                     std::vector<std::string> &sentence) {
  if (!src.good()) {
    LOG(INFO) << "stream in bad state";
    return false;
  }

  sentence.clear();
  std::string line;

  std::getline(src, line);
  boost::algorithm::trim(line);
  while (src.good() && (line.size() < 1)) {
    std::getline(src, line);
    boost::algorithm::trim(line);
  }

  if ((!src.good()) && (!src.eof())) {
    LOG(FATAL) << "error when read files";
    return false;
  }

  while (src.good() && line.size() > 0) {
    sentence.push_back(line);
    std::getline(src, line);
    boost::algorithm::trim(line);
  }

  return true;
}
//-------------------------INTERFACE------------------------
BOOL IFileManager::ImportFile_3DS(
	NFilePath pFilePath,
	std::vector<NVECTOR3>& outVertexBuffer, 
	std::vector<NVECTOR2>& outTexCoordList, 
	std::vector<UINT>& outIndexBuffer, 
	std::vector<N_MeshSubsetInfo>& outSubsetList, 
	std::vector<N_Material>& outMaterialList,
	std::unordered_map<std::string, NFilePath>& out_TexName2FilePathPairList)
{
	static_meshObjList.clear();
	static_materialList.clear();
	static_TexName2FilePathPairList.clear();

	fileIn.open(pFilePath, std::ios::binary);

	if (!fileIn.good())
	{
		DEBUG_MSG1("Noise File Manager : Import .3ds file failed!!");
		return FALSE;
	}

	fileIn.seekg(0, std::ios::end);
	static_currentChunkFileEndPos = 0;
	static_fileSize = fileIn.tellg();
	fileIn.seekg(0);

	//maybe linearly deal with chunks is also OK....
	//stack will be used when necessary because recursive solution
	//can sometimes be rewritten in non-recursive form using stack.
	while (!fileIn.eof() && fileIn.good())
	{
		ReadChunk();
	}
	fileIn.close();

	//Finish Parsing,check if Vertices/Indices had been loaded
	auto& vertexList = static_meshObjList.back().verticesList;
	if (vertexList.size() == 0 || vertexList.size() == 0)
	{
		DEBUG_MSG1("Noise File Manager :Data Damaged!!!No Vertices or Indices loaded!");
		return FALSE;
	}


	//std::move transform lval into rval to avoid copying happens
	N_Load3ds_MeshObject finalMeshObj;
	IntegratePartialMeshIntoOnePiece(finalMeshObj);
	outIndexBuffer = std::move(finalMeshObj.indicesList);
	outVertexBuffer = std::move(finalMeshObj.verticesList);
	outTexCoordList = std::move(finalMeshObj.texcoordList);
	outSubsetList = std::move(finalMeshObj.subsetList);
	outMaterialList = std::move(static_materialList);
	out_TexName2FilePathPairList = std::move(static_TexName2FilePathPairList);

	//used to generate unique name
	++static_MeshIndex;

	return TRUE;
}
Esempio n. 14
0
bool ObjectRecord::loadFromStream(std::ifstream& inStream)
{
  unsigned int len;
  uint32_t Header = 0;
  char ID_Buffer[256], Mesh_Buffer[256];

  //read header "ObjS" (Object, Static)
  inStream.read((char*) &Header, sizeof(uint32_t));
  if (Header!=cHeaderObjS)
  {
    DuskLog() << "ObjectRecord::loadFromStream: ERROR: Stream contains invalid "
              << "record header.\n";
    return false;
  }//if
  //read length of ID
  inStream.read((char*) &len, sizeof(unsigned int));
  if (len>255)
  {
    DuskLog() << "ObjectRecord::loadFromStream: ERROR: ID cannot be longer than "
              << "255 characters.\n";
    return false;
  }
  //read ID
  memset(ID_Buffer, 0, 256);
  inStream.read(ID_Buffer, len);
  ID_Buffer[len] = '\0'; //add terminating null character
  if (!inStream.good())
  {
    DuskLog() << "ObjectRecord::loadFromStream: ERROR while reading data.\n";
    return false;
  }
  //read length of mesh name
  inStream.read((char*) &len, sizeof(unsigned int));
  if (len>255)
  {
    DuskLog() << "ObjectRecord::loadFromStream: ERROR: Name of Mesh cannot be "
              << "longer than 255 characters.\n";
    return false;
  }
  //read mesh
  memset(Mesh_Buffer, 0, 256);
  inStream.read(Mesh_Buffer, len);
  Mesh_Buffer[len] = '\0'; //add terminating null character
  //read collision flag
  bool collision_flag = true;
  inStream.read((char*) &collision_flag, sizeof(bool));
  if (!inStream.good())
  {
    DuskLog() << "ObjectRecord::loadFromStream: ERROR while reading data.\n";
    return false;
  }
  //now set the data
  ID = std::string(ID_Buffer);
  Mesh = std::string(Mesh_Buffer);
  collide = collision_flag;
  return true;
}
Esempio n. 15
0
/**
 * @brief read correlator meta-data and map to file positions
 * @description Nissa text correlator files contain meta-data in the form
 *              of comment lines. One line gives information about the
 *              contracted propagators in the form
 *
 *                S0_th0_m0_r0_ll ^ \dag S0_th0_m0_r0_ll
 *
 *              where we are (currently) interested in the indices
 *              on the m and r tokens. Another comment line specifies
 *              the spin content of the correlator in the form
 *              "P5P5" or "V1A0", for example. This function
 *              reads through the whole file and extracts the two
 *              m and two r indices as well as the spin combination.
 *              It constructs a key based on this information and stores
 *              the file position of the character after the newline behind
 *              the spin combination tag. Thus it stores the position of the
 *              beginning of the correlator corresponding to the constructed key.
 *
 * @param ifs file to be parsed
 * @param filemap output, map of file positions for the various correlators in the file
 */
inline void map_file(std::ifstream &ifs, std::map<std::string, std::iostream::pos_type> & filemap){
  if( !ifs.good() ){
    stop("map_file: input file stream not in a good state!");
  }

  std::string linebuf;
  std::string::size_type comment_pos;

  // currently the key for a two-point function consists of four unsigned integers (two mass and two r indices)
  // and the name of the spin combination stored in the correlator
  // a generalisation of the reader will have to modify this as well as the key construction
  // for now we store the numeric key components in this array
  unsigned int key_components[4];

  while( ifs.good() ){
    std::getline(ifs, linebuf);
    // we search for commented lines
    comment_pos = linebuf.find("#");
    if( comment_pos != std::string::npos ){
      // in these commented lines, we extract either
      // the current set of mass / r parameter combinations
      // or the current spin combination
      // the line looks like so:
      // " # Contraction of S0_th0_m0_r0_ll ^ \dag and S0_th0_m0_r0_ll"
      std::string::size_type contr_pos = linebuf.find("Contraction");
      if( contr_pos != std::string::npos ){
        std::vector<char> lbcopy( linebuf.size() + 1 );
        lbcopy[ linebuf.size() ] = '\0';
        memcpy( lbcopy.data(), linebuf.c_str(), linebuf.size() );
        unsigned int key_components_counter = 0;
        char * token = strtok(lbcopy.data(), "_");
        while( key_components_counter != 4 | token != NULL ){
          if( token[0] == 'm' || token[0] == 'r'){
            key_components[key_components_counter] = atoi(token+1);
            key_components_counter++;
          }
          token = strtok(NULL, "_");
        }
        if(key_components_counter != 4 && token == NULL){
          char message[200];
          snprintf(message, 200, "map_file: unable to construct key components in parsing of '%s'", linebuf.c_str());
          stop(message);
        }
      } else {
        // the line looks like so:
        // " # P5S0"
        std::string::size_type last_space_pos = linebuf.find_last_of(" ");
        std::string spin_comb = linebuf.substr(last_space_pos+1);
        // now we can build the key
        std::string key = make_key_2pt(key_components[0], key_components[2], key_components[1], key_components[3], spin_comb);
        // and store the position after the current newline as the starting point
        // of the present correlator
        filemap[ key ] = ifs.tellg();
      }
    }
  }
}
Esempio n. 16
0
ossimFilename ossimRpfToc::getSourceTocFile(std::ifstream& dotRpfStr) const
{
   ossimFilename tocFile;
   
   if ( !dotRpfStr.good() )
   {
      dotRpfStr.clear();
   }

   dotRpfStr.seekg(0, ios_base::beg);

   // Eat the first line which is the bounding rect.
   std::string line;
   std::getline(dotRpfStr, line);

   // Get the second line which is first file. 
   std::getline(dotRpfStr, line);

   // Get the file name and make the sub directory if needed.
   ossimFilename file;
   if ( getFile(line, file) )
   {
      ossimFilename subDir = file.path();
      tocFile = subDir.dirCat("a.toc");
      if ( !tocFile.exists() )
      {
         tocFile = subDir.dirCat("A.TOC");
         if ( !tocFile.exists() )
         {
            subDir = subDir.path();
            tocFile = subDir.dirCat("a.toc");
            if ( !tocFile.exists() )
            {
               tocFile = subDir.dirCat("A.TOC");
               if ( !tocFile.exists() )
               {
                  tocFile.clear();
               }
            }
         }
      }
   }

   if ( !dotRpfStr.good() )
   {
      dotRpfStr.clear();
   }
   dotRpfStr.seekg(0, ios_base::beg);

   if ( traceDebug() )
   {
      ossimNotify(ossimNotifyLevel_DEBUG) << "ossimRpfToc::getSourceTocFile result: " << tocFile << "\n";
   }

   return tocFile;
}
Esempio n. 17
0
  bool file_manager::load_file(std::ifstream &fs, string_t& out_buf) const
  {
    if (!fs.is_open() || !fs.good()) return false;

    while (fs.good()) {
      out_buf.push_back(fs.get());
    }

    out_buf.erase(out_buf.size()-1,1);

    return true;
  }
void sigintHandler(int a)
{
    while(footer_kml.good())
    {
        char c = footer_kml.get();       // get character from file
            if (footer_kml.good())
             kml_file << c;
    }
    kml_file << std::endl;

    ros::requestShutdown();
}
Esempio n. 19
0
bool LightRecord::loadFromStream(std::ifstream& inStream)
{
  if (!inStream.good())
  {
    DuskLog() << "LightRecord::loadFromStream: ERROR: stream contains errors.\n";
    return false;
  }
  char ID_Buffer[256];
  uint32_t Header = 0;
  inStream.read((char*) &Header, sizeof(uint32_t));
  if (Header != cHeaderLight)
  {
    DuskLog() << "LightRecord::loadFromStream: ERROR: invalid record header.\n";
    return false;
  }
  //read ID length
  Header = 0;
  inStream.read((char*) &Header, sizeof(uint32_t));
  if (Header>255)
  {
    DuskLog() << "LightRecord::loadFromStream: ERROR: ID is longer than 255"
              << "characters.\n";
    return false;
  }
  //read ID
  memset(ID_Buffer, 0, Header+1);
  inStream.read(ID_Buffer, Header);
  if (!inStream.good())
  {
    DuskLog() << "LightRecord::loadFromStream: ERROR while reading light's"
              << " ID from stream.\n";
    return false;
  }
  ID_Buffer[Header] = '\0'; //make sure it's NUL-terminated
  ID = std::string(ID_Buffer);
  //read RGB and radius
  inStream.read((char*) &red, sizeof(float));
  inStream.read((char*) &green, sizeof(float));
  inStream.read((char*) &blue, sizeof(float));
  inStream.read((char*) &radius, sizeof(float));
  //read light type
  inStream.read((char*) &type, sizeof(Ogre::Light::LightTypes));
  if (!inStream.good())
  {
    DuskLog() << "LightRecord::loadFromStream: ERROR while reading light's"
              << " colour values from stream.\n";
    return false;
  }
  //normalise values, just to be safe
  normalise();
  return true;
}
Esempio n. 20
0
bool NodePartitionedMeshReader::openASCIIFiles(std::string const& file_name_base,
    std::ifstream& is_cfg, std::ifstream& is_node, std::ifstream& is_elem) const
{
    const std::string fname_header = file_name_base +  "_partitioned_";
    const std::string fname_num_p_ext = std::to_string(_mpi_comm_size) + ".msh";

    {   // Configuration.
        std::string const filename = fname_header + "cfg" + fname_num_p_ext;
        is_cfg.open(filename);

        if( !is_cfg.good() )
        {
            ERR("Error opening file %s for input.", filename.c_str());
            return false;
        }

        std::string tmp_line;
        std::getline(is_cfg, tmp_line);
        int num_parts;
        is_cfg >> num_parts >> std::ws;

        if(num_parts != _mpi_comm_size)
        {
            ERR("Aborting computation because of number of cores"
                "/ subdomains mismatch.");
            return false;
        }
    }

    {   // Nodes.
        std::string const filename = fname_header + "nodes_" + fname_num_p_ext;
        is_node.open(filename);
        if( !is_node.good() )
        {
            ERR("Error opening file %s for input.", filename.c_str());
            return false;
        }
    }

    {   // Elements.
        std::string const filename = fname_header + "elems_" + fname_num_p_ext;
        is_elem.open(filename);
        if( !is_elem.good() )
        {
            ERR("Error opening file %s for input.", filename.c_str());
            return false;
        }
    }

    return true;
}
Esempio n. 21
0
bool TGAImage::load_rle_data(std::ifstream &in) {
	unsigned long pixelcount = width*height;
	unsigned long currentpixel = 0;
	unsigned long currentbyte = 0;
	TGAColor colorbuffer;
	do {
		unsigned char chunkheader = 0;
		chunkheader = in.get();
		if (!in.good()) {
			std::cerr << "an error occured while reading the data\n";
			return false;
		}
		if (chunkheader<128) {
			chunkheader++;
			for (int i = 0; i<chunkheader; i++) {
				in.read((char *)colorbuffer.raw, bytespp);
				if (!in.good()) {
					std::cerr << "an error occured while reading the header\n";
					return false;
				}
				for (int t = 0; t<bytespp; t++)
					data[currentbyte++] = colorbuffer.raw[t];
				currentpixel++;
				if (currentpixel>pixelcount) {
					std::cerr << "Too many pixels read\n";
					return false;
				}
			}
		}
		else {
			chunkheader -= 127;
			in.read((char *)colorbuffer.raw, bytespp);
			if (!in.good()) {
				std::cerr << "an error occured while reading the header\n";
				return false;
			}
			for (int i = 0; i<chunkheader; i++) {
				for (int t = 0; t<bytespp; t++)
					data[currentbyte++] = colorbuffer.raw[t];
				currentpixel++;
				if (currentpixel>pixelcount) {
					std::cerr << "Too many pixels read\n";
					return false;
				}
			}
		}
	} while (currentpixel < pixelcount);
	return true;
}
Esempio n. 22
0
bool SoundRecord::loadFromStream(std::ifstream& inStream)
{
  uint32_t len = 0;
  //read header "Soun" (Sound)
  inStream.read((char*) &len, sizeof(uint32_t));
  if (len!=cHeaderSoun)
  {
    DuskLog() << "SoundRecord::loadFromStream: ERROR: Stream contains invalid "
              << "record header.\n";
    return false;
  }//if
  //read length of ID
  inStream.read((char*) &len, sizeof(uint32_t));
  if (len>255)
  {
    DuskLog() << "SoundRecord::loadFromStream: ERROR: ID cannot be longer than "
              << "255 characters.\n";
    return false;
  }
  //read ID
  char buffer[256];
  memset(buffer, 0, 256);
  inStream.read(buffer, len);
  if (!inStream.good())
  {
    DuskLog() << "SoundRecord::loadFromStream: ERROR while reading ID.\n";
    return false;
  }
  ID = std::string(buffer);
  //read length of path
  inStream.read((char*) &len, sizeof(uint32_t));
  if (len>255)
  {
    DuskLog() << "SoundRecord::loadFromStream: ERROR: File path cannot "
              << "be longer than 255 characters.\n";
    return false;
  }
  //read mesh
  memset(buffer, 0, 256);
  inStream.read(buffer, len);
  if (!inStream.good())
  {
    DuskLog() << "SoundRecord::loadFromStream: ERROR while reading path data.\n";
    return false;
  }
  filePath = std::string(buffer);

  return (!filePath.empty() and !ID.empty());
}
Esempio n. 23
0
  //-------------------------------------------------------------------------//
  bool Material::Load(std::ifstream& ifs)
  {
    //-----------------------------------------------------------------------//
    // Throw assertion is file streams is not open.
    assert(ifs.is_open() && ifs.good());
    //-----------------------------------------------------------------------//

    //-----------------------------------------------------------------------//
    // If the file stream is not open return false.
    if(!ifs.is_open() || !ifs.good())
      return false;
    //-----------------------------------------------------------------------//

    //-----------------------------------------------------------------------//
    // This string will hold the label that describes some camera parameter.
    string strLabel;
    //-----------------------------------------------------------------------//

    //-----------------------------------------------------------------------//
    // This unsigned short will count the number of camera parameters read in
    // and will be used to verify that the correct number of parameters have 
    // been initialized.
    unsigned short usParameterCount = 0;
    //-----------------------------------------------------------------------//

    //-----------------------------------------------------------------------//
    // The for loop will read in data from the file stream and will set 
    // the objects data members accordingly.
    for(unsigned short i = 0; i < NUMBER_OF_MATERIAL_PARAMETERS; i++)
    {
      //---------------------------------------------------------------------//
      // Read in the label
      ifs >> strLabel;
      //---------------------------------------------------------------------//

      //---------------------------------------------------------------------//
      // Match the label to some predefined token and set the proper data member.
      float fR, fG, fB, fA;
      if(strLabel == DIFFUSE_COLOR_LABEL)
      {
        ifs >> fR;
        ifs >> fG;
        ifs >> fB;
        ifs >> fA;
        this->SetDiffuse(fR, fG, fB);
        usParameterCount++;
      }
      else if(strLabel == AMBIENT_FACTOR_LABEL)
Esempio n. 24
0
bool FastaFile::readLine() {
  int n;

  ifsIn.getline(pcLine, nMaxLineLength);
  if ( pcLine[0] == '>' ) {
    if ( curSeqIndex >= 0 ) {
      updateCurrentSequenceInfo();
    }
    std::vector<std::string> tokens;
    tokenizeString(pcLine, tokens);
    curSeqName = tokens[0].substr(1); // make SeqName without leading '>'
    MD5Init(&curMD5Ctx);
    curSeqLength = 0;
    ++curSeqIndex;
  }
  else {
    n = strlen(pcLine);
    // convert to upper-case for calculating FASTA MD5
    for(int i = 0; i < n; ++i)
    {
        pcLine[i] = toupper(pcLine[i]);
    }
    MD5Update(&curMD5Ctx, (unsigned char*)pcLine, n);
    curSeqLength += n;
  }
  ++nCurrentLine;
  return ifsIn.good();
}
Esempio n. 25
0
void tokenizePatternFile(std::ifstream& in) {
    // tokenize a line from the pattern file.  The first part will be the pattern and the second
    // part is the file to write to.

    std::string lineptr;

    while(in.good()) {
        std::getline(in, lineptr);
        if(lineptr.empty()) {
            continue;
        }
        std::vector<std::string> fields;
        split(fields, lineptr, "\t");
        switch(fields.size()) {
            case 0:
                break;
            case 1:
                manager.add(fields[0]);
                if(opts.r_flag) {
                    std::string rcpattern = fields[0];
                    reverseComplement(rcpattern);
                    manager.add(rcpattern);
                }
                break;
            default:
                manager.add(fields[0], fields[1]);
                if(opts.r_flag) {
                    std::string rcpattern = fields[0];
                    reverseComplement(rcpattern);
                    manager.add(rcpattern, fields[1]);
                }
                break;
        }
    }
}
Esempio n. 26
0
    bool InpNativeInfo::read_file()
    {
        if(already_read)
            std::cout << "Warning: trying to substitute ninfo for already initiated object." 
                      << std::endl;
        already_read = true;

        if(!inpfile.good())
        {
            throw std::invalid_argument("file open error");
        }
        bool read(false);
        
        while(!inpfile.eof())
        {
            std::string line;
            std::getline(inpfile, line);

            if(line.empty()) continue;
            if(line[0] == '\x2a') continue;

            if(eq_ignorecase(line.substr(0,20), "<<<< native_info_sim"))
            {
                read = true;
                std::string temp(line, 20);
                simN = std::stoi(temp);
                read_block(inpfile);
            }
        }
        return read;
    }
Esempio n. 27
0
void displaytext_delay(std::ifstream& File)
{
    std::string Lines = "";
    int j=0;
    sleep_for(seconds(3));
    if (File)
    {
		while (File.good ())
		{
			std::string TempLines;
			std::getline (File , TempLines);
			TempLines += "\n";
			char myArray[TempLines.size()+1];
			strcpy(myArray, TempLines.c_str());
				for (int i=0; i<TempLines.size();i++)
				{
				mvaddch(j,(40+i),myArray[i]);
				refresh();
				sleep_for(milliseconds(50));
				}
			j=j+1;
			refresh();
			sleep_until(system_clock::now() + seconds(1));
		}
		printw("###################$$$$$$$$$$$$$$$$###################\n");
		printw("                   WELCOME TO DORK\n");
		printw("###################$$$$$$$$$$$$$$$$###################\n");
    }
    else                           //Return error
    {
	cout<< "ERROR File does not exist.";
    }
}
Esempio n. 28
0
void l1menu::TriggerMenu::loadMenuInOldFormat( std::ifstream& file )
{
	const size_t bufferSize=200;
	char buffer[bufferSize];

	while( file.good() )
	{
		try
		{
			// Get one line at a time
			file.getline( buffer, bufferSize );

			// split the line by whitespace into columns
			std::vector<std::string> tableColumns=l1menu::tools::splitByWhitespace( buffer );

			if( tableColumns.size()==1 && tableColumns[0].empty() ) continue; // Allow blank lines without giving a warning
			if( tableColumns.size()!=12 ) throw std::runtime_error( "The line does not have the correct number of columns" );

			addTriggerFromOldFormat( tableColumns );

		} // end of try block
		catch( std::runtime_error& exception )
		{
			std::cout << "Some error occured while processing the line \"" << buffer << "\":" << exception.what() << std::endl;
		}
	}
}
Esempio n. 29
0
std::vector <points> read (std::ifstream &f,int a,int b,int c,int d){
std::vector <points> v;
f.clear();
f.seekg(0, std::ios::beg);

while (f.good()){
std::string s;
f>>s;
std::stringstream ss;
ss<<s;
int temp_x,temp_y;
ss>>temp_x;
s.clear();ss.clear();
f>>s;
ss<<s;
ss>>temp_y;


points temp(temp_x,temp_y,a,b,c,d);
v.push_back(temp);
}







return v;
}
Esempio n. 30
0
void GlowNodeGroup::open(std::ifstream& fp)
{
  int type = 0;
  int end_found = 0;
  char dummy[40];

  for (;;) {
    if (!fp.good()) {
      fp.clear();
      fp.getline(dummy, sizeof(dummy));
      printf("** Read error GlowNodeGroup: \"%d %s\"\n", type, dummy);
    }

    fp >> type;
    switch (type) {
    case glow_eSave_NodeGroup:
      break;
    case glow_eSave_NodeGroup_nodeclass_part:
      GlowNodeClass::open(fp);
      break;
    case glow_eSave_End:
      end_found = 1;
      break;
    default:
      std::cout << "GrowGroup:open syntax error\n";
      fp.getline(dummy, sizeof(dummy));
    }
    if (end_found)
      break;
  }
}