/* * Souffle - A Datalog Compiler * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved * Licensed under the Universal Permissive License v 1.0 as shown at: * - https://opensource.org/licenses/UPL * - /licenses/SOUFFLE-UPL.txt */ /************************************************************************ * * @file IOSystem.h * ***********************************************************************/ #pragma once #include "RamTypes.h" #include "ReadStream.h" #include "ReadStreamCSV.h" #include "ReadStreamJSON.h" #include "SymbolTable.h" #include "WriteStream.h" #include "WriteStreamCSV.h" #include "WriteStreamJSON.h" #ifdef USE_SQLITE #include "ReadStreamSQLite.h" #include "WriteStreamSQLite.h" #endif #include #include #include #include namespace souffle { class RecordTable; class IOSystem { public: static IOSystem& getInstance() { static IOSystem singleton; return singleton; } void registerWriteStreamFactory(const std::shared_ptr& factory) { outputFactories[factory->getName()] = factory; } void registerReadStreamFactory(const std::shared_ptr& factory) { inputFactories[factory->getName()] = factory; } /** * Return a new WriteStream */ std::unique_ptr getWriter(const std::map& rwOperation, const SymbolTable& symbolTable, const RecordTable& recordTable) const { std::string ioType = rwOperation.at("IO"); if (outputFactories.count(ioType) == 0) { throw std::invalid_argument("Requested output type <" + ioType + "> is not supported."); } return outputFactories.at(ioType)->getWriter(rwOperation, symbolTable, recordTable); } /** * Return a new ReadStream */ std::unique_ptr getReader(const std::map& rwOperation, SymbolTable& symbolTable, RecordTable& recordTable) const { std::string ioType = rwOperation.at("IO"); if (inputFactories.count(ioType) == 0) { throw std::invalid_argument("Requested input type <" + ioType + "> is not supported."); } return inputFactories.at(ioType)->getReader(rwOperation, symbolTable, recordTable); } ~IOSystem() = default; private: IOSystem() { registerReadStreamFactory(std::make_shared()); registerReadStreamFactory(std::make_shared()); registerReadStreamFactory(std::make_shared()); registerReadStreamFactory(std::make_shared()); registerWriteStreamFactory(std::make_shared()); registerWriteStreamFactory(std::make_shared()); registerWriteStreamFactory(std::make_shared()); registerWriteStreamFactory(std::make_shared()); registerWriteStreamFactory(std::make_shared()); #ifdef USE_SQLITE registerReadStreamFactory(std::make_shared()); registerWriteStreamFactory(std::make_shared()); #endif }; std::map> outputFactories; std::map> inputFactories; }; } /* namespace souffle */