anonymous_variable.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package ArmarXCore
19  * @author Raphael Grimm ( raphael dot grimm at kit dot edu)
20  * @date 2016
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #pragma once
25 
26 #include "concat.h"
27 
28 /**
29  * \defgroup CPreprocessor
30  * \ingroup core-utility
31  */
32 
33 #ifndef __COUNTER__
34 #pragma message "The macro __COUNTER__ is not defined! It will be defined as MACRO_COUNTER_NOT_DEFINED"
35 #define __COUNTER__ MACRO_COUNTER_NOT_DEFINED
36 #endif
37 
38 /**
39  * @brief creates a identifier with a given prefix.
40  * The prefix may help when the variable shows up in compiler output.
41  *
42  * can be used like this:
43  * \code
44  * void foo()
45  * {
46  * std::mutex mtx;
47  * std::lock_guard<std::mutex> ARMARX_ANONYMOUS_VARIABLE_WITH_PREFIX(guard)(mtx);
48  * //guarded section
49  * }
50  * \endcode
51  * @see ARMARX_ANONYMOUS_VARIABLE
52  * \ingroup CPreprocessor
53  */
54 #define ARMARX_ANONYMOUS_VARIABLE_WITH_PREFIX(pre) ARMARX_CONCATENATE_5(pre, _IN_LINE_, __LINE__, _WITH_COUNT_, __COUNTER__)
55 
56 /**
57  * @brief creates a identifier.
58  * The created identifier contains the linenumber and is unique per translation unit.
59  * This makro's usecase are other macros, where a variable for RAII has to be created in the enclosing scope.
60  *
61  * can be used like this:
62  * \code
63  * void foo()
64  * {
65  * std::mutex mtx;
66  * std::lock_guard<std::mutex> ARMARX_ANONYMOUS_VARIABLE(mtx);
67  * //guarded section
68  * }
69  * \endcode
70  * \ingroup CPreprocessor
71  */
72 #define ARMARX_ANONYMOUS_VARIABLE ARMARX_ANONYMOUS_VARIABLE_WITH_PREFIX(armarxAnonymousVariable)
73 
concat.h