Пример #1
0
bool ZipArchive::writeCentralDirectory(std::ofstream& ofs,
                                       const std::vector<ZipArchive::ArchivedFile>& files)
{
    std::streampos offsetCD = ofs.tellp();
    size_t sizeCD = 0;
    bool error = false;
    for (size_t i = 0; i < files.size(); ++i) {
        const ZipFileHeader& fileHeader = files[i].zipFileHader_;
        ofs.write(reinterpret_cast<const char*>(&fileHeader), SIZE_ZIPFILEHEADER);
        sizeCD += SIZE_ZIPFILEHEADER;
        error = ofs.fail();

        size_t stringSize = files[i].fileName_.size();
        sizeCD += stringSize;
        if ((error == false) && (stringSize > 0) && (stringSize == fileHeader.filenameLength)) {
            ofs.write(files[i].fileName_.c_str(), stringSize);
            error = ofs.fail();
        }

        stringSize = files[i].fileExtra_.size();
        sizeCD += stringSize;
        if ((error == false) && (stringSize > 0) && (stringSize == fileHeader.extraFieldLength)) {
            ofs.write(files[i].fileExtra_.c_str(), stringSize);
            error = ofs.fail();
        }

        stringSize = files[i].fileComment_.size();
        sizeCD += stringSize;
        if ((error == false) && (stringSize > 0) && (stringSize == fileHeader.fileCommentLength)) {
            ofs.write(files[i].fileComment_.c_str(), stringSize);
            error = ofs.fail();
        }

        if (error == true) {
            LERROR("writeCentralDirectory(): failed to write Central Directory Entry in zip archive!");
            break;
        }
    }   // for

    ZipEOCDHeaderRecord eocd;
    eocd.signature = SIGNATURE_ZIPEOCDHEADERRECORD;
    eocd.numberOfDisk = 0;
    eocd.numberOfDiskWithStartOfCD = 0;
    eocd.numberOfEntriesInThisCD = static_cast<uint16_t>(files.size());
    eocd.numberOfEntriesInCD = static_cast<uint16_t>(files.size());
    eocd.sizeOfCD = static_cast<uint32_t>(sizeCD);
    eocd.offsetStartCD = (offsetCD >= 0) ? static_cast<uint32_t>(offsetCD) : 0;
    eocd.commmentLength = 0;

    if (error == false) {
        ofs.write(reinterpret_cast<char*>(&eocd), SIZE_ZIPEOCDRECORD);
        error = ofs.fail();
    }

    return (! error);
}
Пример #2
0
void cineon_writer_t::write_pixels( std::ofstream& out, const image::const_image_view_t& view) const
{
    std::vector<boost::uint32_t> buffer( view.width());

    for( int y = 0; y < view.height(); ++y)
    {
		image::const_image_view_t::x_iterator src_it( view.row_begin( y));
	
		for( int x = 0; x < view.width(); ++x)
		{
			boost::uint32_t pix = 0;
	
			float r = boost::gil::get_color( *src_it, boost::gil::red_t());
			float g = boost::gil::get_color( *src_it, boost::gil::green_t());
			float b = boost::gil::get_color( *src_it, boost::gil::blue_t());
	
			boost::uint32_t ri = adobe::clamp( r, 0.0f, 1.0f) * 1023;
			boost::uint32_t gi = adobe::clamp( g, 0.0f, 1.0f) * 1023;
			boost::uint32_t bi = adobe::clamp( b, 0.0f, 1.0f) * 1023;
			pix = ( ri << 22) | ( gi << 12) | ( bi << 2);
	
			buffer[x] = IECore::asBigEndian( pix);
			++src_it;
		}
	
		// write vector
		out.write( reinterpret_cast<char *>( &buffer[0]), view.width() * sizeof( boost::uint32_t));
		
		if ( out.fail())
			throw exception( "error while writting image");
    }
}
Пример #3
0
/*---------------------------------------------------------*/
bool NOMAD::Cache_File_Point::write(std::ofstream &fout) const
{
    // do nothing if no point:
    if (_n <= 0)
        return true;

    // 1. _eval_status:
    fout.write((char *) &_eval_status , sizeof(_eval_status));

    // 2. _n:
    fout.write((char *) &_n           , sizeof(_n));

    // 3. _m:
    fout.write((char *) &_m           , sizeof(_m));

    // 4. _m_def:
    fout.write((char *) &_m_def       , sizeof(_m_def));

    // 5. _coords:
    fout.write((char *)  _coords      , _n*sizeof(double));

    if (_m_def > 0)
    {

        // 6. _bbo_def:
        fout.write((char *)  _bbo_def   , _m_def*sizeof(double));

        // 7. _bbo_index:
        fout.write((char *)  _bbo_index , _m_def*sizeof(int));
    }

    return !fout.fail();
}
Пример #4
0
void openOutputFile(std::ofstream& s, std::string path){
  s.open(path);
  if(s.fail()){
    std::cerr << "Failure opening file \"" << path << "\" for output." << std::endl;
    exit(0);
  }
}
Пример #5
0
bool File::write(std::ofstream& stream)
{
  CwdGuard cg(physical_dir_);
  stream.open(ACE_TEXT_ALWAYS_CHAR(physical_file_.c_str()),
              ios::binary | ios::out);
  return !stream.bad() && !stream.fail();
}
Пример #6
0
bool redirect_cout (const std::string& fn)
{
	static std::ofstream alt_cout;
	alt_cout.open (fn.c_str(), std::ios::out | std::ios::binary);
	if (alt_cout.fail() ) return false;
	std::cout.rdbuf (alt_cout.rdbuf() );
	return true;
}
std::string openFileDialog(std::ofstream& stream,
                           const std::string& title,
                           const std::string& path) {
    std::string filename = pp->file_openFileDialog(title, "save", path);
    if (filename == "") return "";
    stream.open(filename.c_str());
    return (stream.fail()) ? "" : filename;
}
Пример #8
0
int Path::write(std::ofstream &out, std::string &msg)
{
	short record_size;

	record_size = 4;
	writeShort(out, record_size);
	writeByte(out, PATH);
	writeByte(out, NoData);

	record_size = 6;
	writeShort(out, record_size);
	writeByte(out, EFLAGS);
	writeByte(out, Integer_2);
	writeShort(out, Eflags);

	record_size = 6;
	writeShort(out, record_size);
	writeByte(out, LAYER);
	writeByte(out, Integer_2);
	writeShort(out, Layer);

	record_size = 6;
	writeShort(out, record_size);
	writeByte(out, DATATYPE);
	writeByte(out, Integer_2);
	writeShort(out, Data_type);

	record_size = 8;
	writeShort(out, record_size);
	writeByte(out, WIDTH);
	writeByte(out, Integer_4);
	writeInteger(out, Width);

	record_size = 6;
	writeShort(out, record_size);
	writeByte(out, PATHTYPE);
	writeByte(out, Integer_2);
	writeShort(out, Path_type);

    record_size = 4 + short(8 * Pts.size());
	writeShort(out, record_size);
	writeByte(out, XY);
	writeByte(out, Integer_4);
	for (auto p : Pts)
	{
		writeInteger(out, p.x);
		writeInteger(out, p.y);
	}

	record_size = 4;
	writeShort(out, record_size);
	writeByte(out, ENDEL);
	writeByte(out, NoData);

	return out.fail() ? FILE_ERROR : 0;
}
Пример #9
0
void _LogAppenderBase::open()
{
  if (out.is_open())
    {
      return;
    }

  makeLogDir();

  out.open(context.path.c_str(), std::fstream::out | std::fstream::app);
  if (out.fail())
    {
      out.open(context.path.c_str(), std::fstream::out | std::fstream::app);
      if (out.fail())
        {
          throw LOG_ER_OPEN;
        }
    }
}
Пример #10
0
void 
OpenOFile(std::ofstream& fs, const char* filenm)
{
  using namespace std;

  fs.open(filenm, ios::out | ios::trunc);
  if (!fs.is_open() || fs.fail()) {
    DIAG_Throw("Cannot open file '" << filenm << "'");
  }
}
Пример #11
0
int FileManagement::getLogStream(std::ofstream& logStream) {
    log = logFileName + "/" + fname;
    fullPath = log + ".debug";
    logStream.open(log.c_str(), ios::app);
    if (logStream.fail()) {
        return errno;
    } else {
        chmod(log.c_str(), (mode_t) 0644);
        return 0;
    }
}
Пример #12
0
 /*
 * Open an ofstream with fully specified path and mode.
 */
 void
 FileMaster::open(const std::string& name, std::ofstream& out,
                  std::ios_base::openmode mode) const
 {
    out.open(name.c_str(), mode);
    if (out.fail()) {
       std::string message = "Error opening output file. Filename: ";
       message += name;
       UTIL_THROW(message.c_str());
    }
 }
