generate_macros.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 # Adapted from rosconsole's generate_macros.py (license below)
3 
4 # Software License Agreement (BSD License)
5 #
6 # Copyright (c) 2008, Willow Garage, Inc.
7 # All rights reserved.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
11 # are met:
12 #
13 # * Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 # * Redistributions in binary form must reproduce the above
16 # copyright notice, this list of conditions and the following
17 # disclaimer in the documentation and/or other materials provided
18 # with the distribution.
19 # * Neither the name of Willow Garage, Inc. nor the names of its
20 # contributors may be used to endorse or promote products derived
21 # from this software without specific prior written permission.
22 #
23 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 # POSSIBILITY OF SUCH DAMAGE.
35 
36 import os
37 import sys
38 
39 def add_macro(f, caps_name, enum_name):
40  f.write('#if (ROSCONSOLE_MIN_SEVERITY > ROSCONSOLE_SEVERITY_%s)\n' %(caps_name))
41  f.write('#define ROSFMT_%s(...)\n' %(caps_name))
42  f.write('#define ROSFMT_%s_NAMED(name, ...)\n' %(caps_name))
43  f.write('#define ROSFMT_%s_COND(cond, ...)\n' %(caps_name))
44  f.write('#define ROSFMT_%s_COND_NAMED(cond, name, ...)\n' %(caps_name))
45 
46  f.write('#define ROSFMT_%s_ONCE(...)\n' %(caps_name))
47  f.write('#define ROSFMT_%s_ONCE_NAMED(name, ...)\n' %(caps_name))
48  f.write('#define ROSFMT_%s_THROTTLE(period, ...)\n' %(caps_name))
49  f.write('#define ROSFMT_%s_THROTTLE_NAMED(period, name, ...)\n' %(caps_name))
50  f.write('#define ROSFMT_%s_DELAYED_THROTTLE(period, ...)\n' %(caps_name))
51  f.write('#define ROSFMT_%s_DELAYED_THROTTLE_NAMED(period, name, ...)\n' %(caps_name))
52 
53  f.write('#define ROSFMT_%s_FILTER(filter, ...)\n' %(caps_name))
54  f.write('#define ROSFMT_%s_FILTER_NAMED(filter, name, ...)\n' %(caps_name))
55  f.write('#else\n')
56  f.write('#define ROSFMT_%s(...) ROSFMT_LOG(::ros::console::levels::%s, ROSCONSOLE_DEFAULT_NAME, __VA_ARGS__)\n' %(caps_name, enum_name))
57  f.write('#define ROSFMT_%s_NAMED(name, ...) ROSFMT_LOG(::ros::console::levels::%s, std::string(ROSCONSOLE_NAME_PREFIX) + "." + name, __VA_ARGS__)\n' %(caps_name, enum_name))
58  f.write('#define ROSFMT_%s_COND(cond, ...) ROSFMT_LOG_COND(cond, ::ros::console::levels::%s, ROSCONSOLE_DEFAULT_NAME, __VA_ARGS__)\n' %(caps_name, enum_name))
59  f.write('#define ROSFMT_%s_COND_NAMED(cond, name, ...) ROSFMT_LOG_COND(cond, ::ros::console::levels::%s, std::string(ROSCONSOLE_NAME_PREFIX) + "." + name, __VA_ARGS__)\n' %(caps_name, enum_name))
60 
61  f.write('#define ROSFMT_%s_ONCE(...) ROSFMT_LOG_ONCE(::ros::console::levels::%s, ROSCONSOLE_DEFAULT_NAME, __VA_ARGS__)\n' %(caps_name, enum_name))
62  f.write('#define ROSFMT_%s_ONCE_NAMED(name, ...) ROSFMT_LOG_ONCE(::ros::console::levels::%s, std::string(ROSCONSOLE_NAME_PREFIX) + "." + name, __VA_ARGS__)\n' %(caps_name, enum_name))
63 
64  f.write('#define ROSFMT_%s_THROTTLE(period, ...) ROSFMT_LOG_THROTTLE(period, ::ros::console::levels::%s, ROSCONSOLE_DEFAULT_NAME, __VA_ARGS__)\n' %(caps_name, enum_name))
65  f.write('#define ROSFMT_%s_THROTTLE_NAMED(period, name, ...) ROSFMT_LOG_THROTTLE(period, ::ros::console::levels::%s, std::string(ROSCONSOLE_NAME_PREFIX) + "." + name, __VA_ARGS__)\n' %(caps_name, enum_name))
66 
67  f.write('#define ROSFMT_%s_DELAYED_THROTTLE(period, ...) ROSFMT_LOG_DELAYED_THROTTLE(period, ::ros::console::levels::%s, ROSCONSOLE_DEFAULT_NAME, __VA_ARGS__)\n' %(caps_name, enum_name))
68  f.write('#define ROSFMT_%s_DELAYED_THROTTLE_NAMED(period, name, ...) ROSFMT_LOG_DELAYED_THROTTLE(period, ::ros::console::levels::%s, std::string(ROSCONSOLE_NAME_PREFIX) + "." + name, __VA_ARGS__)\n' %(caps_name, enum_name))
69 
70  f.write('#define ROSFMT_%s_FILTER(filter, ...) ROSFMT_LOG_FILTER(filter, ::ros::console::levels::%s, ROSCONSOLE_DEFAULT_NAME, __VA_ARGS__)\n' %(caps_name, enum_name))
71  f.write('#define ROSFMT_%s_FILTER_NAMED(filter, name, ...) ROSFMT_LOG_FILTER(filter, ::ros::console::levels::%s, std::string(ROSCONSOLE_NAME_PREFIX) + "." + name, __VA_ARGS__)\n' %(caps_name, enum_name))
72  f.write('#endif\n\n')
73 
74 f = open(os.path.join(os.path.dirname(__file__), '../include/rosfmt/macros_generated.h'), 'w')
75 
76 f.write("// !!!!!!!!!!!!!!!!!!!!!!! This is a generated file, do not edit manually\n\n")
77 
78 add_macro(f, "DEBUG", "Debug")
79 add_macro(f, "INFO", "Info")
80 add_macro(f, "WARN", "Warn")
81 add_macro(f, "ERROR", "Error")
82 add_macro(f, "FATAL", "Fatal")
def add_macro(f, caps_name, enum_name)


rosfmt
Author(s):
autogenerated on Wed May 15 2019 02:54:11