コード例 #1
0
ファイル: image_io.cpp プロジェクト: amarburg/Pangolin
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.");
}
コード例 #2
0
ファイル: main.cpp プロジェクト: akalsi87/pcsh
void die_if_unable_to_open_file(std::ifstream& in, const std::string& fn)
{
        if (in.fail()) {
        auto msg = "Failed to open file `" + fn + "'.";
        PCSH_ENFORCE_MSG(!in.fail(), msg.c_str());
    }
}
コード例 #3
0
void OpenMTP_binary_header::read( std::ifstream &file )
{
  unsigned char *pnt;

  memset(header, 0, BUFLEN);

  file.read((char *) header, BINARY_HEADER_FIRST_SECTION_LENGTH);
  if (file.fail( ))
  {
    std::cerr << "Read error : BINARY Header, first section." << std::endl;
    throw;
  }

  pnt = header + BINARY_HEADER_FIRST_SECTION_LENGTH;

  if (is_rectified())
  {
    file.seekg(BINARY_HEADER_SECOND_SECTION_LENGTH, ios::cur);
    if (file.fail( ))
    {
      std::cerr << "Read error : BINARY Header, second section" << std::endl;
      throw;
    }
  }
  else
  {
    file.read((char *) pnt, BINARY_HEADER_SECOND_SECTION_LENGTH);
    if (file.fail( ))
    {
      std::cerr << "Read error : BINARY Header, second section" << std::endl;
      throw;
    }
  }

  pnt = pnt + BINARY_HEADER_SECOND_SECTION_LENGTH;
  if (is_visible_composite())
  {
    file.read((char *) pnt, BINARY_HEADER_THIRD_SECTION_VIS_CMP_LENGTH);
    if (file.fail( ))
    {
      std::cerr << "Read error : BINARY Header, third section" << std::endl;
      throw;
    }
  }
  else
  {
    file.read((char *) pnt, BINARY_HEADER_THIRD_SECTION_NORMAL_LEGTH);
    if (file.fail( ))
    {
      std::cerr << "Read error : BINARY Header, third section" << std::endl;
      throw;
    }
  }

  return;
}
コード例 #4
0
//the case if encounter a angle bracket "["
void MDparser::angleBracket(std::string& tobeStored, bool& readyToStore, std::ifstream& myinput, myset<std::string>& allWords, myset<std::string>& allLinks){
	string buffer("");

    char letter=(char)myinput.get();
    while(letter!=']'&& !myinput.fail()){
      buffer=buffer+letter;
      letter=(char)myinput.get();
   }
   buffer+="]";
   //parsing,change bool varibale to false
   for (int i=0;i<(int)buffer.size();i++){
   		letter=buffer[i];
   		if(isLetter(letter)){
   			readyToStore=true;
   			tobeStored+=letter;
   		}
   		else if(!isLetter(letter)&&readyToStore){
   			allWords.insert(tobeStored);
   			tobeStored="";
   			readyToStore=false;
   		}
   		else if(!isLetter(letter)&&!readyToStore){
   			//donothing
   		}
   }

   if(!myinput.fail()){
   	   letter=(char)myinput.get(); //get the next letter after']'
		if(letter=='('){
			buffer="";
			letter=(char)myinput.get();
			while(letter!=')'){
				buffer+=letter;
				letter=(char)myinput.get();
			}
			ifstream my_input(buffer.c_str());
			if(!my_input.fail()){
				allLinks.insert(buffer);				
			}
			my_input.close();
			buffer="";
			readyToStore=false;
		}
		else{
			if(isLetter(letter)){
				readyToStore=true;
				tobeStored+=letter;
			}
			else{
				readyToStore=false;
			}
		}
   }
}
コード例 #5
0
bool TUtilities::CheckAndCompareFileString(std::ifstream &InFile, AnsiString InString)
//Reads the next item and checks it as a string value up to either the '\0' delimiter
//if there is one, in which case the '\0' is extracted but nothing more, or up to the next '\n',
//in which case the '\n' is extracted.  There may or may not be a '\n' at the start, and if there
//is it is ignored (only one is ignored, a second one is treated as a delimiter).
//The item is then compared with InString and fails if different.
{
char TempChar;
char *Buffer = new char[10000];
int Count = 0;
InFile.get(TempChar);//may or may not be '\n'
if(InFile.fail())
    {
    delete Buffer;
    return false;
    }
if(TempChar == '\n')
    {
    InFile.get(TempChar);//get the next one if first was '\n'
    if(InFile.fail())
        {
        delete Buffer;
        return false;
        }
    }
while((TempChar != '\0') && (TempChar != '\n'))
    {
    if((TempChar < 32) && (TempChar >= 0))
        {
        delete Buffer;
        return false;
        }
    Buffer[Count] = TempChar;
    Count++;
    InFile.get(TempChar);
    if(InFile.fail())
        {
        delete Buffer;
        return false;
        }
    }
Buffer[Count] = '\0';
Count++;
Buffer[Count] = '\n';
Count++;
if(AnsiString(Buffer) != InString)
    {
    delete Buffer;
    return false;
    }
delete Buffer;
return true;
}
コード例 #6
0
 /**
  * This helper method just moves forward the two file pointers to skip some header lines.
  * @param numLinesToSkip  The number of header lines to skip
  */
 void SkipHeaderLines(unsigned numLinesToSkip)
 {
     if (!mCalledCollectively || PetscTools::AmMaster())
     {
         for (unsigned line_number=0; line_number<numLinesToSkip; line_number++)
         {
             char buffer[1024];
             mpFile1->getline(buffer, 1024);
             mpFile2->getline(buffer, 1024);
             TS_ASSERT(!mpFile1->fail()); // Here we assume there are at least "ignoreFirstFewLines" lines...
             TS_ASSERT(!mpFile2->fail()); // ...and that they are lines of no more than 1024 characters
             mLineNum++;
         }
     }
 }
