Ignore:
Timestamp:
Mar 19, 2009, 1:35:47 PM (13 years ago)
Author:
Peter
Message:

fixes #504. Also added pp macro YAT_ASSERT that calls yat_assert with an appropriate msg

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/utility/yat_assert.h

    r1797 r1875  
    55/*
    66  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
     7  Copyright (C) 2009 Peter Johansson
    78
    89  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    2223*/
    2324
     25#include <sstream>
     26#include <stdexcept>
    2427#include <string>
    2528
     
    3639     X is thrown using constructor X(\a msg ).
    3740   */
    38   template<class X> inline void yat_assert(bool assertion, std::string msg="")
     41  template<class X> inline void yat_assert(bool assertion, std::string msg)
    3942#ifdef YAT_DEBUG
    4043  { if (!assertion) throw X(std::string("yat_assert:")+msg); }
     
    4447
    4548}}}
     49
     50
     51#ifdef YAT_DEBUG
     52// Peter, this is a bit clumsy, but I wanna keep the stringstream
     53// invisible outside macro, or multiple calls to macro would result in
     54// multiple declaration of the stringstream. Also the macro is
     55// supposed to be called with a trailing `;', and that's why we need
     56// to end with something that allows that.
     57#define YAT_ASSERT(expr) \
     58  if (expr) { \
     59    std::stringstream yat_msg_;                                 \
     60    yat_msg_ << __FILE__ << ":" << __LINE__ << " failed assertion `" \
     61             << #expr << "'";                                           \
     62    theplu::yat::utility::yat_assert<std::runtime_error>(expr,          \
     63                                                         yat_msg_.str()); \
     64  } \
     65  else theplu::yat::utility::yat_assert<std::runtime_error>(expr, "")
     66#else
     67// This could be anything empty, but why not use the empty yat_assert
     68#define YAT_ASSERT(expr) theplu::yat::utility::yat_assert<std::runtime_error>(expr, "")
     69#endif
    4670  /*
    4771  */
Note: See TracChangeset for help on using the changeset viewer.