Пример #13
0
/*!
   Save an homography in a file.
   The laod() function allows then to read and set the homography from this file.

   \sa load()
 */
void
vpHomography::save(std::ofstream &f) const
{
  if (! f.fail())
  {
    f << *this ;
  }
  else
  {
    throw(vpException(vpException::ioError, "Cannot write the homography to the output stream")) ;
  }
}
Пример #14
0
 void openStreamInto( Ptr<Config> const& config, std::ofstream& ofs ) {
     // Open output file, if specified
     if( !config->getFilename().empty() ) {
         ofs.open( config->getFilename().c_str() );
         if( ofs.fail() ) {
             std::ostringstream oss;
             oss << "Unable to open file: '" << config->getFilename() << "'";
             throw std::domain_error( oss.str() );
         }
         config->setStreamBuf( ofs.rdbuf() );
     }
 }
Пример #15
0
/*!

  Save the pose vector in the output file stream.

  \param f : Output file stream. Should be open before entering in this method.

  \exception vpException::ioError : If the output stream is not open.

  \sa load()
*/
void
vpPoseVector::save(std::ofstream &f) const
{
  if (! f.fail())
    {
      f << *this ;
    }
  else
    {
      vpERROR_TRACE("\t\t file not open " );
      throw(vpException(vpException::ioError, "\t\t file not open")) ;
    }
}
Пример #16
0
std::string promptUserForFile(std::ofstream &outFile, std::string prompt) {
    while (true) {
        std::cout << prompt;
        std::string fileName;
        getline(std::cin, fileName);
        outFile.open(fileName.c_str());
        if (!outFile.fail()) return fileName;
        outFile.clear();
        std::cout << "Unable to open that file. Try again." << std::endl;
        if (prompt == "") prompt = "Output file: ";
        
    }
}
Пример #17
0
void fstreamWriteBig(std::ofstream &S, char* A, unsigned long long N, std::string fileName, std::string errorID, Parameters *P) {

    struct statvfs statvfsBuf;
    statvfs(fileName.c_str(), &statvfsBuf);
    P->inOut->logMain << "Writing " << N << " bytes into " <<fileName << " ; empty space on disk = " << statvfsBuf.f_bavail * statvfsBuf.f_bsize <<" bytes ..." <<flush;
    
    unsigned long long C=0;
    unsigned long long iC;
    for (iC=0; iC<N/fstream_Chunk_Max; iC++) {
        S.write(A+C,fstream_Chunk_Max);
        C+=fstream_Chunk_Max;
    };
    if (!S.fail()) S.write(A+C,N%fstream_Chunk_Max);
    if (S.fail()) {//failed to write

        struct statvfs statvfsBuf;
        statvfs(fileName.c_str(), &statvfsBuf);
    
//         system(( "ls -lL "+ P->genomeDir + " > "+ P->genomeDir +"/error.info 2>&1").c_str());
//         ifstream error_info((P->genomeDir +"/error.info").c_str());
//         P->inOut->logMain <<error_info.rdbuf();
        
        struct stat statBuf;
        stat(fileName.c_str(), &statBuf);
        
        remove(fileName.c_str());
        
        ostringstream errOut;
        errOut << errorID<<": exiting because of *OUTPUT FILE* error: could not write the output file "<< fileName <<"\n";
        errOut << "fail()=" <<S.fail() <<" ; bad()="<< S.bad()<<"\n";
        errOut << "Error while trying to write chunk # " << iC << "; "<< C << " bytes\n";
        errOut << "File size full = "<< N <<" bytes\n";        
        errOut << "File size on disk = " << statBuf.st_size<<" bytes\n";
        errOut << "Solution: check that you have enough space on the disk\n";
        errOut << "Empty space on disk = " << statvfsBuf.f_bavail * statvfsBuf.f_bsize <<" bytes\n";
        exitWithError(errOut.str(),std::cerr, P->inOut->logMain, EXIT_CODE_FILE_WRITE, *P);
    };
    P->inOut->logMain << " done\n" <<flush;
};
Пример #18
0
    static void createTextFile(const std::string& filepath, std::ofstream& file){
        
#ifdef _WIN32
        // WIN32 will create the wrong file names if we don't first convert them to UTF-16.
        std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
        std::wstring wide_path = converter.from_bytes(filepath);
        file.open(wide_path, std::ios::out | std::ios::trunc);
#else
        file.open(filepath, std::ios::trunc);
#endif

        if (file.fail())
            throw std::ios_base::failure(std::strerror(errno));
    }
