training_2008_10_25 / std.check.src.global.hpp

ru en cn

с начала прошло: 5518 д. 13:13
страница обновлена: 05.12.2023 03:18

std.check.src.global.hpp: src/global.hpp

/*!
  \file global.hpp
  \brief Header file which declares general functions used by the library.
*/
#ifndef CHECK_GLOBAL_HPP
#define CHECK_GLOBAL_HPP

#include 

#undef CHECK_MSC
#undef CHECK_MSC_VERSION
#if defined(_MSC_VER)
/*!
  \brief Defined only if program compiled with Microsoft Visual C++ Compiler.

  \see CHECK_GCC
*/
#  define CHECK_MSC
/*!
  \brief Defines boolean expression to check that version of current compiler
  as Microsoft Visual C++ Compiler is greater or equals to given one.

  If current compiler's family is not Microsoft then zero is substituted.

  \param MAJOR Major version number.
  \param MINOR Minor version number.

  \see CHECK_MSC and CHECK_GCC_VERSION
*/
#  define CHECK_MSC_VERSION(MAJOR, MINOR) ((MAJOR) * 100 + (MINOR) <= _MSC_VER)
#else
#  define CHECK_MSC_VERSION(MAJOR, MINOR) (0)
#endif

#undef CHECK_GCC
#undef CHECK_GCC_VERSION
#if defined(__GNUC__)
/*!
  \brief Defined only if program compiled with GNU Compiler Collection.

  \see CHECK_MSC and CHECK_GCC_VERSION
*/
#  define CHECK_GCC
/*!
  \brief Defines boolean expression to check that version of current compiler
  as compiler of GNU Compiler Collection is greater or equals to given one.

  If current compiler's family is not GNU then zero is substituted.

  \param MAJOR Major version number.
  \param MINOR Minor version number.

  \see CHECK_GCC and CHECK_MSC_VERSION
*/
#  define CHECK_GCC_VERSION(MAJOR, MINOR) \
    ((MAJOR) < __GNUC__ || ((MAJOR) == __GNUC__ && (MINOR) <= __GNUC_MINOR__))
#else
#  define CHECK_GCC_VERSION(MAJOR, MINOR) (0)
#endif


namespace Check
{


/*!
  \brief Enumeration which defines outcomes of testing.

  Define \c CHECK_NO_SHORT_NAMES to disable short equivalents.
*/
enum Decision
{
  SolutionAccepted, //!< Test successfully passed.
  WrongAnswer, //!< The answer is presented well, but it's wrong.
  PresentationError, //!< Incorrect format of the answer.
  UnhandledError, //!< Any other error occurred during check process.
  #if !defined(CHECK_NO_SHORT_NAMES)
  OK = SolutionAccepted, //!< Same as #SolutionAccepted.
  WA = WrongAnswer, //!< Same as #WrongAnswer.
  PE = PresentationError, //!< Same as #PresentationError.
  UE = UnhandledError //!< Same as #UnhandledError.
  #endif
};


class Stream;

//! Default Stream opened for reading input file.
extern Stream input;

//! Default Stream opened for reading tested program output file.
extern Stream output;

//! Default Stream opened for reading master program output file (answer file).
extern Stream answer;


/*!
  Initializes current instance of the library using \a argsCount command line
  arguments \a args[].

  \throws InternalError
*/
void init(int argsCount, char *args[]);

//! Determines an exit code for a given outcome \a result.
int exitCode(const Decision result);

/*!
  \ingroup error

  Reports testing outcome \a result along with message specified by
  printf \a format and arguments, then terminates program.

  If #output contains unread symbols which is not whitespace, this function
  throws UnhopedDataError exception.

  \throws InternalError
  \throws UnhopedDataError

  \see quit() and exitUnless()
*/
void exit(const Decision result, const char *format, ...);

/*!
  \ingroup error

  Works in the same way as exit() but only if \a cond is false;
  otherwise does nothing.

  \throws InternalError
  \throws UnhopedDataError

  \see exit() and quitUnless()
*/
void exitUnless(
  const bool cond, const Decision result, const char *format, ...);

/*!
  \ingroup error

  Reports testing outcome \a result along with text \a message,
  then terminates program.

  Argument \a message is not mandatory, by default \a message is empty.

  If #output contains unread symbols which is not whitespace, this function
  throws UnhopedDataError exception.

  \throws InternalError
  \throws UnhopedDataError

  \see exit() and quitUnless()
*/
inline void quit(const Decision result, const char *message = NULL)
{ exit(result, "%s", message != NULL ? message : ""); }

/*!
  \ingroup error

  Works in the same way as quit() only if \a cond is false;
  otherwise does nothing.

  \throws InternalError
  \throws UnhopedDataError

  \see quit() and exitUnless()
*/
inline void quitUnless(
  const bool cond, const Decision result, const char *message = NULL)
{ exitUnless(cond, result, "%s", message != NULL ? message : ""); }

/*!
  \ingroup error

  This is an overloaded function, provided for convenience.

  Exactly alike quit(const Decision, const char *)
  except for the type of \a message parameter.

  \throws InternalError
  \throws UnhopedDataError

  \see exit() and quitUnless()
*/
inline void quit(const Decision result, const std::string &message)
{ exit(result, "%s", message.c_str()); }

/*!
  \ingroup error

  This is an overloaded function, provided for convenience.

  Exactly alike quitUnless(const bool, const Decision, const char *)
  except for the type of \a message parameter.

  \throws InternalError
  \throws UnhopedDataError

  \see quit() and exitUnless()
*/
inline void quitUnless(
  const bool cond, const Decision result, const std::string &message)
{ exitUnless(cond, result, "%s", message.c_str()); }


}


#endif /* CHECK_GLOBAL_HPP */
Дальневосточный федеральный университет