当前位置: 首页>>代码示例>>C++>>正文


C++ ostream::fail方法代码示例

本文整理汇总了C++中std::ostream::fail方法的典型用法代码示例。如果您正苦于以下问题:C++ ostream::fail方法的具体用法?C++ ostream::fail怎么用?C++ ostream::fail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::ostream的用法示例。


在下文中一共展示了ostream::fail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: saveToStream

void BmpImageExporter::saveToStream(const ImageRawData& image, std::ostream& os)
{
    if (image.isNull())
        throw Exception("[BmpImageExporter::save] null image given");

    BitmapFileHeader bf; //  bmp fileheader
    BitmapInfoHeader * bfinfo = (BitmapInfoHeader *) image.data();

    // uliss: TODO! check for endianness
    bf.bfType = 0x4d42; // 'BM'
    bf.bfSize = BMP_FILE_HEADER_SIZE + image.dataSize();
    // fileheader + infoheader + palette
    bf.bfOffBits = BMP_FILE_HEADER_SIZE + sizeof(BitmapInfoHeader) + bfinfo->biClrUsed
            * sizeof(RGBQuad);

    os.write((char*) &bf, sizeof(bf));

    if (os.fail())
        throw Exception("[BmpImageExporter::save] failed");

    os << image;

    if (os.fail())
        throw Exception("[BmpImageExporter::save] failed");
}
开发者ID:nctan,项目名称:quneiform,代码行数:25,代码来源:bmpimageexporter.cpp

示例2: SaveFile

void  FeatureFileIO::SaveFile (FeatureVectorList&    _data,
                               const KKStr&          _fileName,
                               FeatureNumListConst&  _selFeatures,
                               std::ostream&         _out,
                               kkuint32&             _numExamplesWritten,
                               VolConstBool&         _cancelFlag,
                               bool&                 _successful,
                               KKStr&                _errorMessage,
                               RunLog&               _log
                              )
{
   _errorMessage = "Driver: '" + this->DriverName () + "' does not implement 'SaveFile' method.";
   _log.Level (-1) << endl
      << "FeatureFileIO::SaveFile    ***ERROR***   " << _errorMessage << endl
      << "     _data.size   : " << _data.size () << endl
      << "     _fileName    : " << _fileName << endl
      << "     _selFeatures : " << _selFeatures.ToCommaDelStr () << endl
      << "     _out.fail    : " << _out.fail () << endl
      << "     _cancelFlag  : " << _cancelFlag << endl
      << endl;
      
  _successful = false;
  _numExamplesWritten = 0;
  return;
}
开发者ID:KurtKramer,项目名称:KSquareLibraries,代码行数:25,代码来源:FeatureFileIO.cpp

示例3: serialize

bool VehicleStateBasicLux::serialize(std::ostream& os) const
{
	const std::istream::pos_type startPos = os.tellp();

	lock();

	ibeo::writeLE(os, m_timestamp);
	ibeo::writeLE(os, m_scanNumber);
	ibeo::writeLE(os, m_errorFlags);
	ibeo::writeLE(os, m_longitudinalVelocity);
	ibeo::writeLE(os, m_steeringWheeAngle);
	ibeo::writeLE(os, m_wheelAngle);
	ibeo::writeLE(os, m_reserved0);

	ibeo::writeLE(os, m_xPos);
	ibeo::writeLE(os, m_yPos);
	ibeo::writeLE(os, m_courseAngle);

	ibeo::writeLE(os, m_timeDiff);
	ibeo::writeLE(os, m_xDiff);
	ibeo::writeLE(os, m_yDiff);
	ibeo::writeLE(os, m_yaw);

	ibeo::writeLE(os, m_reserved1);
	ibeo::writeLE(os, m_currentYawRate);
	ibeo::writeLE(os, m_reserved2);

	unlock();

	return !os.fail() && ((os.tellp() - startPos) == this->getSerializedSize());
}
开发者ID:jannickep,项目名称:snowbots,代码行数:31,代码来源:VehicleStateBasicLux.cpp

示例4: WriteBinaryMaterial

bool WriteBinaryMaterial(const Material& material, std::ostream& stream)
{
    IOUtils::WriteBinaryFloat(material.diffuse.r, stream);
    IOUtils::WriteBinaryFloat(material.diffuse.g, stream);
    IOUtils::WriteBinaryFloat(material.diffuse.b, stream);
    IOUtils::WriteBinaryFloat(material.diffuse.a, stream);

    IOUtils::WriteBinaryFloat(material.ambient.r, stream);
    IOUtils::WriteBinaryFloat(material.ambient.g, stream);
    IOUtils::WriteBinaryFloat(material.ambient.b, stream);
    IOUtils::WriteBinaryFloat(material.ambient.a, stream);

    IOUtils::WriteBinaryFloat(material.specular.r, stream);
    IOUtils::WriteBinaryFloat(material.specular.g, stream);
    IOUtils::WriteBinaryFloat(material.specular.b, stream);
    IOUtils::WriteBinaryFloat(material.specular.a, stream);

    /* emissive.r */  IOUtils::WriteBinaryFloat(0.0f, stream);
    /* emissive.g */  IOUtils::WriteBinaryFloat(0.0f, stream);
    /* emissive.b */  IOUtils::WriteBinaryFloat(0.0f, stream);
    /* emissive.a */  IOUtils::WriteBinaryFloat(0.0f, stream);

    /* power */       IOUtils::WriteBinaryFloat(0.0f, stream);

    return !stream.fail();
}
开发者ID:pol51,项目名称:colobot,代码行数:26,代码来源:modelfile.cpp

