1 #ifndef XPARAM_REG_MACROS_H
2 #define XPARAM_REG_MACROS_H
3 
4 /*	Copyright (C) 2001,2002,2003 Ronnie Maor and Michael Brand
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this software; see the file COPYING.  If not, write to
18  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  * As a special exception, the copyright holders give permission
21  * for additional uses of the text contained in its release of XPARAM.
22  *
23  * The exception is that, if you link the XPARAM library with other files
24  * to produce an executable, this does not by itself cause the
25  * resulting executable to be covered by the GNU General Public License.
26  * Your use of that executable is in no way restricted on account of
27  * linking the XPARAM library code into it.
28  *
29  * This exception does not however invalidate any other reasons why
30  * the executable file might be covered by the GNU General Public License.
31  *
32  * If you write modifications of your own for XPARAM, it is your choice
33  * whether to permit this exception to apply to your modifications.
34  * If you do not wish that, delete this exception notice.
35  */
36 
37 /*
38  * Macros that make it easier to run code when program/library loads
39  */
40 
41 #include <cstdlib>
42 #include <exception>
43 #include <iostream>
44 #include "xp_config.h"
45 
46 /*
47 This is what we want to get:
48 
49 namespace {
50 namespace L##__LINE__ {
51 	class GlobalCode {
52 		public:
53 		GlobalCode() {
54 			try {
55 				// user code here;
56 			}
57 			catch(std::exception& ex) {
58 				std::cerr << "Error during global initialization - "
59 					<< std::endl << ex.what() << std::endl;
60 				exit(-1);
61 			}
62 			catch(...) {
63 				std::cerr << "Error during global initialization"
64 						  << std::endl;
65 				exit(-1);
66 			}
67 		}
68 	};
69 
70 	GlobalCode global_code_instance;
71 } // end line namespace
72 } // end annonymous namespace
73 */
74 
75 #define APPEND2(x,y) x##y
76 #define APPEND(x,y) APPEND2(x,y)
77 
78 #define PARAM_BEGIN_REG \
79 namespace { \
80 namespace APPEND(L,__LINE__) { \
81 class GlobalCode { \
82   public: \
83     GlobalCode() { \
84 		try {
85 
86 
87 #define PARAM_END_REG \
88 			} \
89 			catch(std::exception& ex) { \
90 				std::cerr << "Error during global initialization - " \
91 					<< std::endl << ex.what() << std::endl; \
92 				exit(-1); \
93 			} \
94 			catch(...) { \
95 				std::cerr << "Error during global initialization" \
96 					<< std::endl; \
97 				exit(-1); \
98 			} \
99 		} \
100 	}; \
101 	GlobalCode global_code_instance; \
102 } \
103 }
104 
105 
106 #endif // XPARAM_REG_MACROS_H
107 
108 
109