コード例 #7
0
//---------------------------------------------------------------------------
bool TUtilities::CheckFileInt(std::ifstream &InFile, int Lowest, int Highest)
//no need to worry about leading '\n' characters as the skipws (skip white space) flag is
//set automatically
{
AnsiString IntString;
if(!CheckAndReadFileString(InFile, IntString)) return false;
if(InFile.fail()) return false;
if(IntString == "") return false;
for(int x=1;x<=IntString.Length();x++)
    {
    bool CharacterOK = false;
    if((x == 1) && (IntString[x] == '-'))
        {
        CharacterOK = true;
        }
    else if((IntString[x] >= '0') && (IntString[x] <= '9'))
        {
        CharacterOK = true;
        }
    if(!CharacterOK) return false;
    }
int TempInt = IntString.ToInt();
if((TempInt < Lowest) || (TempInt > Highest))
    {
    return false;
    }
return true;
}
コード例 #8
0
ファイル: io.cpp プロジェクト: bfisch02/csax_cpp
void openInputFile(std::ifstream& s, std::string path){
  s.open(path);
  if(s.fail()){
    std::cerr << "Failure opening file \"" << path << "\" for input." << std::endl;
    exit(0);
  }
}
コード例 #9
0
ファイル: FileSystemStorage.cpp プロジェクト: binary42/OCI
bool File::read(std::ifstream& stream)
{
  CwdGuard cg(physical_dir_);
  stream.open(ACE_TEXT_ALWAYS_CHAR(physical_file_.c_str()),
              ios::binary | ios::in);
  return !stream.bad() && !stream.fail();
}
コード例 #10
0
ファイル: fileio.cpp プロジェクト: bholtsclaw/uox3
void ReadWorldTagData( std::ifstream &inStream, UString &tag, UString &data )
{
	char temp[4096];
	tag = "o---o";
	data = "o---o";
	while( !inStream.eof() && !inStream.fail() )
	{
		inStream.getline( temp, 4096 );
		UString sLine( temp );
		sLine = sLine.removeComment().stripWhiteSpace();
		if( !sLine.empty() )
		{
			if( sLine != "o---o" )
			{
				if( sLine.sectionCount( "=" ) == 1 )
				{
					tag		= sLine.section( "=", 0, 0 ).stripWhiteSpace();
					data	= sLine.section( "=", 1 ).stripWhiteSpace();
					break;
				}
			}
			else
				break;
		}
	}
}
コード例 #11
0
ファイル: TetGenInterface.cpp プロジェクト: wolf-pf/ogs_kb1
bool TetGenInterface::readElementsFromStream(std::ifstream &ins)
{
	std::string line;
	getline (ins, line);
	size_t pos_beg (line.find_first_not_of(" "));
	size_t n_tets, n_nodes_per_tet;
	bool region_attributes;
	bool not_read_header (true);

	while (!ins.fail() && not_read_header)
	{
		line = line.substr(pos_beg);
		if (line.compare(0,1,"#") == 0)
		{
			// this line is a comment - skip
			getline (ins, line);
			pos_beg = line.find_first_not_of(" ");
		}
		else
			// read header line
			not_read_header = !parseElementsFileHeader(line,
			                                           n_tets,
			                                           n_nodes_per_tet,
			                                           region_attributes);
	}
	if (not_read_header)
		return false;
	if (!parseElements(ins, n_tets, n_nodes_per_tet, region_attributes))
		return false;

	return true;
}
コード例 #12
0
ファイル: main.cpp プロジェクト: SavourySnaX/EDL
static int getNextLine(void)
{
	int i;
	char *p;
  
	nBuffer = 0;
	nTokenStart = -1;
	nTokenNextStart = 0;
	eof = false;

	std::getline(inputFile, buffer);
	if (inputFile.eof())
	{
		eof = true;
		return 1;
	}
	if (inputFile.fail())
	{
		return -1;
	}

	buffer += "\n";
	std::replace(buffer.begin(), buffer.end(), '\t', ' ');

	fileLineMap[currentFileName].push_back(buffer);
	nRow += 1;
	lBuffer = buffer.length();

	return 0;
}
コード例 #13
0
ファイル: CollisionHandler.cpp プロジェクト: js4768/4167T2M1
void CollisionHandler::loadImpulses(std::vector<CollisionInfo> &impulses, std::ifstream &ifs)
{
  impulses.clear();
  int numimpulses=0;
  ifs.read((char *)&numimpulses, sizeof(int));
  for(int i=0; i<numimpulses; i++)
    {
      CollisionInfo::collisiontype type;
      ifs.read((char *)&type, sizeof(CollisionInfo::collisiontype));
      int idx1, idx2;
      ifs.read((char *)&idx1, sizeof(int));
      ifs.read((char *)&idx2, sizeof(int));
      VectorXs n(2);
      ifs.read((char *)n.data(), n.size()*sizeof(scalar));
      double time;
      ifs.read((char *)&time, sizeof(double));
      impulses.push_back(CollisionInfo(type, idx1, idx2, n, time));
    }

  if( ifs.fail() )
    {
      std::cout << outputmod::startred << "Error while trying to deserialize time step impulses. Exiting." << std::endl;
      exit(1);
    }
}
コード例 #14
0
void RegionFileLoader::LoadDataFromFile(std::ifstream &file)
{
    if (file.fail())
    {
        std::cerr << "Error <RegionFileLoader::LoadDataFromFile> File is unreadable" <<  std::endl;
        return;
    }

    Double_t sa;
    std::string aline;
    std::stringstream ss;
    while(1)
    {
        std::getline(file,aline);
        if ( FileIsNotOkay(file) )
            break;
        else if ( LineShouldBeSkipped(aline) )
            continue;
        else if ( BeginningOfRegions(aline) )
        {
//            std::cout << aline << std::endl;
            Regions regions = ReadRegions(file);
            if (regions.size()>0)
                fTheRegions.push_back(regions);
        }
    }

    file.close();

}
コード例 #15
0
ファイル: FileIO.cpp プロジェクト: Kosyl/H265Lib
		bool readValue(std::ifstream& str, std::string key, T& out_value)
		{
			try
			{
				if (!goToMarker(str, key) || str.eof() || str.fail())
					return false;
				str >> out_value;
				if (str.eof() || str.fail())
					return false;
			}
			catch (...)
			{
				return false;
			}
			return true;
		}