示例5: WriteHeader

// ヘッダを書き込む
bool WriteHeader(std::ostream& stream,
  std::uint32_t hash_value, const std::string& architecture) {
  stream.write(reinterpret_cast<const char*>(&kVersion), sizeof(kVersion));
  stream.write(reinterpret_cast<const char*>(&hash_value), sizeof(hash_value));
  const std::uint32_t size = static_cast<std::uint32_t>(architecture.size());
  stream.write(reinterpret_cast<const char*>(&size), sizeof(size));
  stream.write(architecture.data(), size);
  return !stream.fail();
}
开发者ID:ai5,项目名称:YaneuraOu,代码行数:10,代码来源:evaluate_nnue.cpp

示例6: dump

 /**
  * Dump the current status to a stream
  *
  * @param[out] os The output stream where the data is saved
  *
  * @exception std::runtime_error When failed to dump.
  */
 void dump(std::ostream& os) const {
     os.write((char*)&b_, sizeof(b_));
     os.write((char*)&M_[0], sizeof(M_[0]) * M_.size());
     os.write((char*)&c_, sizeof(c_));
     os.write((char*)&p_, sizeof(p_));
     if(os.fail()){
         throw std::runtime_error("Failed to dump");
     }
 }
开发者ID:PowerDNS,项目名称:weakforced,代码行数:16,代码来源:hyperloglog.hpp

示例7: write

bool ReaderWriterGZ::write(std::ostream& fout, const std::string& source) const
{
    int ret, flush = Z_FINISH;
    unsigned have;
    z_stream strm;
    unsigned char out[CHUNK];

    int level = 6;
    int stategy = Z_DEFAULT_STRATEGY; // looks to be the best for .osg/.ive files
    //int stategy = Z_FILTERED;
    //int stategy = Z_HUFFMAN_ONLY;
    //int stategy = Z_RLE;

    /* allocate deflate state */
    strm.zalloc = Z_NULL;
    strm.zfree = Z_NULL;
    strm.opaque = Z_NULL;
    ret = deflateInit2(&strm,
                       level,
                       Z_DEFLATED,
                       15+16, // +16 to use gzip encoding
                       8, // default
                       stategy);
    if (ret != Z_OK)
    return false;

    strm.avail_in = source.size();
    strm.next_in = (Bytef*)(&(*source.begin()));

    /* run deflate() on input until output buffer not full, finish
       compression if all of source has been read in */
    do {
        strm.avail_out = CHUNK;
        strm.next_out = out;
        ret = deflate(&strm, flush);    /* no bad return value */

        if (ret == Z_STREAM_ERROR)
        {
            OSG_NOTICE<<"Z_STREAM_ERROR"<<std::endl;
            return false;
        }

        have = CHUNK - strm.avail_out;

        if (have>0) fout.write((const char*)out, have);

        if (fout.fail())
        {
            (void)deflateEnd(&strm);
            return false;
        }
    } while (strm.avail_out == 0);

    /* clean up and return */
    (void)deflateEnd(&strm);
    return true;
}
开发者ID:151706061,项目名称:OpenSceneGraph,代码行数:57,代码来源:ReaderWriterGZ.cpp

示例8: WriteBinaryModel

bool CModelFile::WriteBinaryModel(std::ostream& stream)
{
    if (m_triangles.size() == 0)
    {
        GetLogger()->Error("Empty model\n");
        return false;
    }

    NewModelHeader header;

    header.version        = 1;
    header.totalTriangles = m_triangles.size();

    IOUtils::WriteBinary<4, int>(header.version, stream);
    IOUtils::WriteBinary<4, int>(header.totalTriangles, stream);

    for (int i = 0; i < static_cast<int>( m_triangles.size() ); ++i)
    {
        NewModelTriangle1 t;

        t.p1 = m_triangles[i].p1;
        t.p2 = m_triangles[i].p2;
        t.p3 = m_triangles[i].p3;
        t.material = m_triangles[i].material;
        t.tex1Name = m_triangles[i].tex1Name;
        t.tex2Name = m_triangles[i].tex2Name;
        t.variableTex2 = m_triangles[i].variableTex2;
        t.state = m_triangles[i].state;

        switch (m_triangles[i].lodLevel)
        {
            case LOD_Constant: t.lodLevel = 0; break;
            case LOD_Low:      t.lodLevel = 1; break;
            case LOD_Medium:   t.lodLevel = 2; break;
            case LOD_High:     t.lodLevel = 3; break;
        }

        WriteBinaryVertexTex2(t.p1, stream);
        WriteBinaryVertexTex2(t.p2, stream);
        WriteBinaryVertexTex2(t.p3, stream);
        WriteBinaryMaterial(t.material, stream);
        IOUtils::WriteBinaryString<1>(t.tex1Name, stream);
        IOUtils::WriteBinaryString<1>(t.tex2Name, stream);
        IOUtils::WriteBinaryBool(t.variableTex2, stream);
        IOUtils::WriteBinary<4, int>(t.lodLevel, stream);
        IOUtils::WriteBinary<4, int>(t.state, stream);

        if (stream.fail())
        {
            GetLogger()->Error("Error writing model file\n");
            return false;
        }
    }

    return true;
}
开发者ID:pol51,项目名称:colobot,代码行数:56,代码来源:modelfile.cpp

