Nsound  0.9.4
Macros.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // $Id: Macros.h 912 2015-07-26 00:50:29Z weegreenblobbie $
4 //
5 // Nsound is a C++ library and Python module for audio synthesis featuring
6 // dynamic digital filters. Nsound lets you easily shape waveforms and write
7 // to disk or plot them. Nsound aims to be as powerful as Csound but easy to
8 // use.
9 //
10 // Copyright (c) 2004-Present Nick Hilton
11 //
12 // weegreenblobbie_yahoo_com (replace '_' with '@' and '.')
13 //
14 //-----------------------------------------------------------------------------
15 
16 //-----------------------------------------------------------------------------
17 //
18 // This program is free software; you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation; either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 // This program is distributed in the hope that it will be useful,
24 // but WITHOUT ANY WARRANTY; without even the implied warranty of
25 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 // GNU Library General Public License for more details.
27 //
28 // You should have received a copy of the GNU General Public License
29 // along with this program; if not, write to the Free Software
30 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 //
32 //-----------------------------------------------------------------------------
33 #ifndef _NSOUND_MACROS_H_
34 #define _NSOUND_MACROS_H_
35 
36 #define M_LINE_PREFIX __FILE__ << ":" << __LINE__ << ": "
37 #define M_PRINT_LINE printf("%s:%4d: ", __FILE__, __LINE__)
38 
39 // Round a to nearest higher multiple of b
40 #define M_ROUND_UP(a, b) ((a % b != 0) ? (a - a % b + b) : a)
41 
42 // Fancy float32 round function to nearst N decimal places.
43 #define M_ROUND_FLOAT32(f, N) (floorf((f) * 1.0E##N + 0.5f) / 1.0E##N)
44 
45 #define M_ABS(x) ((x) < 0 ? -(x) : (x))
46 #define M_MAX(x, y) ((x) > (y) ? (x) : (y))
47 #define M_MIN(x, y) ((x) < (y) ? (x) : (y))
48 #define M_SQUARE(x) ((x) * (x))
49 
50 
51 namespace Nsound
52 {
53 
54 inline void __throw__(const std::string & message)
55 {
56  std::cerr << message << std::endl;
57  std::cerr.flush();
58  throw Nsound::Exception(message);
59 }
60 
61 };
62 
63 
64 #define M_CHECK_PTR(ptr) \
65  if((ptr) == NULL) \
66  { \
67  std::stringstream ss; \
68  ss << M_LINE_PREFIX \
69  << "FATAL ERROR: " \
70  << #ptr \
71  << " is NULL"; \
72  Nsound::__throw__(ss.str()); \
73  }
74 
75 
76 #define M_ASSERT_VALUE(a, op, value) \
77  if(! ((a) op (value)) ) \
78  { \
79  std::stringstream ss; \
80  ss << M_LINE_PREFIX \
81  << "FATAL ERROR: " \
82  << #a \
83  << " " #op " " \
84  << #value \
85  << " condition not met " \
86  << "(" \
87  << (a) \
88  << " " #op " " \
89  << (value) \
90  << ")"; \
91  Nsound::__throw__(ss.str()); \
92  }
93 
94 
95 #define M_ASSERT_MSG(expr, message) \
96  if(! (expr) ) \
97  { \
98  std::stringstream ss; \
99  ss << M_LINE_PREFIX \
100  << "Asertion Failed: " \
101  << #expr \
102  << " : " \
103  << message; \
104  Nsound::__throw__(ss.str()); \
105  }
106 
107 
108 #define M_THROW(message) \
109  { \
110  std::stringstream ss; \
111  ss << M_LINE_PREFIX \
112  << message; \
113  Nsound::__throw__(ss.str()); \
114  }
115 
116 #endif
117 
118 // :mode=c++: jEdit modeline
void __throw__(const std::string &message)
Definition: Macros.h:54