Commit 8c9fa3ec authored by Seblu's avatar Seblu
Browse files

No commit message

No commit message
parent 29db56eb
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -2,8 +2,10 @@ bin_PROGRAMS=sudoku

sudoku_SOURCES=	src/sudoku.hh			\
		src/sudoku.cc			\
		src/grid.hxx			\
		src/grid.cc			\
		src/block.hxx
		src/block.hxx			\
		src/error.cc

CLEANFILES= *~ '\#*'

+1 −1
Original line number Diff line number Diff line
Bug: le dernier carre est pas initialise. voir avec la memeoire!
+6 −4
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ AC_ARG_WITH([noerror],
       true
  ],
  [dnl action-if-not-given
       CXXFLAGS="$CFLAGS -Werror"
       CXXFLAGS="$CXXFLAGS -Werror"
  ]
)

@@ -74,8 +74,10 @@ AC_ARG_WITH([efence],
AC_SUBST([CXXFLAGS])
AC_SUBST([LDFLAGS])

# define Autoconf config header
AC_HEADER_STDC

AC_CONFIG_HEADERS([config.h])
AC_CHECK_HEADERS([stdlib.h])

# define Autoconf config files
AC_CONFIG_FILES([
+13 −11
Original line number Diff line number Diff line
@@ -7,9 +7,9 @@ inline Block::Block(int value = 0) {
    forbidden_[i] = false;
}

inline bool Block::is_forbidden(int value) const {
inline bool Block::is_forbidden(int value) const throw (Error) {
  if (!(value > 0 && value <= GRID_SIDE))
    throw std::string("Invalid is_forbidden value");
    throw Error("Invalid \"is_forbidden\" value.");
  return forbidden_[value - 1];
}

@@ -22,30 +22,32 @@ inline int Block::get() const
  return value_;
}

inline void Block::set(int val)
inline void Block::set(int val) throw (Error)
{
  if (!(val > 0 && val <= GRID_SIDE))
    throw std::string("Invalid value");
    throw Error("Try to set an invalid value.", EXIT_INV_VAL);
  if (value_ != 0)
    throw std::string("Value already set");
    throw Error("Try to set an already set value.");
  if (forbidden_[val - 1])
    throw std::string("Set a forbidden value");
    throw Error("Try to set a forbidden value.");
  value_ = val;
  for (register int i = 0; i < GRID_SIDE; ++i)
    forbidden_[i] = true;
}

inline void Block::forbid(int val) {
inline void Block::forbid(int val) throw (Error) {
  if (!(val > 0 && val <= GRID_SIDE))
    throw std::string("Invalid forbid value");
    throw Error("Invalid forbid value.", EXIT_INV_VAL);
  if (value_ == val)
    throw Error("Try to forbid whereas case is set.", EXIT_INV_GRID);
  if (value_ != 0)
    throw std::string("Try to forbid whereas case is set");
    return;
  forbidden_[val - 1] = true;
  if (forbidden_count() == GRID_SIDE)
    throw std::string("All possibilities are forbidden.");
    throw Error("All possibilities are forbidden.", EXIT_INV_GRID);
}

inline std::ostream &operator<<(std::ostream &stream, const Block &blk) {
inline ostream &operator<<(ostream &stream, const Block &blk) {
  if (blk.value_ == 0)
    stream << " ";
  else

src/error.cc

0 → 100644
+68 −0
Original line number Diff line number Diff line
#include "sudoku.hh"

Error::Error(int v)
{
  val_ = v;
}

Error::Error(const string s, int i)
{
  val_ = i;
  msg_ << s;
}

Error::Error(const Error &e)
{
  val_ = e.val_;
  msg_ << e.msg_.str();
}

string Error::message() const
{
  return msg_.str();
}

int Error::code() const
{
  return val_;
}

void Error::code(int v)
{
  val_ = v;
}

Error &Error::operator=(const Error &rhs)
{
  val_ = rhs.val_;
  msg_.str("");
  msg_ << rhs.msg_.str();
  return *this;
}

ostream &operator<<(ostream &o, const Error &e)
{
  o << e.msg_.str();
  return o;
}

Error &operator<<(Error &e, int val)
{
  e.msg_ << val;
  return e;
}

Error &operator<<(Error &e, const string &s)
{
  e.msg_ << s;
  return e;
}

Error &operator>>(Error &e, const string &s)
{
  string buf = s + e.msg_.str();

  e.msg_.str("");
  e.msg_ << buf;
  return e;
}
Loading