Пример #19
0
 void pluginUnload()
 {
     if (notifyFrequency > 0)
     {
         if (writeToFile)
         {
             outFile.flush();
             outFile << std::endl; //now all data are written to file
             if (outFile.fail())
                 std::cerr << "Error on flushing file [" << filename << "]. " << std::endl;
             outFile.close();
         }
     }
 }
Пример #20
0
        void file(const char *f)
        {
            exit();

            if(f)
                out.open(f);

            if(out.fail())
                {
                    std::cerr << "could not open output file '" 
                              << f << "'" << std::endl;
                    ::exit(1);
                }
            s = &out;
            reset();
        }
Пример #21
0
  /// Open the next file with given prefix. If one_file is false,
  /// append _0, _1, etc. to the prefix for actual file name. If
  /// one_file is true, the prefix is the file name. The first time
  /// the file is open in trunc mode, the subsequent times in append
  /// mode.
  void open_next_file(const char *prefix, std::ofstream &out) {
    std::ostringstream name;
    name << prefix;
    std::ios::openmode mode = std::ios::out;
    if(one_file_) {
      mode |= (index_++ ? std::ios::ate : std::ios::trunc);
    } else {
      name << index_++;
      mode |= std::ios::trunc;
    }
    file_names_.push_back(name.str());

    out.open(name.str().c_str());
    if(out.fail())
      eraise(ErrorWriting) << "'" << name.str() << "': "
                           << "Can't open file for writing" << err::no;
  }
