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 \
35  "The macro __COUNTER__ is not defined! It will be defined as MACRO_COUNTER_NOT_DEFINED"
36 #define __COUNTER__ MACRO_COUNTER_NOT_DEFINED
37 #endif
38 
39 /**
40  * @brief creates a identifier with a given prefix.
41  * The prefix may help when the variable shows up in compiler output.
42  *
43  * can be used like this:
44  * \code
45  * void foo()
46  * {
47  * std::mutex mtx;
48  * std::lock_guard<std::mutex> ARMARX_ANONYMOUS_VARIABLE_WITH_PREFIX(guard)(mtx);
49  * //guarded section
50  * }
51  * \endcode
52  * @see ARMARX_ANONYMOUS_VARIABLE
53  * \ingroup CPreprocessor
54  */
55 #define ARMARX_ANONYMOUS_VARIABLE_WITH_PREFIX(pre) \
56  ARMARX_CONCATENATE_5(pre, _IN_LINE_, __LINE__, _WITH_COUNT_, __COUNTER__)
57 
58 /**
59  * @brief creates a identifier.
60  * The created identifier contains the linenumber and is unique per translation unit.
61  * This makro's usecase are other macros, where a variable for RAII has to be created in the enclosing scope.
62  *
63  * can be used like this:
64  * \code
65  * void foo()
66  * {
67  * std::mutex mtx;
68  * std::lock_guard<std::mutex> ARMARX_ANONYMOUS_VARIABLE(mtx);
69  * //guarded section
70  * }
71  * \endcode
72  * \ingroup CPreprocessor
73  */
74 #define ARMARX_ANONYMOUS_VARIABLE ARMARX_ANONYMOUS_VARIABLE_WITH_PREFIX(armarxAnonymousVariable)
concat.h