Merge branch 'develop' of github.com:potassco/plasp into normalization
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#ifndef __PLASP__LANGUAGE_H
|
||||
#define __PLASP__LANGUAGE_H
|
||||
|
||||
#include <plasp/utils/Parser.h>
|
||||
#include <string>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -18,6 +18,7 @@ class Language
|
||||
enum class Type
|
||||
{
|
||||
Unknown,
|
||||
Automatic,
|
||||
PDDL,
|
||||
SAS
|
||||
};
|
||||
|
@@ -2,7 +2,7 @@
|
||||
#define __PLASP__LANGUAGE_DETECTION_H
|
||||
|
||||
#include <plasp/Language.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
#include <plasp/input/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -13,7 +13,7 @@ namespace plasp
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Language::Type detectLanguage(utils::Parser<utils::CaseInsensitiveParserPolicy> &parser)
|
||||
Language::Type detectLanguage(input::Parser<input::CaseInsensitiveParserPolicy> &parser)
|
||||
{
|
||||
parser.skipWhiteSpace();
|
||||
|
||||
|
@@ -1,24 +1,29 @@
|
||||
#ifndef __PLASP__UTILS__STREAM_COORDINATE_H
|
||||
#define __PLASP__UTILS__STREAM_COORDINATE_H
|
||||
#ifndef __PLASP__INPUT__LOCATION_H
|
||||
#define __PLASP__INPUT__LOCATION_H
|
||||
|
||||
#include <string>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace utils
|
||||
namespace input
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// StreamCoordinate
|
||||
// Location
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct StreamCoordinate
|
||||
struct Location
|
||||
{
|
||||
std::string sectionName;
|
||||
size_t row;
|
||||
size_t column;
|
||||
const char *sectionStart = nullptr;
|
||||
const char *sectionEnd = nullptr;
|
||||
|
||||
std::size_t rowStart = -1;
|
||||
std::size_t rowEnd = -1;
|
||||
|
||||
std::size_t columnStart = -1;
|
||||
std::size_t columnEnd = -1;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
@@ -1,5 +1,5 @@
|
||||
#ifndef __PLASP__UTILS__PARSER_H
|
||||
#define __PLASP__UTILS__PARSER_H
|
||||
#ifndef __PLASP__INPUT__PARSER_H
|
||||
#define __PLASP__INPUT__PARSER_H
|
||||
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
@@ -8,14 +8,13 @@
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <plasp/utils/ParserException.h>
|
||||
#include <plasp/utils/ParserPolicy.h>
|
||||
#include <plasp/utils/Stream.h>
|
||||
#include <plasp/utils/StreamCoordinate.h>
|
||||
#include <plasp/input/ParserException.h>
|
||||
#include <plasp/input/ParserPolicy.h>
|
||||
#include <plasp/input/Stream.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace utils
|
||||
namespace input
|
||||
{
|
||||
|
||||
template<typename Type>
|
||||
@@ -199,7 +198,7 @@ void Parser<ParserPolicy>::expect(const Type &expectedValue)
|
||||
std::stringstream message;
|
||||
message << "unexpected value, expected “" << expectedValue << "”";
|
||||
|
||||
throw ParserException(coordinate(), message.str());
|
||||
throw ParserException(location(), message.str());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -402,7 +401,7 @@ uint64_t Parser<ParserPolicy>::parseIntegerBody()
|
||||
check();
|
||||
|
||||
if (!std::isdigit(currentCharacter()))
|
||||
throw ParserException(coordinate(), "could not parse integer value");
|
||||
throw ParserException(location(), "could not parse integer value");
|
||||
|
||||
uint64_t value = 0;
|
||||
|
||||
@@ -444,7 +443,7 @@ uint64_t Parser<ParserPolicy>::parseImpl(Tag<uint64_t>)
|
||||
skipWhiteSpace();
|
||||
|
||||
if (currentCharacter() == '-')
|
||||
throw ParserException(coordinate(), "expected unsigned integer, got signed one");
|
||||
throw ParserException(location(), "expected unsigned integer, got signed one");
|
||||
|
||||
return parseIntegerBody();
|
||||
}
|
||||
@@ -478,7 +477,7 @@ bool Parser<ParserPolicy>::parseImpl(Tag<bool>)
|
||||
if (testAndSkip<char>('1'))
|
||||
return true;
|
||||
|
||||
throw ParserException(coordinate(), "could not parse Boolean value");
|
||||
throw ParserException(location(), "could not parse Boolean value");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
72
include/plasp/input/ParserException.h
Normal file
72
include/plasp/input/ParserException.h
Normal file
@@ -0,0 +1,72 @@
|
||||
#ifndef __PLASP__INPUT__PARSER_EXCEPTION_H
|
||||
#define __PLASP__INPUT__PARSER_EXCEPTION_H
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
#include <plasp/input/Location.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace input
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// ParserException
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ParserException: public std::exception
|
||||
{
|
||||
public:
|
||||
explicit ParserException(const input::Location &location)
|
||||
: ParserException(location, "unspecified parser error")
|
||||
{
|
||||
}
|
||||
|
||||
explicit ParserException(const input::Location &location, const char *message)
|
||||
: ParserException(location, static_cast<std::string>(message))
|
||||
{
|
||||
}
|
||||
|
||||
explicit ParserException(const input::Location &location, const std::string &message)
|
||||
: m_location{location},
|
||||
m_message{message},
|
||||
// TODO: refactor
|
||||
m_plainMessage{std::string(m_location.sectionStart) + ":" + std::to_string(m_location.rowStart)
|
||||
+ ":" + std::to_string(m_location.columnStart) + " " + m_message}
|
||||
{
|
||||
}
|
||||
|
||||
~ParserException() throw()
|
||||
{
|
||||
}
|
||||
|
||||
const char *what() const throw()
|
||||
{
|
||||
return m_plainMessage.c_str();
|
||||
}
|
||||
|
||||
const input::Location &location() const
|
||||
{
|
||||
return m_location;
|
||||
}
|
||||
|
||||
const std::string &message() const
|
||||
{
|
||||
return m_message;
|
||||
}
|
||||
|
||||
private:
|
||||
input::Location m_location;
|
||||
std::string m_message;
|
||||
std::string m_plainMessage;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,11 +1,11 @@
|
||||
#ifndef __PLASP__UTILS__PARSER_POLICY_H
|
||||
#define __PLASP__UTILS__PARSER_POLICY_H
|
||||
#ifndef __PLASP__INPUT__PARSER_POLICY_H
|
||||
#define __PLASP__INPUT__PARSER_POLICY_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace utils
|
||||
namespace input
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
@@ -1,5 +1,5 @@
|
||||
#ifndef __PLASP__UTILS__STREAM_H
|
||||
#define __PLASP__UTILS__STREAM_H
|
||||
#ifndef __PLASP__INPUT__STREAM_H
|
||||
#define __PLASP__INPUT__STREAM_H
|
||||
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
@@ -8,12 +8,11 @@
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <plasp/utils/ParserException.h>
|
||||
#include <plasp/utils/StreamCoordinate.h>
|
||||
#include <plasp/input/Location.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace utils
|
||||
namespace input
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -62,7 +61,7 @@ class Stream
|
||||
void reset();
|
||||
void seek(Position position);
|
||||
Position position() const;
|
||||
StreamCoordinate coordinate() const;
|
||||
Location location() const;
|
||||
|
||||
char currentCharacter() const;
|
||||
void advance();
|
294
include/plasp/output/ColorStream.h
Normal file
294
include/plasp/output/ColorStream.h
Normal file
@@ -0,0 +1,294 @@
|
||||
#ifndef __PLASP__OUTPUT__COLOR_STREAM_H
|
||||
#define __PLASP__OUTPUT__COLOR_STREAM_H
|
||||
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// ColorStream
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ColorStream
|
||||
{
|
||||
public:
|
||||
enum class ColorPolicy
|
||||
{
|
||||
Never,
|
||||
Auto,
|
||||
Always
|
||||
};
|
||||
|
||||
private:
|
||||
using CharacterType = std::ostream::char_type;
|
||||
using TraitsType = std::ostream::traits_type;
|
||||
|
||||
public:
|
||||
ColorStream(std::ostream &stream)
|
||||
: m_stream{stream},
|
||||
m_colorPolicy{ColorPolicy::Auto}
|
||||
{
|
||||
}
|
||||
|
||||
void setColorPolicy(ColorPolicy colorPolicy)
|
||||
{
|
||||
m_colorPolicy = colorPolicy;
|
||||
}
|
||||
|
||||
bool supportsColor() const
|
||||
{
|
||||
if (m_colorPolicy == ColorPolicy::Never)
|
||||
return false;
|
||||
|
||||
if (m_colorPolicy == ColorPolicy::Always)
|
||||
return true;
|
||||
|
||||
if (&m_stream == &std::cout)
|
||||
return isatty(fileno(stdout));
|
||||
|
||||
if (&m_stream == &std::cerr)
|
||||
return isatty(fileno(stderr));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::ostream &stream()
|
||||
{
|
||||
return m_stream;
|
||||
}
|
||||
|
||||
inline ColorStream &operator<<(short value);
|
||||
inline ColorStream &operator<<(unsigned short value);
|
||||
inline ColorStream &operator<<(int value);
|
||||
inline ColorStream &operator<<(unsigned int value);
|
||||
inline ColorStream &operator<<(long value);
|
||||
inline ColorStream &operator<<(unsigned long value);
|
||||
inline ColorStream &operator<<(long long value);
|
||||
inline ColorStream &operator<<(unsigned long long value);
|
||||
inline ColorStream &operator<<(float value);
|
||||
inline ColorStream &operator<<(double value);
|
||||
inline ColorStream &operator<<(long double value);
|
||||
inline ColorStream &operator<<(bool value);
|
||||
inline ColorStream &operator<<(const void *value);
|
||||
inline ColorStream &operator<<(const char *value);
|
||||
inline ColorStream &operator<<(const signed char *value);
|
||||
inline ColorStream &operator<<(const unsigned char *value);
|
||||
inline ColorStream &operator<<(std::basic_streambuf<CharacterType, TraitsType> *sb);
|
||||
inline ColorStream &operator<<(std::ios_base &(*func)(std::ios_base &));
|
||||
inline ColorStream &operator<<(std::basic_ios<CharacterType, TraitsType> &(*func)(std::basic_ios<CharacterType, TraitsType> &));
|
||||
inline ColorStream &operator<<(std::basic_ostream<CharacterType, TraitsType> &(*func)(std::basic_ostream<CharacterType, TraitsType> &));
|
||||
|
||||
inline ColorStream &operator<<(char value);
|
||||
inline ColorStream &operator<<(signed char value);
|
||||
inline ColorStream &operator<<(unsigned char value);
|
||||
|
||||
private:
|
||||
std::ostream &m_stream;
|
||||
ColorPolicy m_colorPolicy;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ColorStream &ColorStream::operator<<(short value)
|
||||
{
|
||||
m_stream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ColorStream &ColorStream::operator<<(unsigned short value)
|
||||
{
|
||||
m_stream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ColorStream &ColorStream::operator<<(int value)
|
||||
{
|
||||
m_stream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ColorStream &ColorStream::operator<<(unsigned int value)
|
||||
{
|
||||
m_stream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ColorStream &ColorStream::operator<<(long value)
|
||||
{
|
||||
m_stream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ColorStream &ColorStream::operator<<(unsigned long value)
|
||||
{
|
||||
m_stream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ColorStream &ColorStream::operator<<(long long value)
|
||||
{
|
||||
m_stream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ColorStream &ColorStream::operator<<(unsigned long long value)
|
||||
{
|
||||
m_stream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ColorStream &ColorStream::operator<<(float value)
|
||||
{
|
||||
m_stream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ColorStream &ColorStream::operator<<(double value)
|
||||
{
|
||||
m_stream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ColorStream &ColorStream::operator<<(long double value)
|
||||
{
|
||||
m_stream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ColorStream &ColorStream::operator<<(bool value)
|
||||
{
|
||||
m_stream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ColorStream &ColorStream::operator<<(const void *value)
|
||||
{
|
||||
m_stream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ColorStream &ColorStream::operator<<(const char *value)
|
||||
{
|
||||
m_stream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ColorStream &ColorStream::operator<<(const signed char *value)
|
||||
{
|
||||
m_stream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ColorStream &ColorStream::operator<<(const unsigned char *value)
|
||||
{
|
||||
m_stream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ColorStream &ColorStream::operator<<(std::basic_streambuf<CharacterType, TraitsType>* sb)
|
||||
{
|
||||
m_stream << sb;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ColorStream &ColorStream::operator<<(std::ios_base &(*func)(std::ios_base &))
|
||||
{
|
||||
m_stream << func;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ColorStream &ColorStream::operator<<(std::basic_ios<CharacterType, TraitsType> &(*func)(std::basic_ios<CharacterType, TraitsType> &))
|
||||
{
|
||||
m_stream << func;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ColorStream &ColorStream::operator<<(std::basic_ostream<CharacterType, TraitsType> &(*func)(std::basic_ostream<CharacterType, TraitsType> &))
|
||||
{
|
||||
m_stream << func;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class CharacterType, class Traits, class Allocator>
|
||||
inline ColorStream &operator<<(ColorStream &colorStream, const std::basic_string<CharacterType, Traits, Allocator> &string)
|
||||
{
|
||||
colorStream.stream() << string;
|
||||
return colorStream;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ColorStream &ColorStream::operator<<(char value)
|
||||
{
|
||||
m_stream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ColorStream &ColorStream::operator<<(signed char value)
|
||||
{
|
||||
m_stream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ColorStream &ColorStream::operator<<(unsigned char value)
|
||||
{
|
||||
m_stream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,13 +1,13 @@
|
||||
#ifndef __PLASP__UTILS__FORMATTING_H
|
||||
#define __PLASP__UTILS__FORMATTING_H
|
||||
#ifndef __PLASP__OUTPUT__FORMATTING_H
|
||||
#define __PLASP__OUTPUT__FORMATTING_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <plasp/utils/LogStream.h>
|
||||
#include <plasp/output/ColorStream.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace utils
|
||||
namespace output
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -18,21 +18,30 @@ namespace utils
|
||||
|
||||
enum class Color
|
||||
{
|
||||
Black = 0,
|
||||
Red = 1,
|
||||
Green = 2,
|
||||
Yellow = 3,
|
||||
Blue = 4,
|
||||
Magenta = 5,
|
||||
Cyan = 6,
|
||||
White = 7
|
||||
Default = 39,
|
||||
Black = 30,
|
||||
Red = 31,
|
||||
Green = 32,
|
||||
Yellow = 33,
|
||||
Blue = 34,
|
||||
Magenta = 35,
|
||||
Cyan = 36,
|
||||
LightGray = 37,
|
||||
DarkGray = 90,
|
||||
LightRed = 91,
|
||||
LightGreen = 92,
|
||||
LightYellow = 93,
|
||||
LightBlue = 94,
|
||||
LightMagenta = 95,
|
||||
LightCyan = 96,
|
||||
White = 97
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum class FontWeight
|
||||
{
|
||||
Normal = 0,
|
||||
Normal = 21,
|
||||
Bold = 1
|
||||
};
|
||||
|
||||
@@ -40,25 +49,19 @@ enum class FontWeight
|
||||
|
||||
struct Format
|
||||
{
|
||||
Format(Color color, FontWeight fontWeight = FontWeight::Normal)
|
||||
: m_color{color},
|
||||
m_fontWeight{fontWeight}
|
||||
{
|
||||
}
|
||||
|
||||
Color m_color;
|
||||
FontWeight m_fontWeight;
|
||||
Color color = Color::Default;
|
||||
FontWeight fontWeight = FontWeight::Normal;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline LogStream &operator<<(LogStream &stream, const Format &format)
|
||||
inline ColorStream &operator<<(ColorStream &stream, const Format &format)
|
||||
{
|
||||
if (!stream.supportsColor())
|
||||
return stream;
|
||||
|
||||
const auto fontWeightCode = static_cast<size_t>(format.m_fontWeight);
|
||||
const auto colorCode = 30 + static_cast<size_t>(format.m_color);
|
||||
const auto fontWeightCode = static_cast<int>(format.fontWeight);
|
||||
const auto colorCode = static_cast<int>(format.color);
|
||||
|
||||
return (stream << "\033[" << fontWeightCode << ";" << colorCode << "m");
|
||||
}
|
||||
@@ -71,7 +74,7 @@ struct ResetFormat
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline LogStream &operator<<(LogStream &stream, const ResetFormat &)
|
||||
inline ColorStream &operator<<(ColorStream &stream, const ResetFormat &)
|
||||
{
|
||||
if (!stream.supportsColor())
|
||||
return stream;
|
||||
@@ -81,196 +84,224 @@ inline LogStream &operator<<(LogStream &stream, const ResetFormat &)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Token
|
||||
struct Function
|
||||
{
|
||||
Token(const std::string &name)
|
||||
: name(name)
|
||||
Function(const char *name)
|
||||
: name{name}
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
const std::string &name;
|
||||
const char *name;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct RuleName: public Token
|
||||
{
|
||||
RuleName(const std::string &name)
|
||||
: Token(name)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline LogStream &operator<<(LogStream &stream, const RuleName &keyword)
|
||||
inline ColorStream &operator<<(ColorStream &stream, const Function &function)
|
||||
{
|
||||
return (stream
|
||||
<< utils::Format(utils::Color::White, utils::FontWeight::Bold)
|
||||
<< Format({Color::White, FontWeight::Normal})
|
||||
<< function.name
|
||||
<< ResetFormat());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Keyword
|
||||
{
|
||||
Keyword(const char *name)
|
||||
: name{name}
|
||||
{
|
||||
};
|
||||
|
||||
const char *name;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline ColorStream &operator<<(ColorStream &stream, const Keyword &keyword)
|
||||
{
|
||||
return (stream
|
||||
<< Format({Color::Blue, FontWeight::Normal})
|
||||
<< keyword.name
|
||||
<< utils::ResetFormat());
|
||||
<< ResetFormat());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Keyword: public Token
|
||||
struct Operator
|
||||
{
|
||||
Keyword(const std::string &name)
|
||||
: Token(name)
|
||||
Operator(const char *name)
|
||||
: name{name}
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
const char *name;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline LogStream &operator<<(LogStream &stream, const Keyword &keyword)
|
||||
inline ColorStream &operator<<(ColorStream &stream, const Operator &operator_)
|
||||
{
|
||||
return (stream
|
||||
<< utils::Format(utils::Color::Blue, utils::FontWeight::Normal)
|
||||
<< keyword.name
|
||||
<< utils::ResetFormat());
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Number: public Token
|
||||
{
|
||||
Number(const std::string &name)
|
||||
: Token(name)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline LogStream &operator<<(LogStream &stream, const Number &number)
|
||||
{
|
||||
return (stream
|
||||
<< utils::Format(utils::Color::Yellow, utils::FontWeight::Normal)
|
||||
<< number.name
|
||||
<< utils::ResetFormat());
|
||||
return (stream << operator_.name);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Variable: public Token
|
||||
template<typename T>
|
||||
struct Number
|
||||
{
|
||||
Variable(const std::string &name)
|
||||
: Token(name)
|
||||
Number(T value)
|
||||
: value{value}
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
T value;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline LogStream &operator<<(LogStream &stream, const Variable &variable)
|
||||
template<typename T>
|
||||
inline ColorStream &operator<<(ColorStream &stream, const Number<T> &number)
|
||||
{
|
||||
return (stream
|
||||
<< utils::Format(utils::Color::Green, utils::FontWeight::Bold)
|
||||
<< Format({Color::Yellow, FontWeight::Normal})
|
||||
<< number.value
|
||||
<< ResetFormat());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Variable
|
||||
{
|
||||
Variable(const char *name)
|
||||
: name{name}
|
||||
{
|
||||
};
|
||||
|
||||
const char *name;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline ColorStream &operator<<(ColorStream &stream, const Variable &variable)
|
||||
{
|
||||
return (stream
|
||||
<< Format({Color::Green, FontWeight::Bold})
|
||||
<< variable.name
|
||||
<< utils::ResetFormat());
|
||||
<< ResetFormat());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct String: public Token
|
||||
struct String
|
||||
{
|
||||
String(const std::string &name)
|
||||
: Token(name)
|
||||
String(const char *content)
|
||||
: content{content}
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
const char *content;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline LogStream &operator<<(LogStream &stream, const String &string)
|
||||
inline ColorStream &operator<<(ColorStream &stream, const String &string)
|
||||
{
|
||||
return (stream
|
||||
<< utils::Format(utils::Color::Green, utils::FontWeight::Normal)
|
||||
<< "\"" << string.name << "\""
|
||||
<< utils::ResetFormat());
|
||||
<< Format({Color::Green, FontWeight::Normal})
|
||||
<< "\"" << string.content << "\""
|
||||
<< ResetFormat());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Boolean: public Token
|
||||
struct Boolean
|
||||
{
|
||||
Boolean(const std::string &name)
|
||||
: Token(name)
|
||||
Boolean(const char *value)
|
||||
: value{value}
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
const char *value;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline LogStream &operator<<(LogStream &stream, const Boolean &string)
|
||||
inline ColorStream &operator<<(ColorStream &stream, const Boolean &boolean)
|
||||
{
|
||||
return (stream
|
||||
<< utils::Format(utils::Color::Red, utils::FontWeight::Normal)
|
||||
<< string.name
|
||||
<< utils::ResetFormat());
|
||||
<< Format({Color::Red, FontWeight::Normal})
|
||||
<< boolean.value
|
||||
<< ResetFormat());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Reserved: public Token
|
||||
struct Reserved
|
||||
{
|
||||
Reserved(const std::string &name)
|
||||
: Token(name)
|
||||
Reserved(const char *name)
|
||||
: name{name}
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
const char *name;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline LogStream &operator<<(LogStream &stream, const Reserved &string)
|
||||
inline ColorStream &operator<<(ColorStream &stream, const Reserved &reserved)
|
||||
{
|
||||
return (stream
|
||||
<< utils::Format(utils::Color::White, utils::FontWeight::Normal)
|
||||
<< string.name
|
||||
<< utils::ResetFormat());
|
||||
<< Format({Color::White, FontWeight::Normal})
|
||||
<< reserved.name
|
||||
<< ResetFormat());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Heading1: public Token
|
||||
struct Heading1
|
||||
{
|
||||
Heading1(const std::string &name)
|
||||
: Token(name)
|
||||
Heading1(const char *content)
|
||||
: content{content}
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
const char *content;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline LogStream &operator<<(LogStream &stream, const Heading1 &heading1)
|
||||
inline ColorStream &operator<<(ColorStream &stream, const Heading1 &heading1)
|
||||
{
|
||||
return (stream
|
||||
<< utils::Format(utils::Color::Blue, utils::FontWeight::Bold)
|
||||
<< Format({Color::Blue, FontWeight::Bold})
|
||||
<< "%---------------------------------------" << std::endl
|
||||
<< "% " << heading1.name << std::endl
|
||||
<< "% " << heading1.content << std::endl
|
||||
<< "%---------------------------------------"
|
||||
<< utils::ResetFormat()
|
||||
<< ResetFormat()
|
||||
<< std::endl);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Heading2: public Token
|
||||
struct Heading2
|
||||
{
|
||||
Heading2(const std::string &name)
|
||||
: Token(name)
|
||||
Heading2(const char *content)
|
||||
: content{content}
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
const char *content;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline LogStream &operator<<(LogStream &stream, const Heading2 &heading2)
|
||||
inline ColorStream &operator<<(ColorStream &stream, const Heading2 &heading2)
|
||||
{
|
||||
return (stream
|
||||
<< utils::Format(utils::Color::Blue, utils::FontWeight::Bold)
|
||||
<< "% " << heading2.name
|
||||
<< utils::ResetFormat());
|
||||
<< Format({Color::Blue, FontWeight::Bold})
|
||||
<< "% " << heading2.content
|
||||
<< ResetFormat());
|
||||
}
|
||||
|
||||
|
57
include/plasp/output/Logger.h
Normal file
57
include/plasp/output/Logger.h
Normal file
@@ -0,0 +1,57 @@
|
||||
#ifndef __PLASP__OUTPUT__LOGGER_H
|
||||
#define __PLASP__OUTPUT__LOGGER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <plasp/input/Location.h>
|
||||
#include <plasp/output/ColorStream.h>
|
||||
#include <plasp/output/Priority.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Logger
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Logger
|
||||
{
|
||||
public:
|
||||
explicit Logger();
|
||||
explicit Logger(ColorStream &&outputStream);
|
||||
explicit Logger(ColorStream &&outputStream, ColorStream &&errorStream);
|
||||
Logger(Logger &&other);
|
||||
Logger &operator=(Logger &&other);
|
||||
|
||||
ColorStream &outputStream();
|
||||
ColorStream &errorStream();
|
||||
|
||||
// The priority from which on messages should be printed
|
||||
void setLogPriority(Priority logPriority);
|
||||
// Messages with this priority (or higher) will terminate the program’s execution
|
||||
void setAbortPriority(Priority abortPriority);
|
||||
void setColorPolicy(ColorStream::ColorPolicy colorPolicy);
|
||||
|
||||
void log(Priority priority, const char *message);
|
||||
void log(Priority priority, const std::string &message);
|
||||
void log(Priority priority, const input::Location &location, const char *message);
|
||||
void log(Priority priority, const input::Location &location, const std::string &message);
|
||||
|
||||
private:
|
||||
ColorStream m_outputStream;
|
||||
ColorStream m_errorStream;
|
||||
|
||||
Priority m_logPriority;
|
||||
Priority m_abortPriority;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
66
include/plasp/output/Priority.h
Normal file
66
include/plasp/output/Priority.h
Normal file
@@ -0,0 +1,66 @@
|
||||
#ifndef __PLASP__OUTPUT__PRIORITY_H
|
||||
#define __PLASP__OUTPUT__PRIORITY_H
|
||||
|
||||
#include <cstring>
|
||||
#include <exception>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Priority
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum class Priority
|
||||
{
|
||||
Debug,
|
||||
Info,
|
||||
Warning,
|
||||
Error
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline constexpr const char *priorityName(Priority priority)
|
||||
{
|
||||
switch (priority)
|
||||
{
|
||||
case Priority::Debug:
|
||||
return "debug";
|
||||
case Priority::Info:
|
||||
return "info";
|
||||
case Priority::Warning:
|
||||
return "warning";
|
||||
case Priority::Error:
|
||||
return "error";
|
||||
}
|
||||
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline Priority priorityFromName(const char *priorityName)
|
||||
{
|
||||
if (std::strcmp(priorityName, "debug") == 0)
|
||||
return Priority::Debug;
|
||||
if (std::strcmp(priorityName, "info") == 0)
|
||||
return Priority::Info;
|
||||
if (std::strcmp(priorityName, "warning") == 0)
|
||||
return Priority::Warning;
|
||||
if (std::strcmp(priorityName, "error") == 0)
|
||||
return Priority::Error;
|
||||
|
||||
throw std::runtime_error("unknown log priority");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,12 +1,12 @@
|
||||
#ifndef __PLASP__UTILS__TRANSLATOR_EXCEPTION_H
|
||||
#define __PLASP__UTILS__TRANSLATOR_EXCEPTION_H
|
||||
#ifndef __PLASP__OUTPUT__TRANSLATOR_EXCEPTION_H
|
||||
#define __PLASP__OUTPUT__TRANSLATOR_EXCEPTION_H
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace utils
|
||||
namespace output
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
@@ -3,9 +3,9 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/input/Parser.h>
|
||||
#include <plasp/pddl/Expression.h>
|
||||
#include <plasp/pddl/expressions/Variable.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
|
@@ -5,8 +5,8 @@
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/output/Logger.h>
|
||||
#include <plasp/pddl/Parser.h>
|
||||
#include <plasp/utils/Logger.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -25,19 +25,9 @@ class Context
|
||||
Context() = default;
|
||||
~Context() = default;
|
||||
|
||||
explicit Context(Parser &&otherParser)
|
||||
: parser{std::move(otherParser)}
|
||||
{
|
||||
}
|
||||
|
||||
explicit Context(utils::Logger &&otherLogger)
|
||||
: logger{std::move(otherLogger)}
|
||||
{
|
||||
}
|
||||
|
||||
explicit Context(Parser &&otherParser, utils::Logger &&otherLogger)
|
||||
explicit Context(Parser &&otherParser, output::Logger &otherLogger)
|
||||
: parser{std::move(otherParser)},
|
||||
logger{std::move(otherLogger)}
|
||||
logger(otherLogger)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -46,17 +36,11 @@ class Context
|
||||
|
||||
Context(Context &&other)
|
||||
: parser(std::move(other.parser)),
|
||||
logger(std::move(other.logger))
|
||||
logger(other.logger)
|
||||
{
|
||||
}
|
||||
|
||||
Context &operator=(Context &&other)
|
||||
{
|
||||
parser = std::move(other.parser);
|
||||
logger = std::move(other.logger);
|
||||
|
||||
return *this;
|
||||
}
|
||||
Context &operator=(Context &&other) = delete;
|
||||
|
||||
constexpr static const char *auxiliaryPrefix()
|
||||
{
|
||||
@@ -64,7 +48,7 @@ class Context
|
||||
}
|
||||
|
||||
Parser parser;
|
||||
utils::Logger logger;
|
||||
output::Logger &logger;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -5,7 +5,7 @@
|
||||
|
||||
#include <plasp/pddl/Domain.h>
|
||||
#include <plasp/pddl/Problem.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
#include <plasp/input/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -21,10 +21,10 @@ namespace pddl
|
||||
class Description
|
||||
{
|
||||
public:
|
||||
static Description fromContext(Context &&context);
|
||||
static Description fromStream(std::istream &istream);
|
||||
static Description fromFile(const std::string &path);
|
||||
static Description fromFiles(const std::vector<std::string> &paths);
|
||||
static Description fromContext(Context &context);
|
||||
static Description fromStream(std::istream &istream, Context &context);
|
||||
static Description fromFile(const std::string &path, Context &context);
|
||||
static Description fromFiles(const std::vector<std::string> &paths, Context &context);
|
||||
|
||||
public:
|
||||
Context &context();
|
||||
@@ -38,18 +38,18 @@ class Description
|
||||
void normalize();
|
||||
|
||||
private:
|
||||
Description();
|
||||
Description(Context &context);
|
||||
|
||||
void parse();
|
||||
void findSections();
|
||||
|
||||
void checkConsistency();
|
||||
|
||||
Context m_context;
|
||||
Context &m_context;
|
||||
|
||||
utils::Stream::Position m_domainPosition;
|
||||
input::Stream::Position m_domainPosition;
|
||||
std::unique_ptr<Domain> m_domain;
|
||||
utils::Stream::Position m_problemPosition;
|
||||
input::Stream::Position m_problemPosition;
|
||||
std::unique_ptr<Problem> m_problem;
|
||||
};
|
||||
|
||||
|
@@ -75,19 +75,19 @@ class Domain
|
||||
|
||||
std::string m_name;
|
||||
|
||||
utils::Stream::Position m_requirementsPosition;
|
||||
input::Stream::Position m_requirementsPosition;
|
||||
Requirements m_requirements;
|
||||
|
||||
utils::Stream::Position m_typesPosition;
|
||||
input::Stream::Position m_typesPosition;
|
||||
expressions::PrimitiveTypes m_types;
|
||||
|
||||
utils::Stream::Position m_constantsPosition;
|
||||
input::Stream::Position m_constantsPosition;
|
||||
expressions::Constants m_constants;
|
||||
|
||||
utils::Stream::Position m_predicatesPosition;
|
||||
input::Stream::Position m_predicatesPosition;
|
||||
expressions::PredicateDeclarations m_predicates;
|
||||
|
||||
std::vector<utils::Stream::Position> m_actionPositions;
|
||||
std::vector<input::Stream::Position> m_actionPositions;
|
||||
std::vector<std::unique_ptr<Action>> m_actions;
|
||||
|
||||
expressions::DerivedPredicates m_derivedPredicates;
|
||||
|
@@ -5,7 +5,7 @@
|
||||
|
||||
#include <boost/intrusive_ptr.hpp>
|
||||
|
||||
#include <plasp/utils/Parser.h>
|
||||
#include <plasp/input/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#ifndef __PLASP__PDDL__PARSER_H
|
||||
#define __PLASP__PDDL__PARSER_H
|
||||
|
||||
#include <plasp/utils/Parser.h>
|
||||
#include <plasp/input/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -44,7 +44,7 @@ class PDDLParserPolicy
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using Parser = utils::Parser<PDDLParserPolicy>;
|
||||
using Parser = input::Parser<PDDLParserPolicy>;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@@ -64,18 +64,18 @@ class Problem
|
||||
|
||||
std::string m_name;
|
||||
|
||||
utils::Stream::Position m_domainPosition;
|
||||
input::Stream::Position m_domainPosition;
|
||||
|
||||
utils::Stream::Position m_requirementsPosition;
|
||||
input::Stream::Position m_requirementsPosition;
|
||||
Requirements m_requirements;
|
||||
|
||||
utils::Stream::Position m_objectsPosition;
|
||||
input::Stream::Position m_objectsPosition;
|
||||
expressions::Constants m_objects;
|
||||
|
||||
utils::Stream::Position m_initialStatePosition;
|
||||
input::Stream::Position m_initialStatePosition;
|
||||
std::unique_ptr<InitialState> m_initialState;
|
||||
|
||||
utils::Stream::Position m_goalPosition;
|
||||
input::Stream::Position m_goalPosition;
|
||||
ExpressionPointer m_goal;
|
||||
};
|
||||
|
||||
|
@@ -19,7 +19,7 @@ namespace pddl
|
||||
class TranslatorASP
|
||||
{
|
||||
public:
|
||||
explicit TranslatorASP(Description &description, utils::LogStream &outputStream);
|
||||
explicit TranslatorASP(Description &description, output::ColorStream &outputStream);
|
||||
|
||||
void translate() const;
|
||||
|
||||
@@ -40,7 +40,7 @@ class TranslatorASP
|
||||
void translatePredicate(const expressions::Predicate &predicate) const;
|
||||
|
||||
Description &m_description;
|
||||
utils::LogStream &m_outputStream;
|
||||
output::ColorStream &m_outputStream;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -2,8 +2,6 @@
|
||||
#define __PLASP__PDDL__EXPRESSIONS__CONSTANT_H
|
||||
|
||||
#include <plasp/pddl/Expression.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
#include <plasp/utils/ParserException.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
|
@@ -79,7 +79,7 @@ boost::intrusive_ptr<Derived> NAry<Derived>::parse(Context &context,
|
||||
}
|
||||
|
||||
if (expression->m_arguments.empty())
|
||||
context.logger.logWarning(parser.coordinate(), "“" + Derived::Identifier + "” expressions should not be empty");
|
||||
context.logger.log(output::Priority::Warning, parser.location(), "“" + Derived::Identifier + "” expressions should not be empty");
|
||||
|
||||
parser.expect<std::string>(")");
|
||||
|
||||
|
@@ -2,7 +2,6 @@
|
||||
#define __PLASP__PDDL__EXPRESSIONS__PRIMITIVE_TYPE_H
|
||||
|
||||
#include <plasp/pddl/Expression.h>
|
||||
#include <plasp/utils/ParserException.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
|
@@ -4,9 +4,9 @@
|
||||
#include <iosfwd>
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/input/Parser.h>
|
||||
#include <plasp/sas/Value.h>
|
||||
#include <plasp/sas/Variable.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -27,8 +27,8 @@ using AssignedVariables = std::vector<AssignedVariable>;
|
||||
class AssignedVariable
|
||||
{
|
||||
public:
|
||||
static AssignedVariable fromSAS(utils::Parser<> &parser, const Variables &variables);
|
||||
static AssignedVariable fromSAS(utils::Parser<> &parser, const Variable &variable);
|
||||
static AssignedVariable fromSAS(input::Parser<> &parser, const Variables &variables);
|
||||
static AssignedVariable fromSAS(input::Parser<> &parser, const Variable &variable);
|
||||
|
||||
public:
|
||||
explicit AssignedVariable(const Variable &variable, const Value &value);
|
||||
|
@@ -3,9 +3,9 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/input/Parser.h>
|
||||
#include <plasp/sas/AssignedVariable.h>
|
||||
#include <plasp/sas/Variable.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -29,7 +29,7 @@ class AxiomRule
|
||||
using Condition = AssignedVariable;
|
||||
using Conditions = AssignedVariables;
|
||||
|
||||
static AxiomRule fromSAS(utils::Parser<> &parser, const Variables &variables);
|
||||
static AxiomRule fromSAS(input::Parser<> &parser, const Variables &variables);
|
||||
|
||||
public:
|
||||
const Conditions &conditions() const;
|
||||
|
@@ -16,7 +16,7 @@ namespace sas
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
utils::LogStream &operator<<(utils::LogStream &ostream, const Description &description);
|
||||
output::ColorStream &operator<<(output::ColorStream &ostream, const Description &description);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@@ -7,13 +7,13 @@
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#include <plasp/input/Parser.h>
|
||||
#include <plasp/sas/AxiomRule.h>
|
||||
#include <plasp/sas/Goal.h>
|
||||
#include <plasp/sas/InitialState.h>
|
||||
#include <plasp/sas/MutexGroup.h>
|
||||
#include <plasp/sas/Operator.h>
|
||||
#include <plasp/sas/Variable.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -29,7 +29,7 @@ namespace sas
|
||||
class Description
|
||||
{
|
||||
public:
|
||||
static Description fromParser(utils::Parser<> &&parser);
|
||||
static Description fromParser(input::Parser<> &&parser);
|
||||
static Description fromStream(std::istream &istream);
|
||||
static Description fromFile(const boost::filesystem::path &path);
|
||||
|
||||
@@ -50,16 +50,16 @@ class Description
|
||||
private:
|
||||
Description();
|
||||
|
||||
void parseContent(utils::Parser<> &parser);
|
||||
void parseContent(input::Parser<> &parser);
|
||||
|
||||
void parseVersionSection(utils::Parser<> &parser) const;
|
||||
void parseMetricSection(utils::Parser<> &parser);
|
||||
void parseVariablesSection(utils::Parser<> &parser);
|
||||
void parseMutexSection(utils::Parser<> &parser);
|
||||
void parseInitialStateSection(utils::Parser<> &parser);
|
||||
void parseGoalSection(utils::Parser<> &parser);
|
||||
void parseOperatorSection(utils::Parser<> &parser);
|
||||
void parseAxiomSection(utils::Parser<> &parser);
|
||||
void parseVersionSection(input::Parser<> &parser) const;
|
||||
void parseMetricSection(input::Parser<> &parser);
|
||||
void parseVariablesSection(input::Parser<> &parser);
|
||||
void parseMutexSection(input::Parser<> &parser);
|
||||
void parseInitialStateSection(input::Parser<> &parser);
|
||||
void parseGoalSection(input::Parser<> &parser);
|
||||
void parseOperatorSection(input::Parser<> &parser);
|
||||
void parseAxiomSection(input::Parser<> &parser);
|
||||
|
||||
bool m_usesActionCosts;
|
||||
|
||||
|
@@ -3,9 +3,9 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/input/Parser.h>
|
||||
#include <plasp/sas/AssignedVariable.h>
|
||||
#include <plasp/sas/Variable.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -29,7 +29,7 @@ class Effect
|
||||
using Condition = AssignedVariable;
|
||||
using Conditions = AssignedVariables;
|
||||
|
||||
static Effect fromSAS(utils::Parser<> &parser, const Variables &variables, Conditions &preconditions);
|
||||
static Effect fromSAS(input::Parser<> &parser, const Variables &variables, Conditions &preconditions);
|
||||
|
||||
public:
|
||||
const Conditions &conditions() const;
|
||||
|
@@ -1,8 +1,8 @@
|
||||
#ifndef __PLASP__SAS__GOAL_H
|
||||
#define __PLASP__SAS__GOAL_H
|
||||
|
||||
#include <plasp/input/Parser.h>
|
||||
#include <plasp/sas/AssignedVariable.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -21,7 +21,7 @@ class Goal
|
||||
using Fact = AssignedVariable;
|
||||
using Facts = AssignedVariables;
|
||||
|
||||
static Goal fromSAS(utils::Parser<> &parser, const Variables &variables);
|
||||
static Goal fromSAS(input::Parser<> &parser, const Variables &variables);
|
||||
|
||||
public:
|
||||
const Facts &facts() const;
|
||||
|
@@ -1,8 +1,8 @@
|
||||
#ifndef __PLASP__SAS__INITIAL_STATE_H
|
||||
#define __PLASP__SAS__INITIAL_STATE_H
|
||||
|
||||
#include <plasp/input/Parser.h>
|
||||
#include <plasp/sas/AssignedVariable.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -21,7 +21,7 @@ class InitialState
|
||||
using Fact = AssignedVariable;
|
||||
using Facts = AssignedVariables;
|
||||
|
||||
static InitialState fromSAS(utils::Parser<> &parser, const Variables &variables);
|
||||
static InitialState fromSAS(input::Parser<> &parser, const Variables &variables);
|
||||
|
||||
public:
|
||||
const Facts &facts() const;
|
||||
|
@@ -3,8 +3,8 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/input/Parser.h>
|
||||
#include <plasp/sas/AssignedVariable.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -28,7 +28,7 @@ class MutexGroup
|
||||
using Fact = AssignedVariable;
|
||||
using Facts = AssignedVariables;
|
||||
|
||||
static MutexGroup fromSAS(utils::Parser<> &parser, const Variables &variables);
|
||||
static MutexGroup fromSAS(input::Parser<> &parser, const Variables &variables);
|
||||
|
||||
public:
|
||||
const Facts &facts() const;
|
||||
|
@@ -4,12 +4,12 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/input/Parser.h>
|
||||
#include <plasp/output/ColorStream.h>
|
||||
#include <plasp/sas/AssignedVariable.h>
|
||||
#include <plasp/sas/Effect.h>
|
||||
#include <plasp/sas/Predicate.h>
|
||||
#include <plasp/sas/Variable.h>
|
||||
#include <plasp/utils/LogStream.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -33,10 +33,10 @@ class Operator
|
||||
using Condition = AssignedVariable;
|
||||
using Conditions = AssignedVariables;
|
||||
|
||||
static Operator fromSAS(utils::Parser<> &parser, const Variables &variables);
|
||||
static Operator fromSAS(input::Parser<> &parser, const Variables &variables);
|
||||
|
||||
public:
|
||||
void printPredicateAsASP(utils::LogStream &ostream) const;
|
||||
void printPredicateAsASP(output::ColorStream &stream) const;
|
||||
|
||||
const Predicate &predicate() const;
|
||||
const Conditions &preconditions() const;
|
||||
|
@@ -5,8 +5,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/utils/LogStream.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
#include <plasp/input/Parser.h>
|
||||
#include <plasp/output/ColorStream.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -22,13 +22,13 @@ namespace sas
|
||||
class Predicate
|
||||
{
|
||||
public:
|
||||
static Predicate fromSAS(utils::Parser<> &parser);
|
||||
static Predicate fromSAS(input::Parser<> &parser);
|
||||
|
||||
using Arguments = std::vector<std::string>;
|
||||
|
||||
public:
|
||||
void printAsSAS(utils::LogStream &outputStream) const;
|
||||
void printAsASP(utils::LogStream &outputStream) const;
|
||||
void printAsSAS(output::ColorStream &stream) const;
|
||||
void printAsASP(output::ColorStream &stream) const;
|
||||
|
||||
const std::string &name() const;
|
||||
const Arguments &arguments() const;
|
||||
|
@@ -1,8 +1,8 @@
|
||||
#ifndef __PLASP__SAS__TRANSLATOR_ASP_H
|
||||
#define __PLASP__SAS__TRANSLATOR_ASP_H
|
||||
|
||||
#include <plasp/output/ColorStream.h>
|
||||
#include <plasp/sas/Description.h>
|
||||
#include <plasp/utils/LogStream.h>
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace sas
|
||||
class TranslatorASP
|
||||
{
|
||||
public:
|
||||
explicit TranslatorASP(const Description &description, utils::LogStream &outputStream);
|
||||
explicit TranslatorASP(const Description &description, output::ColorStream &outputStream);
|
||||
|
||||
void translate() const;
|
||||
|
||||
@@ -34,7 +34,7 @@ class TranslatorASP
|
||||
void translateAxiomRules() const;
|
||||
|
||||
const Description &m_description;
|
||||
utils::LogStream &m_outputStream;
|
||||
output::ColorStream &m_outputStream;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -5,8 +5,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/utils/LogStream.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
#include <plasp/input/Parser.h>
|
||||
#include <plasp/output/ColorStream.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -39,14 +39,14 @@ struct Value
|
||||
static const Value Any;
|
||||
static const Value None;
|
||||
|
||||
static Value fromSAS(utils::Parser<> &parser);
|
||||
static const Value &referenceFromSAS(utils::Parser<> &parser, const Variable &variable);
|
||||
static Value fromSAS(input::Parser<> &parser);
|
||||
static const Value &referenceFromSAS(input::Parser<> &parser, const Variable &variable);
|
||||
|
||||
public:
|
||||
Value negated() const;
|
||||
|
||||
void printAsSAS(utils::LogStream &outputStream) const;
|
||||
void printAsASPPredicate(utils::LogStream &outputStream) const;
|
||||
void printAsSAS(output::ColorStream &stream) const;
|
||||
void printAsASPPredicate(output::ColorStream &stream) const;
|
||||
|
||||
Sign sign() const;
|
||||
const std::string &name() const;
|
||||
|
@@ -5,9 +5,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/input/Parser.h>
|
||||
#include <plasp/output/ColorStream.h>
|
||||
#include <plasp/sas/Value.h>
|
||||
#include <plasp/utils/LogStream.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -28,11 +28,11 @@ using Variables = std::vector<Variable>;
|
||||
class Variable
|
||||
{
|
||||
public:
|
||||
static Variable fromSAS(utils::Parser<> &parser);
|
||||
static const Variable &referenceFromSAS(utils::Parser<> &parser, const Variables &variables);
|
||||
static Variable fromSAS(input::Parser<> &parser);
|
||||
static const Variable &referenceFromSAS(input::Parser<> &parser, const Variables &variables);
|
||||
|
||||
public:
|
||||
void printNameAsASPPredicate(utils::LogStream &outputStream) const;
|
||||
void printNameAsASPPredicate(output::ColorStream &outputStream) const;
|
||||
|
||||
const std::string &name() const;
|
||||
int axiomLayer() const;
|
||||
|
@@ -3,9 +3,9 @@
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
#include <plasp/input/Parser.h>
|
||||
#include <plasp/sas/Value.h>
|
||||
#include <plasp/sas/Variable.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -26,7 +26,7 @@ using VariableTransitions = std::vector<VariableTransition>;
|
||||
class VariableTransition
|
||||
{
|
||||
public:
|
||||
static VariableTransition fromSAS(utils::Parser<> &parser, const Variables &variables);
|
||||
static VariableTransition fromSAS(input::Parser<> &parser, const Variables &variables);
|
||||
|
||||
public:
|
||||
const Variable &variable() const;
|
||||
|
@@ -1,335 +0,0 @@
|
||||
#ifndef __PLASP__UTILS__LOG_STREAM_H
|
||||
#define __PLASP__UTILS__LOG_STREAM_H
|
||||
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace utils
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// LogStream
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum class StandardStream
|
||||
{
|
||||
Out,
|
||||
Err
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class LogStream
|
||||
{
|
||||
public:
|
||||
enum class ColorPolicy
|
||||
{
|
||||
Never,
|
||||
Auto,
|
||||
Always
|
||||
};
|
||||
|
||||
private:
|
||||
using CharacterType = std::ostream::char_type;
|
||||
using TraitsType = std::ostream::traits_type;
|
||||
|
||||
public:
|
||||
LogStream(StandardStream standardStream)
|
||||
: m_standardStream{standardStream},
|
||||
m_colorPolicy{ColorPolicy::Auto}
|
||||
{
|
||||
}
|
||||
|
||||
LogStream(const LogStream &other)
|
||||
: m_standardStream{other.m_standardStream},
|
||||
m_colorPolicy{other.m_colorPolicy}
|
||||
{
|
||||
}
|
||||
|
||||
LogStream &operator=(const LogStream &other)
|
||||
{
|
||||
m_standardStream = other.m_standardStream;
|
||||
m_colorPolicy = other.m_colorPolicy;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
LogStream(LogStream &&other)
|
||||
: m_standardStream{other.m_standardStream},
|
||||
m_colorPolicy{other.m_colorPolicy}
|
||||
{
|
||||
other.m_colorPolicy = ColorPolicy::Auto;
|
||||
}
|
||||
|
||||
LogStream &operator=(LogStream &&other)
|
||||
{
|
||||
m_standardStream = other.m_standardStream;
|
||||
m_colorPolicy = other.m_colorPolicy;
|
||||
|
||||
other.m_colorPolicy = ColorPolicy::Auto;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void setColorPolicy(ColorPolicy colorPolicy)
|
||||
{
|
||||
m_colorPolicy = colorPolicy;
|
||||
}
|
||||
|
||||
bool supportsColor() const
|
||||
{
|
||||
if (m_colorPolicy == ColorPolicy::Never)
|
||||
return false;
|
||||
|
||||
if (m_colorPolicy == ColorPolicy::Always)
|
||||
return true;
|
||||
|
||||
// Autodetect by checking whether output goes to a terminal
|
||||
const auto fileDescriptor =
|
||||
(m_standardStream == utils::StandardStream::Out)
|
||||
? STDOUT_FILENO
|
||||
: STDERR_FILENO;
|
||||
|
||||
return isatty(fileDescriptor);
|
||||
}
|
||||
|
||||
std::ostream &ostream()
|
||||
{
|
||||
return (m_standardStream == utils::StandardStream::Out)
|
||||
? std::cout
|
||||
: std::cerr;
|
||||
}
|
||||
|
||||
inline LogStream &operator<<(short value);
|
||||
inline LogStream &operator<<(unsigned short value);
|
||||
inline LogStream &operator<<(int value);
|
||||
inline LogStream &operator<<(unsigned int value);
|
||||
inline LogStream &operator<<(long value);
|
||||
inline LogStream &operator<<(unsigned long value);
|
||||
inline LogStream &operator<<(long long value);
|
||||
inline LogStream &operator<<(unsigned long long value);
|
||||
inline LogStream &operator<<(float value);
|
||||
inline LogStream &operator<<(double value);
|
||||
inline LogStream &operator<<(long double value);
|
||||
inline LogStream &operator<<(bool value);
|
||||
inline LogStream &operator<<(const void *value);
|
||||
inline LogStream &operator<<(const char *value);
|
||||
inline LogStream &operator<<(const signed char *value);
|
||||
inline LogStream &operator<<(const unsigned char *value);
|
||||
inline LogStream &operator<<(std::basic_streambuf<CharacterType, TraitsType> *sb);
|
||||
inline LogStream &operator<<(std::ios_base &(*func)(std::ios_base &));
|
||||
inline LogStream &operator<<(std::basic_ios<CharacterType, TraitsType> &(*func)(std::basic_ios<CharacterType, TraitsType> &));
|
||||
inline LogStream &operator<<(std::basic_ostream<CharacterType, TraitsType> &(*func)(std::basic_ostream<CharacterType, TraitsType> &));
|
||||
|
||||
inline LogStream &operator<<(char value);
|
||||
inline LogStream &operator<<(signed char value);
|
||||
inline LogStream &operator<<(unsigned char value);
|
||||
|
||||
private:
|
||||
StandardStream m_standardStream;
|
||||
ColorPolicy m_colorPolicy;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LogStream &LogStream::operator<<(short value)
|
||||
{
|
||||
ostream() << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LogStream &LogStream::operator<<(unsigned short value)
|
||||
{
|
||||
ostream() << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LogStream &LogStream::operator<<(int value)
|
||||
{
|
||||
ostream() << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LogStream &LogStream::operator<<(unsigned int value)
|
||||
{
|
||||
ostream() << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LogStream &LogStream::operator<<(long value)
|
||||
{
|
||||
ostream() << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LogStream &LogStream::operator<<(unsigned long value)
|
||||
{
|
||||
ostream() << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LogStream &LogStream::operator<<(long long value)
|
||||
{
|
||||
ostream() << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LogStream &LogStream::operator<<(unsigned long long value)
|
||||
{
|
||||
ostream() << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LogStream &LogStream::operator<<(float value)
|
||||
{
|
||||
ostream() << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LogStream &LogStream::operator<<(double value)
|
||||
{
|
||||
ostream() << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LogStream &LogStream::operator<<(long double value)
|
||||
{
|
||||
ostream() << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LogStream &LogStream::operator<<(bool value)
|
||||
{
|
||||
ostream() << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LogStream &LogStream::operator<<(const void *value)
|
||||
{
|
||||
ostream() << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LogStream &LogStream::operator<<(const char *value)
|
||||
{
|
||||
ostream() << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LogStream &LogStream::operator<<(const signed char *value)
|
||||
{
|
||||
ostream() << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LogStream &LogStream::operator<<(const unsigned char *value)
|
||||
{
|
||||
ostream() << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LogStream &LogStream::operator<<(std::basic_streambuf<CharacterType, TraitsType>* sb)
|
||||
{
|
||||
ostream() << sb;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LogStream &LogStream::operator<<(std::ios_base &(*func)(std::ios_base &))
|
||||
{
|
||||
ostream() << func;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LogStream &LogStream::operator<<(std::basic_ios<CharacterType, TraitsType> &(*func)(std::basic_ios<CharacterType, TraitsType> &))
|
||||
{
|
||||
ostream() << func;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LogStream &LogStream::operator<<(std::basic_ostream<CharacterType, TraitsType> &(*func)(std::basic_ostream<CharacterType, TraitsType> &))
|
||||
{
|
||||
ostream() << func;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class CharacterType, class Traits, class Allocator>
|
||||
inline LogStream &operator<<(LogStream &stream, const std::basic_string<CharacterType, Traits, Allocator> &string)
|
||||
{
|
||||
stream.ostream() << string;
|
||||
return stream;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LogStream &LogStream::operator<<(char value)
|
||||
{
|
||||
ostream() << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LogStream &LogStream::operator<<(signed char value)
|
||||
{
|
||||
ostream() << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LogStream &LogStream::operator<<(unsigned char value)
|
||||
{
|
||||
ostream() << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,62 +0,0 @@
|
||||
#ifndef __PLASP__UTILS__LOGGER_H
|
||||
#define __PLASP__UTILS__LOGGER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <plasp/utils/LogStream.h>
|
||||
#include <plasp/utils/ParserException.h>
|
||||
#include <plasp/utils/StreamCoordinate.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace utils
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Logger
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Logger
|
||||
{
|
||||
public:
|
||||
enum class WarningLevel
|
||||
{
|
||||
Normal,
|
||||
Error,
|
||||
Ignore
|
||||
};
|
||||
|
||||
public:
|
||||
Logger();
|
||||
|
||||
Logger(const Logger &other);
|
||||
Logger &operator=(const Logger &other);
|
||||
|
||||
Logger(Logger &&other);
|
||||
Logger &operator=(Logger &&other);
|
||||
|
||||
LogStream &outputStream();
|
||||
LogStream &errorStream();
|
||||
|
||||
void setWarningLevel(WarningLevel warningLevel);
|
||||
void setColorPolicy(LogStream::ColorPolicy colorPolicy);
|
||||
|
||||
void logError(const std::string &message);
|
||||
void logError(const StreamCoordinate &coordinate, const std::string &message);
|
||||
void logWarning(const StreamCoordinate &parserCoordinate, const std::string &message);
|
||||
|
||||
private:
|
||||
LogStream m_outputStream;
|
||||
LogStream m_errorStream;
|
||||
|
||||
WarningLevel m_warningLevel;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,71 +0,0 @@
|
||||
#ifndef __PLASP__UTILS__PARSER_EXCEPTION_H
|
||||
#define __PLASP__UTILS__PARSER_EXCEPTION_H
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
#include <plasp/utils/StreamCoordinate.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace utils
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// ParserException
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ParserException: public std::exception
|
||||
{
|
||||
public:
|
||||
explicit ParserException(const StreamCoordinate &coordinate)
|
||||
: ParserException(coordinate, "unspecified parser error")
|
||||
{
|
||||
}
|
||||
|
||||
explicit ParserException(const StreamCoordinate &coordinate, const char *message)
|
||||
: ParserException(coordinate, static_cast<std::string>(message))
|
||||
{
|
||||
}
|
||||
|
||||
explicit ParserException(const StreamCoordinate &coordinate, const std::string &message)
|
||||
: m_coordinate{coordinate},
|
||||
m_message{message},
|
||||
m_plainMessage{m_coordinate.sectionName + ":" + std::to_string(m_coordinate.row)
|
||||
+ ":" + std::to_string(m_coordinate.column) + " " + m_message}
|
||||
{
|
||||
}
|
||||
|
||||
~ParserException() throw()
|
||||
{
|
||||
}
|
||||
|
||||
const char *what() const throw()
|
||||
{
|
||||
return m_plainMessage.c_str();
|
||||
}
|
||||
|
||||
const StreamCoordinate &coordinate() const
|
||||
{
|
||||
return m_coordinate;
|
||||
}
|
||||
|
||||
const std::string &message() const
|
||||
{
|
||||
return m_message;
|
||||
}
|
||||
|
||||
private:
|
||||
StreamCoordinate m_coordinate;
|
||||
std::string m_message;
|
||||
std::string m_plainMessage;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user