/* * AsciiWriter.cc * * Created on: 6 août 2013 * Author: CS */ #include #include "AsciiData.hh" #include "AsciiWriter.hh" #include #include "TimeTableCatalogUtil.hh" #include namespace TimeTableCatalog { const std::string AsciiWriter::FORMAT = "ASCII"; AsciiWriter::AsciiWriter(const std::string& pPath, const std::string& pName) : AbstractWriter(pPath, pName) { } AsciiWriter::~AsciiWriter() { } // ----------------- PUBLIC -------------------------- std::string AsciiWriter::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 AsciiWriter::createInstance( const std::string& pPath, const std::string& pName) { return std::unique_ptr < AbstractWriter > (new AsciiWriter(pPath, pName)); } /** * Gets the tt file expected extension, starting with . */ const std::string AsciiWriter::getExtension() const { return ".txt"; } // ----------------- PRIVATE -------------------------- void AsciiWriter::writeMetaData(const TimeTable& pTT, std::ostream& pOut) { // -- write name pOut << "# " << AsciiData::NAME_KEYWORD << " " << pTT._name << ";" << std::endl; // -- write description pOut << "# " << AsciiData::DESCRIPTION_KEYWORD < dataValues = interval.getParameterData (parameterDescription.getId()); for (auto dataValue : dataValues) { pOut << AsciiData::SEPARATOR << dataValue; } } } // skip to next line pOut << std::endl; } } std::string AsciiWriter::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 */