TimeWarpFileStream* TimeWarpFileStreamManager::getFileStream(const std::string& filename, std::ios_base::openmode mode, unsigned int local_object_id, std::shared_ptr<Event> this_event) { TimeWarpFileStream* retval; file_streams_lock_[local_object_id].lock(); if (file_stream_by_filename_.count(filename) == 0) { std::unique_ptr<TimeWarpFileStream, FileStreamDeleter> twfs(new TimeWarpFileStream( filename, mode), FileStreamDeleter()); file_stream_by_filename_[filename] = twfs.get(); file_streams_[local_object_id].push_back(std::move(twfs)); retval = file_streams_[local_object_id].back().get(); } else { auto& this_objects_filestreams = file_streams_[local_object_id]; bool is_this_objects = false; auto twfs = file_stream_by_filename_[filename]; for (auto& stream: this_objects_filestreams) { if (stream.get() == twfs) { is_this_objects = true; break; } } if (is_this_objects) { retval = twfs; } else { throw std::runtime_error(std::string( "A filestream can only be used by a single object")); } } retval->setCurrentEvent(this_event); file_streams_lock_[local_object_id].unlock(); return retval; }
void MyWriter::initialize() { m_stream = FileStreamPtr(FileUtils::createFile(m_filename, true), FileStreamDeleter()); if (!m_stream) { std::stringstream out; out << "writers.mywriter couldn't open '" << m_filename << "' for output."; throw pdal_error(out.str()); } }
void MyWriter::processOptions(const Options& options) { m_filename = options.getValueOrThrow<std::string>("filename"); m_stream = FileStreamPtr(FileUtils::createFile(m_filename, true), FileStreamDeleter()); if (!m_stream) { std::stringstream out; out << "writers.mywriter couldn't open '" << m_filename << "' for output."; throw pdal_error(out.str()); } m_newline = options.getValueOrDefault<std::string>("newline", "\n"); m_datafield = options.getValueOrDefault<std::string>("datafield", "UserData"); m_precision = options.getValueOrDefault<int>("precision", 3); }