~ubuntu-branches/ubuntu/wily/openms/wily

« back to all changes in this revision

Viewing changes to include/OpenMS/CONCEPT/Macros.h

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2012-11-12 15:58:12 UTC
  • Revision ID: package-import@ubuntu.com-20121112155812-vr15wtg9b50cuesg
Tags: upstream-1.9.0
ImportĀ upstreamĀ versionĀ 1.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- mode: C++; tab-width: 2; -*-
 
2
// vi: set ts=2:
 
3
//
 
4
// --------------------------------------------------------------------------
 
5
//                   OpenMS Mass Spectrometry Framework
 
6
// --------------------------------------------------------------------------
 
7
//  Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
 
8
//
 
9
//  This library is free software; you can redistribute it and/or
 
10
//  modify it under the terms of the GNU Lesser General Public
 
11
//  License as published by the Free Software Foundation; either
 
12
//  version 2.1 of the License, or (at your option) any later version.
 
13
//
 
14
//  This library is distributed in the hope that it will be useful,
 
15
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
17
//  Lesser General Public License for more details.
 
18
//
 
19
//  You should have received a copy of the GNU Lesser General Public
 
20
//  License along with this library; if not, write to the Free Software
 
21
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
22
//
 
23
// --------------------------------------------------------------------------
 
24
// $Maintainer: Stephan Aiche$
 
25
// $Authors: Marc Sturm $
 
26
// --------------------------------------------------------------------------
 
27
 
 
28
#ifndef OPENMS_CONCEPT_MACROS_H
 
29
#define OPENMS_CONCEPT_MACROS_H
 
30
 
 
31
 
 
32
#include <OpenMS/config.h>
 
33
#include <OpenMS/CONCEPT/Exception.h>
 
34
 
 
35
#include <string>
 
36
#include <cstring>
 
37
 
 
38
/**
 
39
        @defgroup Conditions Condition macros
 
40
 
 
41
        @brief Macros used for to enforce preconditions and postconditions.
 
42
 
 
43
        These macros are enabled if debug info is enabled and optimization is disabled in configure.
 
44
        Otherwise they are replaced by an empty string, so they won't cost any performance.
 
45
 
 
46
        The macros throw Exception::Precondition or Exception::Postcondition respectively if the condition fails.
 
47
 
 
48
        @ingroup Concept
 
49
 
 
50
        @{
 
51
*/
 
52
 
 
53
#ifdef OPENMS_ASSERTIONS
 
54
 
 
55
/**
 
56
        @brief Precondition macro.
 
57
 
 
58
        @hideinitializer
 
59
*/
 
60
#define OPENMS_PRECONDITION(condition, message)\
 
61
        if (!(condition))\
 
62
        {\
 
63
                Exception::Precondition e(__FILE__, __LINE__, __PRETTY_FUNCTION__, #condition);\
 
64
                if (std::strcmp(message,"")!=0)\
 
65
                {\
 
66
      ::std::string tmp(e.getMessage());\
 
67
                        tmp += " ";\
 
68
                        tmp += ::std::string(message);\
 
69
                        e.setMessage(tmp);\
 
70
                }\
 
71
                throw e;\
 
72
        }\
 
73
 
 
74
/**
 
75
        @brief Postcondition macro.
 
76
 
 
77
        @hideinitializer
 
78
*/
 
79
#define OPENMS_POSTCONDITION(condition, message)\
 
80
        if (!(condition))\
 
81
        {\
 
82
                Exception::Postcondition e(__FILE__, __LINE__, __PRETTY_FUNCTION__, #condition);\
 
83
                if (std::strcmp(message,"")!=0)\
 
84
                {\
 
85
      std::string tmp(e.getMessage());\
 
86
                        tmp += " ";\
 
87
                        tmp += std::string(message);\
 
88
                        e.setMessage(tmp);\
 
89
                }\
 
90
                throw e;\
 
91
        }\
 
92
 
 
93
#else
 
94
 
 
95
/**
 
96
        @brief Precondition macro.
 
97
 
 
98
        @hideinitializer
 
99
*/
 
100
#define OPENMS_PRECONDITION(condition, message)
 
101
 
 
102
/**
 
103
        @brief Postcondition macro.
 
104
 
 
105
        @hideinitializer
 
106
*/
 
107
#define OPENMS_POSTCONDITION(condition, message)
 
108
 
 
109
#endif
 
110
 
 
111
/** @} */ // end of Conditions
 
112
 
 
113
#endif //OPENMS_CONCEPT_MACROS_H