Пример #22
0
// writes out the index list;
// 'top' indicates the vertex ordering and should be
// true for a polygon visible from above the PCB
bool VRML_LAYER::WriteIndices( bool aTopFlag, std::ofstream& aOutFile )
{
    if( triplets.empty() )
    {
        error = "WriteIndices(): no triplets (triangular facets) to write";
        return false;
    }

    // go through the triplet list and write out the indices based on order
    std::list<TRIPLET_3D>::const_iterator   tbeg    = triplets.begin();
    std::list<TRIPLET_3D>::const_iterator   tend    = triplets.end();

    int i = 1;

    if( aTopFlag )
        aOutFile << tbeg->i1 << ", " << tbeg->i2 << ", " << tbeg->i3  << ", -1";
    else
        aOutFile << tbeg->i2 << ", " << tbeg->i1 << ", " << tbeg->i3  << ", -1";

    ++tbeg;

    while( tbeg != tend )
    {
        if( (i++ & 7) == 4 )
        {
            i = 1;

            if( aTopFlag )
                aOutFile << ",\n" << tbeg->i1 << ", " << tbeg->i2 << ", " << tbeg->i3  << ", -1";
            else
                aOutFile << ",\n" << tbeg->i2 << ", " << tbeg->i1 << ", " << tbeg->i3  << ", -1";
        }
        else
        {
            if( aTopFlag )
                aOutFile << ", " << tbeg->i1 << ", " << tbeg->i2 << ", " << tbeg->i3  << ", -1";
            else
                aOutFile << ", " << tbeg->i2 << ", " << tbeg->i1 << ", " << tbeg->i3  << ", -1";
        }

        ++tbeg;
    }

    return !aOutFile.fail();
}
void inicializarSharedObjects(CajaRegistradora& caja, Grilla& grilla, GrillaJefe& grillaJefe, Surtidores& surtidores,
		unsigned int cantEmpleados, unsigned int cantSurtidores,
		std::ofstream& archivoColaInputJefe, ColaConPrioridad<automovil>& colaAutosJefe) {
	caja.inicializarCaja();
	grilla.inicializarGrilla(cantEmpleados);
	grillaJefe.inicializarGrillaJefe();
	surtidores.inicializarSurtidores(cantSurtidores);

	if (archivoColaInputJefe.fail() || archivoColaInputJefe.bad()) {
		std::string me = __FILE__ ":inicializarSharedObjects";
		std::string _msg = std::string("Error creando archivo para la cola entre el jefe y el input: ") + std::string(strerror(errno));
		Logger::error(_msg, me);
		throw _msg;
	}
	// TODO: Ordenar la creacion de esta cola. Encapsularlo porque queda feito
	colaAutosJefe = ColaConPrioridad<automovil> ( colaInputJefe, colaInputJefeKey );

}
Пример #24
0
// writes out the vertex list for a planar feature
bool VRML_LAYER::WriteVertices( double aZcoord, std::ofstream& aOutFile, int aPrecision )
{
    if( ordmap.size() < 3 )
    {
        error = "WriteVertices(): not enough vertices";
        return false;
    }

    if( aPrecision < 4 )
        aPrecision = 4;

    int i, j;

    VERTEX_3D* vp = getVertexByIndex( ordmap[0], pholes );

    if( !vp )
        return false;

    std::string strx, stry, strz;
    FormatDoublet( vp->x + offsetX, vp->y + offsetY, aPrecision, strx, stry );
    FormatSinglet( aZcoord, aPrecision, strz );

    aOutFile << strx << " " << stry << " " << strz;

    for( i = 1, j = ordmap.size(); i < j; ++i )
    {
        vp = getVertexByIndex( ordmap[i], pholes );

        if( !vp )
            return false;

        FormatDoublet( vp->x + offsetX, vp->y + offsetY, aPrecision, strx, stry );

        if( i & 1 )
            aOutFile << ", " << strx << " " << stry << " " << strz;
        else
            aOutFile << ",\n" << strx << " " << stry << " " << strz;
    }

    return !aOutFile.fail();
}
Пример #25
0
bool OTASCIIArmor::SaveTo_ofstream(std::ofstream& fout)
{
    String strOutput;
    std::string str_type("DATA"); // -----BEGIN OT ARMORED DATA-----

    if (WriteArmoredString(strOutput, str_type) && strOutput.Exists()) {
        // WRITE IT TO THE FILE
        //
        fout << strOutput;

        if (fout.fail()) {
            otErr << __FUNCTION__ << ": Failed saving to file.\n Contents:\n\n"
                  << strOutput << "\n\n";
            return false;
        }

        return true;
    }

    return false;
}
Пример #26
0
//--- Open an output file.
//
//   Note not under unit test.
//
bool openOutputFile(std::ofstream& fileStream, const char *const fileName, std::ios_base::openmode mode,
  std::string& errStr)
  {
  //
  // Start with a clean slate.
  if( fileStream.is_open() )
    fileStream.close();
  fileStream.clear(std::ios_base::goodbit);
  //
  // Open file.
  fileStream.open(fileName, mode);
  if( fileStream.fail() )
    {
    if( 0 != errStr.size() )
      errStr.push_back('\n');
    errStr.append("Failed to open file '").append(fileName).push_back('\'');
    return( 0 );
    }
  //
  return( 1 );
  }  // End fcn openOutputFile().