示例9: Write

bool Event::Write(std::ostream & o) const
{
    if(o.fail()) return false;

    o.write(reinterpret_cast<const char*>(pack), sp);
    o.write(&status, 1);
    if(size) o.write(reinterpret_cast<const char*>(data), size);

    return true;
}
开发者ID:asimonov-im,项目名称:fheroes2,代码行数:10,代码来源:midi_event.cpp

示例10: cmnDataSerializeBinary_size_t

void cmnDataSerializeBinary_size_t(const size_t & data,
                                   std::ostream & outputStream)
    throw (std::runtime_error)
{
    outputStream.write(reinterpret_cast<const char *>(&data),
                       sizeof(size_t));
    if (outputStream.fail()) {
        cmnThrow("cmnDataSerializeBinary(type): error occured with std::ostream::write");
    }
}
开发者ID:Shuyoung,项目名称:cisst,代码行数:10,代码来源:cmnDataFunctions.cpp

示例11: cmnDataSerializeText_size_t

void cmnDataSerializeText_size_t(const size_t & data,
                                 std::ostream & outputStream,
                                 const char CMN_UNUSED(delimiter))
    throw (std::runtime_error)
{
    outputStream << data;
    if (outputStream.fail()) {
        cmnThrow("cmnDataSerializeText_size_t: error occured with std::ostream::write");
    }
}
开发者ID:Shuyoung,项目名称:cisst,代码行数:10,代码来源:cmnDataFunctions.cpp

示例12: WriteTextVertexTex2

bool WriteTextVertexTex2(const VertexTex2& vertex, std::ostream& stream)
{
    stream << "c " << vertex.coord.x << " " << vertex.coord.y << " " << vertex.coord.z;
    stream << " n " << vertex.normal.x << " " << vertex.normal.y << " " << vertex.normal.z;
    stream << " t1 " << vertex.texCoord.x << " " << vertex.texCoord.y;
    stream << " t2 " << vertex.texCoord2.x << " " << vertex.texCoord2.y;
    stream << std::endl;

    return !stream.fail();
}
开发者ID:pol51,项目名称:colobot,代码行数:10,代码来源:modelfile.cpp

示例13: cmnDataSerializeBinary

void cmnDataSerializeBinary(const std::string & data,
                            std::ostream & outputStream)
    throw (std::runtime_error)
{
    cmnData<size_t>::SerializeBinary(data.size(), outputStream);
    outputStream.write(data.data(), data.size());
    if (outputStream.fail()) {
        cmnThrow("cmnDataSerializeBinary(std::string): error occured with std::ostream::write");
    }
}
开发者ID:Shuyoung,项目名称:cisst,代码行数:10,代码来源:cmnDataFunctionsString.cpp

示例14: sizeof

bool S3D::WritePoint( std::ostream& aFile, const SGPOINT& aPoint )
{
    aFile.write( (char*)&aPoint.x, sizeof(aPoint.x) );
    aFile.write( (char*)&aPoint.y, sizeof(aPoint.y) );
    aFile.write( (char*)&aPoint.z, sizeof(aPoint.z) );

    if( aFile.fail() )
        return false;

    return true;
}
开发者ID:KiCad,项目名称:kicad-source-mirror,代码行数:11,代码来源:sg_helpers.cpp

示例15: writeImage

 virtual WriteResult writeImage(const Image& image,std::ostream& fout, const osgDB::ReaderWriter::Options* options) const
 {
     ive::DataOutputStream out(&fout, options);
     out.writeImage(ive::IMAGE_INCLUDE_DATA, const_cast<osg::Image*>(&image));
     if (fout.fail()) return WriteResult::ERROR_IN_WRITING_FILE;
     if (out.getException())
     {
         OSG_WARN<<"Error writing IVE image: "<< out.getException()->getError() << std::endl;
         return WriteResult::FILE_NOT_HANDLED;
     }
     return WriteResult::FILE_SAVED;
 }
开发者ID:Kurdakov,项目名称:emscripten_OSG,代码行数:12,代码来源:ReaderWriterIVE.cpp


注:本文中的std::ostream::fail方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。