void SetUp() {
		graph_file.open(GRAPH_FILENAME, std::fstream::in);
		ASSERT_FALSE(graph_file.fail()) << "unable to open " << GRAPH_FILENAME;
		solved_file.open(SOLUTION_FILENAME, std::fstream::in);
		ASSERT_FALSE(solved_file.fail()) << "unable to open " << SOLUTION_FILENAME;

		original = fs::DIMACSOriginalImporter<fs::FlowNetwork>(graph_file).read();
		ASSERT_NE(original, nullptr) << "DIMACS parse error";
		augmented = new fs::FlowNetwork(*original);
		fs::DIMACSFlowImporter<fs::FlowNetwork>(solved_file, *augmented).read();
	}
예제 #2
0
long long TCPTransport::recvfile(std::fstream& ofs, long long offset, long long size)
{
    if (!m_bConnected)
        return -1;

    if (ofs.bad() || ofs.fail())
        return -1;

    ofs.seekp(offset);

    int block = 1000000;
    char* buf = new char[block];
    long long recd = 0;
    while (recd < size)
    {
        int unit = int((size - recd) > block ? block : size - recd);
        recv(buf, unit);
        ofs.write(buf, unit);
        recd += unit;
    }

    delete [] buf;

    return recd;
}
예제 #3
0
long long TCPTransport::sendfile(std::fstream& ifs, long long offset, long long size)
{
    if (!m_bConnected)
        return -1;

    if (ifs.bad() || ifs.fail())
        return -1;

    ifs.seekg(offset);

    int block = 1000000;
    char* buf = new char[block];
    long long sent = 0;
    while (sent < size)
    {
        int unit = int((size - sent) > block ? block : size - sent);
        ifs.read(buf, unit);
        send(buf, unit);
        sent += unit;
    }

    delete [] buf;

    return sent;
}
예제 #4
0
	virtual uint32 read(void *dataPtr, uint32 dataSize) {
		_fileStream->read((char *)dataPtr, dataSize);
		if (_fileStream->fail()) {
			return 0;
		}
		return dataSize;
	}
예제 #5
0
bool
StandardFileProvider::open( std::string name, Mode mode )
{
    ios::openmode om = ios::binary;
    switch( mode ) {
        case MODE_UNDEFINED:
        case MODE_READ:
        default:
            om |= ios::in;
            _seekg = true;
            _seekp = false;
            break;

        case MODE_MODIFY:
            om |= ios::in | ios::out;
            _seekg = true;
            _seekp = true;
            break;

        case MODE_CREATE:
            om |= ios::in | ios::out | ios::trunc;
            _seekg = true;
            _seekp = true;
            break;
    }

    _fstream.open( name.c_str(), om );
    _name = name;
    return _fstream.fail();
}
예제 #6
0
bool
StandardFileProvider::seek( Size pos )
{
    if( _seekg )
        _fstream.seekg( pos, ios::beg );
    if( _seekp )
        _fstream.seekp( pos, ios::beg );
    return _fstream.fail();
}
예제 #7
0
bool
StandardFileProvider::write( const void* buffer, Size size, Size& nout, Size maxChunkSize )
{
    _fstream.write( (const char*)buffer, size );
    if( _fstream.fail() )
        return true;
    nout = size;
    return false;
}
예제 #8
0
bool
StandardFileProvider::read( void* buffer, Size size, Size& nin, Size maxChunkSize )
{
    _fstream.read( (char*)buffer, size );
    if( _fstream.fail() )
        return true;
    nin = _fstream.gcount();
    return false;
}
예제 #9
0
void closeLogFile(std::fstream& logFile)
{
    logFile.close();

    if (logFile.fail())
    {
        std::cout << "ERROR while closing the log file" << std::endl;
        exit(EXIT_FAILURE);
    }
}
예제 #10
0
	MyFileReadStream(const char *filename) {
		_stream = new std::fstream(filename, std::fstream::in);
		if (_stream->fail()) {
			isOpen = false;
			delete _stream; // Primarily done to make sure we crash if this isn't handled.
			_stream = NULL;
		} else {
			isOpen = true;
		}
	}
