/* * SpaceWriter.cc * * Created on: 31/05/2021 * Author: akka */ #include #include "SpaceData.hh" #include "SpaceWriter.hh" #include #include "TimeTableCatalogUtil.hh" #include namespace TimeTableCatalog { const std::string SpaceWriter::FORMAT = "SPACE"; SpaceWriter::SpaceWriter(const std::string& pPath, const std::string& pName) : AbstractWriter(pPath, pName) { } SpaceWriter::~SpaceWriter() { } // ----------------- PUBLIC -------------------------- std::string SpaceWriter::write(const TimeTable& pTT) { LOG4CXX_DEBUG(logger, "Opening file " << getFile(pTT)); std::ofstream ttfile(getFile(pTT), std::ios::out); // -- open file if (ttfile) { LOG4CXX_DEBUG(logger, "Writing metadata"); writeMetaData(pTT, ttfile); LOG4CXX_DEBUG(logger, "Writing intervals"); writeIntervals(pTT, ttfile); } LOG4CXX_DEBUG(logger, "End Of writing"); // -- close file ttfile.close(); return getFile(pTT); } /** * Creates an instance of this. */ std::unique_ptr SpaceWriter::createInstance( const std::string& pPath, const std::string& pName) { return std::unique_ptr < AbstractWriter > (new SpaceWriter(pPath, pName)); } /** * Gets the tt file expected extension, starting with . */ const std::string SpaceWriter::getExtension() const { return ".txt"; } // ----------------- PRIVATE -------------------------- void SpaceWriter::writeMetaData(const TimeTable& pTT, std::ostream& pOut) { // write version pOut << "# " < dataValues = interval.getParameterData (parameterDescription.getId()); for (auto dataValue : dataValues) { pOut << SpaceData::SEPARATOR << dataValue; } } } // skip to next line pOut << std::endl; } } std::string SpaceWriter::getTypeAsString(ParameterDescription::ParameterType type) { switch (type) { case ParameterDescription::ParameterType::Unknown: return "string"; case ParameterDescription::ParameterType::Double: return "double"; case ParameterDescription::ParameterType::Date: return "date"; case ParameterDescription::ParameterType::String: return "string"; case ParameterDescription::ParameterType::Integer: return "integer"; } return "string"; } } /* namespace TimeTableCatalog */