コード例 #16
0
std::string openFileDialog(std::ifstream& stream,
                           const std::string& title,
                           const std::string& path) {
    std::string filename = pp->file_openFileDialog(title, "load", path);
    if (filename == "") return "";
    stream.open(filename.c_str());
    return (stream.fail()) ? "" : filename;
}
コード例 #17
0
ファイル: iohelpers.cpp プロジェクト: frankwz/codecrypt
bool redirect_cin (const std::string& fn)
{
	static std::ifstream alt_cin;
	alt_cin.open (fn.c_str(), std::ios::in | std::ios::binary);
	if (alt_cin.fail() ) return false;
	std::cin.rdbuf (alt_cin.rdbuf() );
	return true;
}
コード例 #18
0
ファイル: main.cpp プロジェクト: Lvyn/neco-net-compiler
void readline(std::string* dst, std::ifstream& stream) {
    char buf[1024];
    do {
        stream.clear();
        stream.getline(buf, 1024);
        *dst += buf;
    } while( stream.fail() && !stream.eof() );
}
コード例 #19
0
ファイル: BmpToTga.cpp プロジェクト: GitTaniguchi/Kadai
int LoadFileHeader( std::ifstream& ifs, BITMAPFILEHEADER& header ) {
	ifs.read( reinterpret_cast< char* >( &header.bfType ), 2 );
	ifs.read( reinterpret_cast< char* >( &header.bfSize ), 4 );
	ifs.read( reinterpret_cast< char* >( &header.bfReserved1 ), 2 );
	ifs.read( reinterpret_cast< char* >( &header.bfReserved2 ), 2 );
	ifs.read( reinterpret_cast< char* >( &header.bfOffBits ), 4 );
	return ifs.fail();
}
コード例 #20
0
void safe_open(std::ifstream& f, const std::string& prompt, const std::string& default_name) {
  for (;;) {
    std::string file_name = prompt_string(prompt,default_name);
    f.open(file_name.c_str());
    if (!f.fail())
      break;
    std::cout << "Opening " << file_name << " failed." << std::endl;
  }
}
コード例 #21
0
ファイル: level.cpp プロジェクト: yugiohatemu/ForScience
//return -1 if fail to read file
int Level::get_int_from_file(std::ifstream &file){
    int n = -1;
    file >> n;
    if (file.fail()) {
        debug("load map fail");
    }
    
    return n;
}
コード例 #22
0
/*---------------------------------------------------------*/
bool NOMAD::Cache_File_Point::read ( std::ifstream & fin )
{
  reset();

  // 1. _eval_status:
  fin.read ( (char *) &_eval_status , sizeof(_eval_status) );
  if ( fin.fail() || _eval_status > 3 )
    return false;

  // 2. _n:
  fin.read ( (char *) &_n , sizeof(_n) );
  if ( fin.fail() || _n <= 0 ) {
    _n = 0;
    return false;
  }

  // 3. _m:
  fin.read ( (char *) &_m , sizeof(_m) );
  if ( fin.fail() || _m < 0 ) {
    _n = _m = 0;
    return false;
  }

  // 4. _m_def:
  fin.read ( (char *) &_m_def , sizeof(_m_def) );
  if ( fin.fail() || _m_def < 0 ) {
    _m_def = _n = _m = 0;
    return false;
  }

  // 5. _coords:
  _coords = new double [_n];
  fin.read ( (char *) _coords , _n*sizeof(double) );
  if ( fin.fail() ) {
    reset();
    return false;
  }

  if ( _m_def > 0 ) {

    // 6. _bb_def:
    _bbo_def = new double [_m_def];
    fin.read ( (char *) _bbo_def , _m_def*sizeof(double) );
    if ( fin.fail() ) {
      reset();
      return false;
    }
  
    // 7. _bbo_index:
    _bbo_index = new int [_m_def];
    fin.read ( (char *) _bbo_index , _m_def*sizeof(int) );
    if ( fin.fail() ) {
      reset();
      return false;
    }
  }

  return true;
}
コード例 #23
0
/*
* Opens a text file whose name is entered by the user. If the file
* does not exist, the user is given additional chances to enter a
* valid file. The prompt string is used to tell the user what kind
* of file is required.
*/
void askUserForInputFile(std::string prompt, std::ifstream & infile) {
	while (true) {
		cout << prompt;
		string filename = getLine();
		infile.open(filename.c_str());
		if (!infile.fail()) break;
		cout << "Unable to open " << filename << endl;
		infile.clear();
	}
}
コード例 #24
0
ファイル: IOUtil.cpp プロジェクト: HPCToolkit/hpctoolkit
void
OpenIFile(std::ifstream& fs, const char* filenm)
{
  using namespace std;

  fs.open(filenm, ios::in);
  if (!fs.is_open() || fs.fail()) {
    DIAG_Throw("Cannot open file '" << filenm << "'");
  }
}
コード例 #25
0
ファイル: prt_ifstream.hpp プロジェクト: nyue/PRT-IO-Library
    /**
     * Opens the prt_ifstream to read from the specified file
     * @param file Path to the file to read particles from
     */
    void open( const std::string& file ) {
        m_fin.open( file.c_str(), std::ios::in | std::ios::binary );
        if( m_fin.fail() )
            throw std::ios_base::failure( "Failed to open file \"" + file + "\"" );

        m_filePath = file;
        m_fin.exceptions( std::ios::badbit );

        read_header();
        init_zlib();
    }
