Revision cfdc7053f2bba3965c665328fc1d014f44cab16b authored by Lonca Emmanuel on 17 March 2021, 12:16:06 UTC, committed by Lonca Emmanuel on 17 March 2021, 12:16:06 UTC
1 parent 76983f8
ParserFactory.h
#ifndef __PARSER_FACTORY_H__
#define __PARSER_FACTORY_H__
#include <memory>
#include "IParser.h"
#include "AspartixFormatParser.h"
#include "CNFFormatParser.h"
#include "TrivialGraphFormatParser.h"
namespace CoQuiAAS {
/**
* \class ParserFactory
* \brief Class used to get a parser instance and that provides static methods related to instance formats
*/
class ParserFactory {
public:
/**
* \fn getInstanceFormat
* \brief return an InstanceFormat object corresponding to the string passed in parameter
* \param str : the string that may be related to an InstanceFormat object
* \return an InstanceFormat object corresponding to the string passed in parameter ; FORMAT_UNDEFINED is returned in case the string is not recognized
*/
static InstanceFormat getInstanceFormat(string str) {
if(!str.compare("tgf")) return FORMAT_TRIVIAL_GRAPH;
if(!str.compare("apx")) return FORMAT_ASPARTIX;
if(!str.compare("cnf")) return FORMAT_CNF;
return FORMAT_UNDEFINED;
}
/**
* \fn getParserInstance
* \brief return a parser object given an InstanceFormat object and a file
* \param format : the instance format
* \param file : a stream opened with read rights where pointer is at the beginning of the instance file
* \return an InstanceFormat object corresponding to the string passed in parameter ; FORMAT_UNDEFINED is returned in case the string is not recognized
*/
static std::unique_ptr<IParser> getParserInstance(InstanceFormat format, istream *file) {
switch(format) {
case FORMAT_ASPARTIX:
return std::unique_ptr<IParser>(new AspartixFormatParser(file));
case FORMAT_CNF:
return std::unique_ptr<IParser>(new CNFFormatParser(file));
case FORMAT_TRIVIAL_GRAPH:
return std::unique_ptr<IParser>(new TrivialGraphFormatParser(file));
default:
return nullptr;
}
}
};
}
#endif
Computing file changes ...