void main2() { Person person; person.Name = "Bob"; person.Age = 28; person.Educations.push_back(Education("MIT", 600)); string_stream ss; save_to(ss, person); std::cout << ss.str() << std::endl; }
void recording_t::save(void) { int fd = open("recording", O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd < 0) { perror("save: open:"); return; } save_to(fd); close(fd); }
bool Drumkit::save_file( const QString& dk_path, bool overwrite ) { INFOLOG( QString( "Saving drumkit definition into %1" ).arg( dk_path ) ); if( Filesystem::file_exists( dk_path, true ) && !overwrite ) { ERRORLOG( QString( "drumkit %1 already exists" ).arg( dk_path ) ); return false; } XMLDoc doc; doc.set_root( "drumkit_info", "drumkit" ); XMLNode root = doc.firstChildElement( "drumkit_info" ); save_to( &root ); return doc.write( dk_path ); }
bool Pattern::save_file( const QString& drumkit_name, const QString& author, const QString& license, const QString& pattern_path, bool overwrite ) const { INFOLOG( QString( "Saving pattern into %1" ).arg( pattern_path ) ); if( !overwrite && Filesystem::file_exists( pattern_path, true ) ) { ERRORLOG( QString( "pattern %1 already exists" ).arg( pattern_path ) ); return false; } XMLDoc doc; XMLNode root = doc.set_root( "drumkit_pattern", "drumkit_pattern" ); root.write_string( "drumkit_name", drumkit_name ); // FIXME loaded with LocalFileMng::getDrumkitNameForPattern(…) root.write_string( "author", author ); // FIXME this is never loaded back root.write_string( "license", license ); // FIXME this is never loaded back save_to( &root ); return doc.write( pattern_path ); }
// construct the classifier Classifier::Classifier(const ClassifierOptions &options ) { kmerSize_ = options.kmerSize; numThreads_ = options.numThreads; numBootstrap_ = options.numBootstrap; subsampleSize_ = options.subsample; kmerizer_.setKmerSize(kmerSize_); outputAmbiguous_ = options.dumpAmbiguous; std::stringstream s; s << options.dbFilename << ".idx_" << kmerSize_; try { // load cached index std::ifstream ifs(s.str().c_str()); boost::archive::binary_iarchive ia(ifs); ScopedTimer tim; std::cerr << "Loading cached index from " << s.str(); ia >> referenceData_; std::cerr << " done. "; } catch (boost::archive::archive_exception &) { // create index from raw sequences referenceData_.load(options.dbFilename, kmerizer_, numThreads_); // save index for future use if (options.saveIndex) { std::ofstream ofs(s.str().c_str()); boost::archive::binary_oarchive oa(ofs); ScopedTimer tim; std::cerr << "Writing cached index to " << s.str(); save_to(oa, referenceData_); std::cerr << " done. "; } } numRefSeqs_ = referenceData_.numSequences(); }
// 将rawdata截取部分数据到learndata中 void create_learn_data(const char* raw_data_folder, const char* out_data_folder, const int how_many /* = 5000 */) { assert(raw_data_folder); assert(out_data_folder); auto files = Utils::getFiles(raw_data_folder); size_t size = files.size(); if (0 == size) { std::cout << "No file found in " << raw_data_folder << std::endl; return; } // 随机排列rawdata srand(unsigned(time(NULL))); std::random_shuffle(files.begin(), files.end()); int count = 0; for (auto f : files) { // 选取前how_many个rawdata数据作为learndata if (count++ >= how_many) { break; } //读取数据,并对图片进行预处理 cv::Mat img = cv::imread(f); img = cut_top_bottom(img); std::string save_to(out_data_folder); if (*(save_to.end() - 1) != '/') { save_to.push_back('/'); } save_to.append(Utils::getFileName(f, true)); utils::imwrite(save_to, img); std::cout << f << " -> " << save_to << std::endl; } std::cout << "Learn data created successfully!" << std::endl; }
void KVConfig::save_as(const char *filename) { save_to(filename); }
void KVConfig::save() { std::string sess_fname = filename_ + ".session"; save_to(sess_fname.c_str()); }