本文整理汇总了C++中BinaryFileStream类的典型用法代码示例。如果您正苦于以下问题:C++ BinaryFileStream类的具体用法?C++ BinaryFileStream怎么用?C++ BinaryFileStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BinaryFileStream类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sizeof
void ImporterSoundWAV::read(BinaryFileStream &infile, DTcharacter id[4])
{
infile.read_raw((DTubyte*)&id[0], sizeof(DTcharacter));
infile.read_raw((DTubyte*)&id[1], sizeof(DTcharacter));
infile.read_raw((DTubyte*)&id[2], sizeof(DTcharacter));
infile.read_raw((DTubyte*)&id[3], sizeof(DTcharacter));
}
示例2: end_export_section
void TWMWriter::end_export_section (BinaryFileStream &file, DTsize size_location)
{
DTsize save_location = file.p();
file.seek_p(size_location, Stream::FROM_BEGINNING);
file << (DTint) (save_location-size_location-sizeof(DTint));
file.seek_p(save_location, Stream::FROM_BEGINNING);
}
示例3: begin_export_section
DTsize TWMWriter::begin_export_section (BinaryFileStream &file, DTint section)
{
file << section;
DTsize size_location = file.p();
file << (DTint) 0;
return size_location;
}
示例4: append_data
void AssetDownloader::append_data (std::string &data, BinaryFileStream &temp_file)
{
// Search for HTTP header
if (_total_size == 0) {
std::size_t header_pos = data.find("\r\n\r\n");
if (header_pos != std::string::npos) {
// Parse the header
std::string header = data.substr(0,header_pos);
std::vector<std::string> header_items = MoreStrings::split(header, "\r\n");
std::map<std::string,std::string> header_items_map;
// Find the content length
for (std::size_t i = 0; i < header_items.size(); ++i) {
std::vector<std::string> header_item = MoreStrings::split(header_items[i],":");
// Validate entry
if (header_item.size() != 2)
continue;
std::string param = MoreStrings::trim(header_item[0]);
std::string value = MoreStrings::trim(header_item[1]);
LOG_MESSAGE << "Header: " << param << " " << value;
header_items_map[param] = value;
}
auto i = header_items_map.find("Content-Length");
if (i != header_items_map.end())
_total_size = MoreStrings::cast_from_string<DTsize>(i->second);
// Strip off header
data = data.substr(header_pos+4);
}
// Append data
}
if (_total_size > 0) {
// Write out data to a file
temp_file.write_raw( (DTubyte*) &(data[0]), data.size());
// Update sizes
_current_size += data.size();
data.clear();
}
// Update progress
update_status (STATUS_DOWNLOADING, _current_size, _total_size);
}
示例5: finalize_data
void AssetDownloader::finalize_data (std::string &data, BinaryFileStream &temp_file)
{
// Write out data to a file
temp_file.write_raw( (DTubyte*) &(data[0]), data.size());
// Update sizes
_current_size += data.size();
data.clear();
// Update progress
update_status (STATUS_DOWNLOADING, _current_size, _total_size);
}
示例6: TestObjectSerialization3
void TestObjectSerialization3()
{
ObjectFactory<Serializable> factory;
//factory.Register("ObjectA", new ObjectCreator<ObjectA, Serializable>());
factory.Register("ObjectD", new ObjectCreator<ObjectD, Serializable>());
ObjectD d = ObjectD();
d.Set(6, 7, 8, "ObjectD baby");
d.AccessA().Set(1, 2, 3, "ObjectA baby");
BinaryFileStream stream;
stream.StartWrite("test3.txt");
d.Save(stream);
stream.SerializeQueue();
stream.Close();
std::vector<Serializable *> load;
stream.StartRead("test3.txt", factory);
ObjectD * loaded = stream.GetNext<ObjectD*>();
stream.Close();
loaded->Print();
delete loaded;
}
示例7: BinaryFileStream
DTerr ImporterFontTTF::import(FontResource *target, std::string args)
{
// Open up the stream for the font file
BinaryFileStream *file = new BinaryFileStream(); // This pointer has to go through a C-API so no shared_ptr
DTerr err = FileManager::open(*file, target->path(), true);
if (err != DT3_ERR_NONE) {
LOG_MESSAGE << "Unable to open font " << target->path().full_path();
delete file;
return DT3_ERR_FILE_OPEN_FAILED;
}
// Send the stream to freetype
FT_Open_Args ftargs;
::memset((void *)&ftargs,0,sizeof(ftargs));
ftargs.flags = FT_OPEN_STREAM;
ftargs.stream=(FT_Stream)malloc(sizeof *(ftargs.stream));
ftargs.stream->base = NULL;
ftargs.stream->size = static_cast<DTuint>(file->length());
ftargs.stream->pos = 0;
ftargs.stream->descriptor.pointer = (void*) (file);
ftargs.stream->pathname.pointer = NULL;
ftargs.stream->read = &ImporterFontTTF::ft_io_func;
ftargs.stream->close = &ImporterFontTTF::ft_close_func;
FT_Error error = ::FT_Open_Face(FontResource::library(),
&ftargs,
0,
&(target->typeface()));
::FT_Select_Charmap(target->typeface(),FT_ENCODING_UNICODE);
return error == 0 ? DT3_ERR_NONE : DT3_ERR_FILE_OPEN_FAILED;
}
示例8: TEST_F
// Tests reading and writing of a single long variant from and to binary files
TEST_F(TestVariant, FileIOBinaryIOMultipleTypes) {
BinaryFileStream stream;
// Values we'll be testing for
long value1 = 123;
std::string value2 = "test";
auto value3 = nullptr;
// Initialize variants
Variant variant1(value1);
Variant variant2(value2);
Variant variant3(value3);
// Open stream for writing
stream.open(filename, std::ios::out);
// Write variants
stream << variant1;
stream << variant2;
stream << variant3;
// Close stream
stream.close();
// Open stream for reading
stream.open(filename, std::ios::in);
// Initialize a final variant for storage of data read from the stream
Variant variant("a value that must not conflict with the tests");
stream >> variant;
EXPECT_EQ(variant, value1);
stream >> variant;
EXPECT_EQ(variant, value2);
stream >> variant;
EXPECT_EQ(variant, value3);
// Lets make sure this was all the data. We need to read again to set the
// EOF bit
char tc;
EXPECT_FALSE(stream.get(tc));
// Ensure EOF
EXPECT_TRUE(stream.eof());
// Close stream
stream.close();
}
示例9: TestObjectSerialization
void TestObjectSerialization()
{
ObjectFactory<Serializable> factory;
factory.Register("ObjectA", new ObjectCreator<ObjectA, Serializable>());
factory.Register("ObjectB", new ObjectCreator<ObjectB, Serializable>());
factory.Register("ObjectC", new ObjectCreator<ObjectC, Serializable>());
factory.Register("STLVectorObjectIO", new ObjectCreator<STLVectorObjectIO<ObjectA>, Serializable>());
ObjectA a = ObjectA();
a.Set(1, 2, 3, "ObjectA baby");
ObjectB b = ObjectB();
b.Set(6, 7, 8, "ObjectB baby");
ObjectC c = ObjectC();
c.Set(3, 4, 5, "ObjectC baby");
b.data4 = &c;
c.data4 = &b;
BinaryFileStream stream;
stream.StartWrite("test.txt");
a.Save(stream);
b.Save(stream);
//c.Save(stream, true);
stream.SerializeQueue();
stream.Close();
std::vector<Serializable *> load;
stream.StartRead("test.txt", factory);
//stream.LoadObjects(factory);
ObjectA * loaded_a = stream.GetNext<ObjectA*>();
ObjectB * loaded_b = stream.GetNext<ObjectB*>();
ObjectC * loaded_c = stream.GetNext<ObjectC*>();
stream.Close();
loaded_a->Print();
loaded_b->Print();
loaded_c->Print();
delete loaded_a;
delete loaded_b;
delete loaded_c;
}
示例10: import
DTerr ImporterImageJPG::import(const FilePath &pathname, const std::string &args, DTuint &width, DTuint &height, std::shared_ptr<DTubyte> &data, DT3GLTextelFormat &format)
{
//
// The following is based on the libpng manual. http://www.libpng.org/pub/png/libpng-1.2.5-manual.html#section-3.1
//
//
// Check the file header
//
// open the file
BinaryFileStream file;
DTerr err;
if ((err = FileManager::open(file, pathname, true)) != DT3_ERR_NONE)
return err;
// This struct contains the JPEG decompression parameters and pointers to
// working space (which is allocated as needed by the JPEG library).
jpeg_decompress_struct cinfo;
ImportSource csrc;
// We use our private extension JPEG error handler.
// Note that this struct must live as long as the main JPEG parameter
// struct, to avoid dangling-pointer problems.
ImportErr jerr;
cinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = ImporterImageJPG::error_handler;
// Establish the setjmp return context for my_error_exit to use.
if (setjmp(jerr.setjmp_buffer)) {
// If we get here, the JPEG code has signaled an error.
// We need to clean up the JPEG object, close the input file, and return.
jpeg_destroy_decompress(&cinfo);
file.close();
return DT3_ERR_FILE_WRONG_TYPE;
}
// Now we can initialize the JPEG decompression object.
jpeg_create_decompress(&cinfo);
cinfo.src = (jpeg_source_mgr*) &csrc;
// Step 2: specify data source (eg, a file)
jpeg_stream_src(&cinfo, file);
// Step 3: read file parameters with jpeg_read_header()
jpeg_read_header(&cinfo, TRUE);
// Step 4: set parameters for decompression
// In this example, we don't need to change any of the defaults set by
// jpeg_read_header(), so we do nothing here.
// Step 5: Start decompressor
jpeg_start_decompress(&cinfo);
ASSERT(cinfo.out_color_components == 3 && cinfo.data_precision == 8);
// Build a buffer for reading in the image
width = cinfo.output_width;
height = cinfo.output_height;
format = DT3GL_FORMAT_RGB;
// Change data format to 16 bit
data = std::shared_ptr<DTubyte>(new DTubyte[width * height * 3]);
DTubyte *buffer = data.get();
DTint row_stride = cinfo.output_width * cinfo.output_components;
// Make a one-row-high sample array that will go away when done with image
JSAMPARRAY scanline_buffer = (*cinfo.mem->alloc_sarray) ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
// Step 6: while (scan lines remain to be read)
// Here we use the library's state variable cinfo.output_scanline as the
// loop counter, so that we don't have to keep track ourselves.
while (cinfo.output_scanline < cinfo.output_height) {
//jpeg_read_scanlines expects an array of pointers to scanlines.
// Here the array is only one element long, but you could ask for
// more than one scanline at a time if that's more convenient.
jpeg_read_scanlines(&cinfo, scanline_buffer, 1);
// Copy Row into buffer
DTubyte *src_data = (DTubyte*) scanline_buffer[0];
DTubyte *dst_data = (DTubyte*) &buffer[width * (height - cinfo.output_scanline) * 3];
// Copy row
::memcpy(dst_data, src_data, row_stride);
}
// Step 7: Finish decompression
jpeg_finish_decompress(&cinfo);
// Step 8: Release JPEG decompression object
// This is an important step since it will release a good deal of memory.
jpeg_destroy_decompress(&cinfo);
//#endif
//.........这里部分代码省略.........
示例11: TestObjectSerialization2
void TestObjectSerialization2()
{
ObjectFactory<Serializable> factory;
factory.Register("ObjectA", new ObjectCreator<ObjectA, Serializable>());
factory.Register("ObjectB", new ObjectCreator<ObjectB, Serializable>());
factory.Register("ObjectC", new ObjectCreator<ObjectC, Serializable>());
factory.Register("STLVectorObjectIO_ObjectA", new ObjectCreator<STLVectorObjectIO<ObjectA>, Serializable>());
factory.Register("STLVectorObjectIO_ObjectB", new ObjectCreator<STLVectorObjectIO<ObjectB>, Serializable>());
factory.Register("STLVectorObjectIO_ObjectC", new ObjectCreator<STLVectorObjectIO<ObjectC>, Serializable>());
factory.Register("STLVectorObjectIO_Serializable", new ObjectCreator<STLVectorObjectIO<Serializable>, Serializable>());
ObjectC a = ObjectC();
a.Set(1, 2, 3, "ObjectA baby");
ObjectC b = ObjectC();
b.Set(4, 5, 6, "ObjectB baby");
ObjectC c = ObjectC();
c.Set(7, 8, 9, "ObjectC baby");
ObjectB d = ObjectB();
d.Set(10, 11, 12, "ObjectD baby");
ObjectB e = ObjectB();
e.Set(13, 14, 15, "ObjectE baby");
ObjectB f = ObjectB();
f.Set(16, 17, 18, "ObjectF baby");
a.data4 = &d;
b.data4 = &e;
c.data4 = &f;
d.data4 = &a;
e.data4 = &b;
f.data4 = &c;
BinaryFileStream stream;
std::vector<ObjectC const *> to_serialize_C;
to_serialize_C.push_back(&a);
to_serialize_C.push_back(&b);
to_serialize_C.push_back(&c);
STLVectorObjectIO<ObjectC> * proxy_C = new STLVectorObjectIO<ObjectC>(&to_serialize_C, "ObjectC");
std::vector<ObjectB const *> to_serialize_B;
to_serialize_B.push_back(&d);
to_serialize_B.push_back(&e);
to_serialize_B.push_back(&f);
STLVectorObjectIO<ObjectB> * proxy_B = new STLVectorObjectIO<ObjectB>(&to_serialize_B, "ObjectB");
std::vector<Serializable *> to_serialize_master;
to_serialize_master.push_back(proxy_C);
to_serialize_master.push_back(proxy_B);
STLVectorObjectIO<Serializable> * proxy_master = new STLVectorObjectIO<Serializable>(&to_serialize_master, "Serializable");
stream.StartWrite("test2.txt");
proxy_master->Save(stream);
stream.SerializeQueue();
stream.Close();
std::vector<Serializable *> load;
stream.StartRead("test2.txt", factory);
STLVectorObjectIO<Serializable> * loaded_vector_proxy_M = stream.GetNext<STLVectorObjectIO<Serializable> *>();
stream.SetEOF();
STLVectorObjectIO<ObjectC> * loaded_vector_proxy_C = loaded_vector_proxy_M->GetAs<STLVectorObjectIO<ObjectC>*>(0);
STLVectorObjectIO<ObjectB> * loaded_vector_proxy_B = loaded_vector_proxy_M->GetAs<STLVectorObjectIO<ObjectB>*>(1);
for(unsigned int i = 0; i < loaded_vector_proxy_C->Size(); ++i)
{
(*loaded_vector_proxy_C)[i]->Print();
}
for(unsigned int i = 0; i < loaded_vector_proxy_B->Size(); ++i)
{
(*loaded_vector_proxy_B)[i]->Print();
}
loaded_vector_proxy_C->DeleteObjects();
loaded_vector_proxy_B->DeleteObjects();
loaded_vector_proxy_M->DeleteObjects();
delete loaded_vector_proxy_M;
}