void MultipleAvroFileWriter::commit() { RMF_TRACE("Writing frame " << frame_.index); for (unsigned int i = 0; i < categories_.size(); ++i) { if (categories_[i].dirty) { if (!categories_[i].writer) { std::string name = get_category_dynamic_file_path(Category(i)); try { categories_[i].writer.reset( new internal_avro::DataFileWriter<RMF_avro_backend::Data>( name.c_str(), internal_avro::compileJsonSchemaFromString( data_deprecated_avro::data_json))); } catch (const std::exception& e) { RMF_THROW(Message(e.what()) << Component(name), IOException); } } // show(categories_[i].data); RMF_INTERNAL_CHECK(categories_[i].data.frame == frame_.index, "Trying to write category that is at wrong frame."); categories_[i].writer->write(categories_[i].data); categories_[i].writer->flush(); } categories_[i].data = RMF_avro_backend::Data(); // go to the about to be added frame categories_[i].data.frame = frame_.index + 1; } for (unsigned int i = 0; i < static_categories_.size(); ++i) { if (static_categories_dirty_[i]) { std::string name = get_category_static_file_path(Category(i)); try { internal_avro::DataFileWriter<RMF_avro_backend::Data> writer( name.c_str(), internal_avro::compileJsonSchemaFromString( data_deprecated_avro::data_json)); writer.write(static_categories_[i]); writer.flush(); } catch (const std::exception& e) { RMF_THROW(Message(e.what()) << Component(name), IOException); } // std::cout << "Writing data for " << get_category_name(Category(i)) << // std::endl; // show(static_categories_[i]); static_categories_dirty_[i] = false; } } RMF_COMMIT(File, file); RMF_COMMIT(Nodes, nodes); if (frames_dirty_) { if (!frame_writer_) { frame_writer_.reset( new internal_avro::DataFileWriter<RMF_avro_backend::Frame>( get_frames_file_path().c_str(), internal_avro::compileJsonSchemaFromString( data_deprecated_avro::frame_json))); } frame_writer_->write(frame_); frames_dirty_ = false; } }
MultipleAvroFileWriter::MultipleAvroFileWriter(std::string path, bool create, bool read_only) : MultipleAvroFileBase(path) { RMF_INTERNAL_CHECK(create, "Can only create files"); RMF_INTERNAL_CHECK(!read_only, "Can only create files"); RMF_UNUSED(create); RMF_UNUSED(read_only); boost::filesystem::remove_all(path); boost::filesystem::create_directory(path); frame_.index = -1; frame_.name = "static"; frame_.type = "static"; file_.version = 2; file_dirty_ = true; frames_dirty_ = true; nodes_dirty_ = true; }
int SingleAvroFile::add_child_frame(int node, std::string name, int t) { unsigned int index = get_number_of_frames(); access_frame(index).name = name; access_frame(index).type = boost::lexical_cast<std::string>(FrameType(t)); access_frame(node).children.push_back(index); RMF_INTERNAL_CHECK(get_number_of_frames() == index + 1, "No frame added"); return index; }
FrameHandle FrameHandle::add_child(std::string name, FrameType t) { FrameHandle ret(get_shared_data()->add_child_frame(get_frame_id(), name, t), get_shared_data()); ret.set_as_current_frame(); RMF_INTERNAL_CHECK(get_shared_data()->get_number_of_frames() == static_cast<unsigned int>(ret.get_id().get_index() + 1), "Wrong number of frames"); return ret; }