src/core/abort.h
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Sat, 04 Jul 2009 08:15:48 +0200
changeset 4654 2eaebe77d66b
parent 3781 0eea20a7b592
permissions -rw-r--r--
Added tag ns-3.5 for changeset c975274c9707
mathieu@3781
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
mathieu@3781
     2
/*
mathieu@3781
     3
 * Copyright (c) 2008 INRIA
mathieu@3781
     4
 *
mathieu@3781
     5
 * This program is free software; you can redistribute it and/or modify
mathieu@3781
     6
 * it under the terms of the GNU General Public License version 2 as
mathieu@3781
     7
 * published by the Free Software Foundation;
mathieu@3781
     8
 *
mathieu@3781
     9
 * This program is distributed in the hope that it will be useful,
mathieu@3781
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
mathieu@3781
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
mathieu@3781
    12
 * GNU General Public License for more details.
mathieu@3781
    13
 *
mathieu@3781
    14
 * You should have received a copy of the GNU General Public License
mathieu@3781
    15
 * along with this program; if not, write to the Free Software
mathieu@3781
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
mathieu@3781
    17
 *
mathieu@3781
    18
 */
mathieu@3781
    19
#ifndef NS3_ABORT_H
mathieu@3781
    20
#define NS3_ABORT_H
mathieu@3781
    21
mathieu@3781
    22
#include "fatal-error.h"
mathieu@3781
    23
craigdo@3937
    24
#define NS_ABORT_MSG(msg)                                       \
craigdo@3937
    25
  do {								\
craigdo@3937
    26
    std::cerr << "file=" << __FILE__ <<                         \
craigdo@3937
    27
      ", line=" << __LINE__ << ", abort, msg=\"" <<             \
craigdo@3937
    28
      msg << "\"" << std::endl;                                 \
craigdo@3937
    29
    int *a = 0;                                                 \
craigdo@3937
    30
    *a = 0;							\
craigdo@3937
    31
  } while (false)
craigdo@3937
    32
craigdo@3937
    33
mathieu@3781
    34
#define NS_ABORT_IF(cond)					\
mathieu@3781
    35
  do {								\
mathieu@3781
    36
    if (cond)							\
mathieu@3781
    37
      {								\
mathieu@3781
    38
	std::cerr << "file=" << __FILE__ <<			\
mathieu@3781
    39
	  ", line=" << __LINE__ << ", abort on=\""#cond <<	\
mathieu@3781
    40
            "\"" << std::endl;                                  \
mathieu@3781
    41
	int *a = 0;						\
mathieu@3781
    42
	*a = 0;							\
mathieu@3781
    43
      }								\
mathieu@3781
    44
  } while (false)
mathieu@3781
    45
mathieu@3781
    46
#define NS_ABORT_MSG_IF(cond, msg)				\
mathieu@3781
    47
  do {								\
mathieu@3781
    48
    if (cond)							\
mathieu@3781
    49
      {								\
mathieu@3781
    50
	std::cerr << "file=" << __FILE__ <<			\
mathieu@3781
    51
	  ", line=" << __LINE__ << ", abort on=\""#cond <<	\
mathieu@3781
    52
	  "\", msg=\"" << msg << "\"" << std::endl;		\
mathieu@3781
    53
	int *a = 0;						\
mathieu@3781
    54
	*a = 0;							\
mathieu@3781
    55
      }								\
mathieu@3781
    56
  } while (false)
mathieu@3781
    57
mathieu@3781
    58
#define NS_ABORT_UNLESS(cond)				\
mathieu@3781
    59
  NS_ABORT_IF(!(cond))
mathieu@3781
    60
mathieu@3781
    61
#define NS_ABORT_MSG_UNLESS(cond, msg)			\
mathieu@3781
    62
  NS_ABORT_MSG_IF(!(cond),msg)
mathieu@3781
    63
mathieu@3781
    64
#endif /* NS3_ABORT_H */