std::string promptUserForFile(std::ofstream& stream,
                              const std::string& prompt,
                              const std::string& reprompt) {
    std::string promptCopy = prompt;
    std::string repromptCopy = reprompt;
    if (reprompt == "") {
        repromptCopy = "Unable to open that file.  Try again.";
    }
    appendSpace(promptCopy);
    while (true) {
        std::cout << promptCopy;
        std::string filename;
        getline(std::cin, filename);
        if (!filename.empty()) {
            openFile(stream, filename);
            if (!stream.fail()) return filename;
            stream.clear();
        }
        std::cout << repromptCopy << std::endl;
        if (promptCopy == "") promptCopy = "Output file: ";
    }
}
Пример #28
0
bool OTASCIIArmor::SaveTo_ofstream(std::ofstream & fout)
{
    OTString strOutput;
    std::string str_type("DATA"); // -----BEGIN OT ARMORED DATA-----
    
    if (this->WriteArmoredString(strOutput, str_type) && strOutput.Exists())
    {
        // WRITE IT TO THE FILE
        //
        fout << strOutput.Get();

        if (fout.fail())
        {
            OTLog::vError("%s: Failed saving to file.\n Contents:\n\n%s\n\n",
                          __FUNCTION__, strOutput.Get());
            return false;
        }
        // --------------------------------------------------------------------
        return true;
    }
    // -----------------------
    return false;
}
Пример #29
0
bool IDF3::WriteLayersText( std::ofstream& aBoardFile, IDF3::IDF_LAYER aLayer )
{
    switch( aLayer )
    {
        case LYR_TOP:
            aBoardFile << "TOP";
            break;

        case LYR_BOTTOM:
            aBoardFile << "BOTTOM";
            break;

        case LYR_BOTH:
            aBoardFile << "BOTH";
            break;

        case LYR_INNER:
            aBoardFile << "INNER";
            break;

        case LYR_ALL:
            aBoardFile << "ALL";
            break;

        default:
            do{
                std::ostringstream ostr;
                ostr << "invalid IDF layer: " << aLayer;

                throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
            } while( 0 );

            break;
    }

    return !aBoardFile.fail();
}
Пример #30
0
int parse_args(int argc, char **argv)
{

    int option;
     while ((option = getopt(argc, argv,"l:")) != -1)
    {
      switch (option) {
              case 'l' : 
                   if(logger)
                    logger.close(); 

                   logger.open(optarg, std::ofstream::out | std::ofstream::app);
                   if (logger.fail()) {
                   cerr << "open failure as expected: " << strerror(errno) << '\n';
                   return -1;
                   }

              break;
              default : 
              usage(); 
              return -1; 
             }    
    }
}