int main() { #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES char temp[L_tmpnam]; tmpnam(temp); { std::ofstream fso(temp); std::ofstream fs; fs = move(fso); fs << 3.25; } { std::ifstream fs(temp); double x = 0; fs >> x; assert(x == 3.25); } remove(temp); { std::wofstream fso(temp); std::wofstream fs; fs = move(fso); fs << 3.25; } { std::wifstream fs(temp); double x = 0; fs >> x; assert(x == 3.25); } remove(temp); #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES }
int main() { #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES char temp[L_tmpnam]; tmpnam(temp); { std::fstream fso(temp, std::ios_base::in | std::ios_base::out | std::ios_base::trunc); std::fstream fs = move(fso); double x = 0; fs << 3.25; fs.seekg(0); fs >> x; assert(x == 3.25); } std::remove("test.dat"); { std::wfstream fso(temp, std::ios_base::in | std::ios_base::out | std::ios_base::trunc); std::wfstream fs = move(fso); double x = 0; fs << 3.25; fs.seekg(0); fs >> x; assert(x == 3.25); } std::remove(temp); #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES }
std::vector<std::shared_ptr<FileSystemObject>> ArchiveReader::read_base_objects(){ if (!this->version_manifest) this->read_manifest(); zekvok_assert(this->version_manifest); decltype(this->base_objects) ret; ret.reserve(this->version_manifest->archive_metadata.entry_sizes.size()); auto stream = this->get_stream(); stream->seekg(this->base_objects_offset); { boost::iostreams::stream<BoundedInputFilter> bounded(*stream, this->manifest_offset - this->base_objects_offset); std::istream *stream = &bounded; std::shared_ptr<std::istream> crypto; if (this->keypair){ CryptoPP::SecByteBlock key, iv; zekvok_assert(this->get_key_iv(key, iv, KeyIndices::FileObjectDataKey)); crypto = CryptoInputFilter::create(default_crypto_algorithm, *stream, &key, &iv); stream = crypto.get(); } boost::iostreams::stream<LzmaInputFilter> lzma(*stream); for (const auto &s : this->version_manifest->archive_metadata.entry_sizes){ boost::iostreams::stream<BoundedInputFilter> bounded2(lzma, s); ImplementedDeserializerStream ds(bounded2); std::shared_ptr<FileSystemObject> fso(ds.begin_deserialization<FileSystemObject>(config::include_typehashes)); if (!fso) throw ArchiveReadException("Invalid data: Error during FSO deserialization"); ret.push_back(fso); } } this->base_objects = std::move(ret); return this->base_objects; }
void BackupSystem::set_base_objects(){ if (this->base_objects_set) return; this->base_objects_set = true; std::shared_ptr<std::vector<std::wstring>> for_later_check(new std::vector<std::wstring>); FileSystemObject::CreationSettings settings = { this, make_shared(new SimpleErrorReporter), this->make_map(for_later_check) }; for (auto ¤t_source_location : this->get_current_source_locations()){ auto mapped = this->map_forward(current_source_location); std::shared_ptr<FileSystemObject> fso(FileSystemObject::create(mapped, current_source_location, settings)); fso->set_is_main(true); this->base_objects.push_back(fso); } while (for_later_check->size()){ auto old_for_later_check = for_later_check; for_later_check.reset(new std::vector<std::wstring>); settings.backup_mode_map = this->make_map(for_later_check); for (auto &path : *old_for_later_check){ if (this->covered(path)) continue; std::shared_ptr<FileSystemObject> fso( FileSystemObject::create( this->map_forward(path), path, settings ) ); this->base_objects.push_back(fso); } } int i = 0; for (auto &fso : this->base_objects) fso->set_entry_number(i++); this->recalculate_file_guids(); }
int main() { #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES { std::ifstream fso("test.dat"); std::ifstream fs; fs = move(fso); double x = 0; fs >> x; assert(x == 3.25); } { std::wifstream fso("test.dat"); std::wifstream fs; fs = move(fso); double x = 0; fs >> x; assert(x == 3.25); } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES }
int main(int argc, char **argv) { char buffer[MAX_BUFFER_SIZE]; for (int i=1; i< argc; ++i) { std::string filename(argv[i]); std::ifstream fs(filename.c_str(), std::ios::in); if (!fs.good()) { std::cerr << "Unable to open file " << filename << std::endl; return 1; } size_t last_slash = filename.rfind('/'); if (last_slash == std::string::npos) { last_slash = filename.rfind('\\'); if (last_slash == std::string::npos) last_slash = 0; else ++last_slash; } else ++last_slash; std::string outName = filename.substr(last_slash,filename.size()-last_slash); std::stringstream ssi; std::stringstream sso; std::ifstream fsi(outName.c_str(),std::ios::in); if (fsi.good()) { while (!fsi.eof()) { fsi.getline(buffer,MAX_BUFFER_SIZE); if (!fsi.eof()) ssi << buffer << std::endl ; } fsi.close(); } // fist line fs.getline(buffer,MAX_BUFFER_SIZE); char *sub=buffer; while ((*sub=='/') || (*sub==' ')) ++sub; sso << "std::string "<<sub<< " ="; // text of shader unsigned int nbbl=0; while (!fs.eof()) { fs.getline(buffer,MAX_BUFFER_SIZE); //std::cout << buffer << std::endl; if (*buffer!=0) { for (unsigned int i=0; i<nbbl;++i) sso << std::endl <<"\"\\n\""; nbbl=0; sso << std::endl << "\"" << buffer <<"\\n\""; } else nbbl++; }; sso << ";"<< std::endl<< std::endl; std::string ssostr = sso.str(); if (ssostr != ssi.str()) { std::ofstream fso(outName.c_str(),std::ios::out); fso << ssostr; std::cout << "Shader_to_h: "<< outName << " copy"<< std::endl; fso.close(); } else std::cout << "Shader_to_h: "<< outName << " ok"<< std::endl; fs.close(); } return 0; }