コード例 #26
0
ファイル: putCommand.cpp プロジェクト: ytn86/LikeFTP
void PutCommand::openFile(std::string& filename, std::ifstream &ifs)
{
	ifs.open(filename, std::ifstream::binary);
	if (ifs.fail() == true) {

		this->header["size"] = "-1";		
	} else {
		this->header["size"] = std::to_string(this->getFileSize(ifs));
	}	

}
コード例 #27
0
ファイル: getCommand.cpp プロジェクト: ytn86/LikeFTP
void GetCommand::openFile(std::ifstream &ifs)
{
	ifs.open(this->header["filename"], std::ifstream::binary);
	if (ifs.fail() == true) {
		std::cerr << "Failed to open : " << this->header["filename"] << std::endl;
		this->header["size"] = "-1";		
	} else {
		this->header["size"] = std::to_string(this->getFileSize(ifs));
	}	

}
コード例 #28
0
 /*
 * Open an ifstream with fully specified path and mode.
 */
 void
 FileMaster::open(const std::string& name, std::ifstream& in,
                  std::ios_base::openmode mode) const
 {
    in.open(name.c_str(), mode);
    if (in.fail()) {
       std::string message = "Error opening input file. Filename: ";
       message += name;
       UTIL_THROW(message.c_str());
    }
 }
コード例 #29
0
std::string promptUserForFile(std::ifstream &inFile, std::string prompt) {
    while (true) {
        std::cout << prompt;
        std::string fileName;
        getline(std::cin, fileName);
        inFile.open(fileName.c_str());
        if (!inFile.fail()) return fileName;
        inFile.clear();
        std::cout << "Unable to open that file. Try again." << std::endl;
        if (prompt == "") prompt = "Input file: ";
    }
}
コード例 #30
0
//---------------------------------------------------------------------------
bool TUtilities::CheckFileBool(std::ifstream &InFile)
//no need to worry about leading '\n' characters as the skipws (skip white space) flag is
//set automatically
{
AnsiString BoolString;
if(!CheckAndReadFileString(InFile, BoolString)) return false;
if(InFile.fail()) return false;
if(BoolString == "") return false;
if((BoolString.Length() > 1) || (BoolString == "")) return false;
if((BoolString != "0") && (BoolString != "1")) return false;
return true;
}