예제 #11
0
파일: bot.cpp 프로젝트: raj61/chatBot
/*
void TechBot::Saveunknown_input()
{
    std::fstream fout("unknown.txt", std::ios::out);
    if(fout.fail())
    {
        throw std::string("Unable to save Unknown Input List");
    }
    Vstr::const_iterator iter = ListOfUnknownInput.begin();
    for( ; iter != ListOfUnknownInput.end(); ++iter )
    {
        fout << *iter << std::endl;
    }
    fout.flush();
    fout.close();
}
*/
void TechBot::Savelog()
{
    time_t ltime; 
    time(&ltime);
    logfile.open("log.txt", std::ios::out | std::ios::app);
    if(logfile.fail()) 
    {
        throw std::string("can't save conversation log");
    }
    logfile << "\n\nConversation log - " << ctime(&ltime) << std::endl;
}
예제 #12
0
	SeekableFileStream(const char *name) {
		_fileStream = new std::fstream();
		_fileStream->open(name, std::fstream::in | std::fstream::binary);
		if (_fileStream->fail()) {
			_length = -1;
		} else {
			_fileStream->seekg(0, std::ios_base::end);
			_length = _fileStream->tellg();
			_fileStream->seekg(0, std::ios_base::beg);
		}
	}
예제 #13
0
void openLogFile(std::fstream& logFile, const char* logFileName)
{
    // Open the log file with append flag
    logFile.open(logFileName, std::ios_base::app);

    if (logFile.fail())
    {
        GET_TIME
        std::cout << timeBuffer << "\t"
                  << SYS_CALL_ERR_MSG("open", strerror(errno));
        exit(EXIT_FAILURE);
    }
}
예제 #14
0
	/**
	 * Sets the stream position indicator for the stream. The new position,
	 * measured in bytes, is obtained by adding offset bytes to the position
	 * specified by whence. If whence is set to SEEK_SET, SEEK_CUR, or
	 * SEEK_END, the offset is relative to the start of the file, the current
	 * position indicator, or end-of-file, respectively. A successful call
	 * to the seek() method clears the end-of-file indicator for the stream.
	 *
	 * @note The semantics of any implementation of this method are
	 * supposed to match those of ISO C fseek().
	 *
	 * @param offset	the relative offset in bytes
	 * @param whence	the seek reference: SEEK_SET, SEEK_CUR, or SEEK_END
	 * @return true on success, false in case of a failure
	 */
	virtual bool seek(int32 offset, int whence = SEEK_SET) {
		if (whence == SEEK_SET) {
			_stream->seekg(offset, std::ios::beg);
		} else if (whence == SEEK_CUR) {
			_stream->seekg(offset, std::ios::cur);
		} else {
			_stream->seekg(offset, std::ios::end);
		}
		
		if (_stream->fail())
			return false;
		if (_stream->bad())
			return false;
		return true;
	}
예제 #15
0
파일: dollar.cpp 프로젝트: alexezh/trv
bool Dollar::OpenScriptStream(const char * pszName, std::fstream& stm)
{
	for(int i = 0;;i++)
	{
		std::string fileName;

		if(i == 0)
		{
			// use current dir
			fileName = pszName;
		}
		else if (i == 1)
		{
			fileName = GetCurrentHost()->GetAppDataDir();
			fileName += "\\";
			fileName += pszName;
		}
		else if (i == 2)
		{
			// exe directory 
			char szPath[_MAX_PATH];
			char szDrive[_MAX_PATH];
			char szDir[_MAX_PATH];
			GetModuleFileNameA(NULL, szPath, _countof(szPath)); 

			_splitpath(szPath, szDrive, szDir, NULL, NULL);
			fileName = szDrive;
			fileName += szDir;
			fileName += pszName;
		}
		else
		{
			break;
		}
		stm.open(fileName, std::fstream::in);
		if(!stm.fail())
		{
			return true;
		}
	}

	return false;
}
예제 #16
0
파일: xml.cpp 프로젝트: doniexun/OrangeC
bool xmlAttrib::Read(std::fstream &stream)
{
    char t;
    stream >> t;
    if (stream.fail()) return false;
    while (isspace(t))
    {
        stream >> t;
        if (stream.fail()) return false;
    }
    if (isalpha(t)|| t=='_')
    {
        char buf[512];
        char *p = buf;
        buf[0] = 0;
        while (isalnum(t)|| t=='_')
        {
            *p++ = t;
            stream >> t;
            if (stream.fail()) return false;
        }
        *p = 0;
        name = buf;
        while (isspace(t))
        {
            stream >> t;
            if (stream.fail()) return false;
        }
        if (t != '=')
            return false;		
        stream >> t;
        if (stream.fail()) return false;
        while (isspace(t))
        {
            stream >> t;
            if (stream.fail()) return false;
        }
        if (t != '\"')
            return false;
        if (!ReadTextString(stream, value))
            return false;
    }
예제 #17
0
bool
StandardFileProvider::close()
{
    _fstream.close();
    return _fstream.fail();
}