generate_macros.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 # Software License Agreement (BSD License)
00003 #
00004 # Copyright (c) 2008, Willow Garage, Inc.
00005 # All rights reserved.
00006 #
00007 # Redistribution and use in source and binary forms, with or without
00008 # modification, are permitted provided that the following conditions
00009 # are met:
00010 #
00011 #  * Redistributions of source code must retain the above copyright
00012 #    notice, this list of conditions and the following disclaimer.
00013 #  * Redistributions in binary form must reproduce the above
00014 #    copyright notice, this list of conditions and the following
00015 #    disclaimer in the documentation and/or other materials provided
00016 #    with the distribution.
00017 #  * Neither the name of Willow Garage, Inc. nor the names of its
00018 #    contributors may be used to endorse or promote products derived
00019 #    from this software without specific prior written permission.
00020 #
00021 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 # POSSIBILITY OF SUCH DAMAGE.
00033 
00034 import sys
00035 import rospkg
00036 
00037 rospack = rospkg.RosPack()
00038 base_path = rospack.get_path('rosconsole')
00039 
00040 def add_macro(f, caps_name, enum_name):
00041     f.write('#if (ROSCONSOLE_MIN_SEVERITY > ROSCONSOLE_SEVERITY_%s)\n' %(caps_name))
00042     f.write('#define ROS_%s(...)\n' %(caps_name))
00043     f.write('#define ROS_%s_STREAM(args)\n' %(caps_name))
00044     f.write('#define ROS_%s_NAMED(name, ...)\n' %(caps_name))
00045     f.write('#define ROS_%s_STREAM_NAMED(name, args)\n' %(caps_name))
00046     f.write('#define ROS_%s_COND(cond, ...)\n' %(caps_name))
00047     f.write('#define ROS_%s_STREAM_COND(cond, args)\n' %(caps_name))
00048     f.write('#define ROS_%s_COND_NAMED(cond, name, ...)\n' %(caps_name))
00049     f.write('#define ROS_%s_STREAM_COND_NAMED(cond, name, args)\n' %(caps_name))
00050     
00051     f.write('#define ROS_%s_ONCE(...)\n' %(caps_name))
00052     f.write('#define ROS_%s_STREAM_ONCE(args)\n' %(caps_name))
00053     f.write('#define ROS_%s_ONCE_NAMED(name, ...)\n' %(caps_name))
00054     f.write('#define ROS_%s_STREAM_ONCE_NAMED(name, args)\n' %(caps_name))
00055     f.write('#define ROS_%s_THROTTLE(rate, ...)\n' %(caps_name))
00056     f.write('#define ROS_%s_STREAM_THROTTLE(rate, args)\n' %(caps_name))
00057     f.write('#define ROS_%s_THROTTLE_NAMED(rate, name, ...)\n' %(caps_name))
00058     f.write('#define ROS_%s_STREAM_THROTTLE_NAMED(rate, name, args)\n' %(caps_name))
00059     
00060     f.write('#define ROS_%s_FILTER(filter, ...)\n' %(caps_name))
00061     f.write('#define ROS_%s_STREAM_FILTER(filter, args)\n' %(caps_name))
00062     f.write('#define ROS_%s_FILTER_NAMED(filter, name, ...)\n' %(caps_name))
00063     f.write('#define ROS_%s_STREAM_FILTER_NAMED(filter, name, args)\n' %(caps_name))
00064     f.write('#else\n')
00065     f.write('#define ROS_%s(...) ROS_LOG(::ros::console::levels::%s, ROSCONSOLE_DEFAULT_NAME, __VA_ARGS__)\n' %(caps_name, enum_name))
00066     f.write('#define ROS_%s_STREAM(args) ROS_LOG_STREAM(::ros::console::levels::%s, ROSCONSOLE_DEFAULT_NAME, args)\n' %(caps_name, enum_name))
00067     f.write('#define ROS_%s_NAMED(name, ...) ROS_LOG(::ros::console::levels::%s, std::string(ROSCONSOLE_NAME_PREFIX) + "." + name, __VA_ARGS__)\n' %(caps_name, enum_name))
00068     f.write('#define ROS_%s_STREAM_NAMED(name, args) ROS_LOG_STREAM(::ros::console::levels::%s, std::string(ROSCONSOLE_NAME_PREFIX) + "." + name, args)\n' %(caps_name, enum_name))
00069     f.write('#define ROS_%s_COND(cond, ...) ROS_LOG_COND(cond, ::ros::console::levels::%s, ROSCONSOLE_DEFAULT_NAME, __VA_ARGS__)\n' %(caps_name, enum_name))
00070     f.write('#define ROS_%s_STREAM_COND(cond, args) ROS_LOG_STREAM_COND(cond, ::ros::console::levels::%s, ROSCONSOLE_DEFAULT_NAME, args)\n' %(caps_name, enum_name))
00071     f.write('#define ROS_%s_COND_NAMED(cond, name, ...) ROS_LOG_COND(cond, ::ros::console::levels::%s, std::string(ROSCONSOLE_NAME_PREFIX) + "." + name, __VA_ARGS__)\n' %(caps_name, enum_name))
00072     f.write('#define ROS_%s_STREAM_COND_NAMED(cond, name, args) ROS_LOG_STREAM_COND(cond, ::ros::console::levels::%s, std::string(ROSCONSOLE_NAME_PREFIX) + "." + name, args)\n' %(caps_name, enum_name))
00073     
00074     f.write('#define ROS_%s_ONCE(...) ROS_LOG_ONCE(::ros::console::levels::%s, ROSCONSOLE_DEFAULT_NAME, __VA_ARGS__)\n' %(caps_name, enum_name))
00075     f.write('#define ROS_%s_STREAM_ONCE(args) ROS_LOG_STREAM_ONCE(::ros::console::levels::%s, ROSCONSOLE_DEFAULT_NAME, args)\n' %(caps_name, enum_name))
00076     f.write('#define ROS_%s_ONCE_NAMED(name, ...) ROS_LOG_ONCE(::ros::console::levels::%s, std::string(ROSCONSOLE_NAME_PREFIX) + "." + name, __VA_ARGS__)\n' %(caps_name, enum_name))
00077     f.write('#define ROS_%s_STREAM_ONCE_NAMED(name, args) ROS_LOG_STREAM_ONCE(::ros::console::levels::%s, std::string(ROSCONSOLE_NAME_PREFIX) + "." + name, args)\n' %(caps_name, enum_name))
00078     
00079     f.write('#define ROS_%s_THROTTLE(rate, ...) ROS_LOG_THROTTLE(rate, ::ros::console::levels::%s, ROSCONSOLE_DEFAULT_NAME, __VA_ARGS__)\n' %(caps_name, enum_name))
00080     f.write('#define ROS_%s_STREAM_THROTTLE(rate, args) ROS_LOG_STREAM_THROTTLE(rate, ::ros::console::levels::%s, ROSCONSOLE_DEFAULT_NAME, args)\n' %(caps_name, enum_name))
00081     f.write('#define ROS_%s_THROTTLE_NAMED(rate, name, ...) ROS_LOG_THROTTLE(rate, ::ros::console::levels::%s, std::string(ROSCONSOLE_NAME_PREFIX) + "." + name, __VA_ARGS__)\n' %(caps_name, enum_name))
00082     f.write('#define ROS_%s_STREAM_THROTTLE_NAMED(rate, name, args) ROS_LOG_STREAM_THROTTLE(rate, ::ros::console::levels::%s, std::string(ROSCONSOLE_NAME_PREFIX) + "." + name, args)\n' %(caps_name, enum_name))
00083     
00084     f.write('#define ROS_%s_FILTER(filter, ...) ROS_LOG_FILTER(filter, ::ros::console::levels::%s, ROSCONSOLE_DEFAULT_NAME, __VA_ARGS__)\n' %(caps_name, enum_name))
00085     f.write('#define ROS_%s_STREAM_FILTER(filter, args) ROS_LOG_STREAM_FILTER(filter, ::ros::console::levels::%s, ROSCONSOLE_DEFAULT_NAME, args)\n' %(caps_name, enum_name))
00086     f.write('#define ROS_%s_FILTER_NAMED(filter, name, ...) ROS_LOG_FILTER(filter, ::ros::console::levels::%s, std::string(ROSCONSOLE_NAME_PREFIX) + "." + name, __VA_ARGS__)\n' %(caps_name, enum_name))
00087     f.write('#define ROS_%s_STREAM_FILTER_NAMED(filter, name, args) ROS_LOG_STREAM_FILTER(filter, ::ros::console::levels::%s, std::string(ROSCONSOLE_NAME_PREFIX) + "." + name, args)\n' %(caps_name, enum_name))
00088     f.write('#endif\n\n')
00089 
00090 f = open('%s/include/rosconsole/macros_generated.h' %(base_path), 'w')
00091 
00092 f.write("// !!!!!!!!!!!!!!!!!!!!!!! This is a generated file, do not edit manually\n\n")
00093 
00094 f.write('/*\n')
00095 f.write(' * Copyright (c) 2008, Willow Garage, Inc.\n')
00096 f.write(' * All rights reserved.\n')
00097 f.write(' *\n')
00098 f.write(' * Redistribution and use in source and binary forms, with or without\n')
00099 f.write(' * modification, are permitted provided that the following conditions are met:\n')
00100 f.write(' *\n')
00101 f.write(' *     * Redistributions of source code must retain the above copyright\n')
00102 f.write(' *       notice, this list of conditions and the following disclaimer.\n')
00103 f.write(' *     * Redistributions in binary form must reproduce the above copyright\n')
00104 f.write(' *       notice, this list of conditions and the following disclaimer in the\n')
00105 f.write(' *       documentation and/or other materials provided with the distribution.\n')
00106 f.write(' *     * Neither the name of Willow Garage, Inc. nor the names of its\n')
00107 f.write(' *       contributors may be used to endorse or promote products derived from\n')
00108 f.write(' *       this software without specific prior written permission.\n')
00109 f.write(' *\n')
00110 f.write(' * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\n')
00111 f.write(' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n')
00112 f.write(' * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n')
00113 f.write(' * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE\n')
00114 f.write(' * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n')
00115 f.write(' * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n')
00116 f.write(' * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n')
00117 f.write(' * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n')
00118 f.write(' * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n')
00119 f.write(' * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n')
00120 f.write(' * POSSIBILITY OF SUCH DAMAGE.\n')
00121 f.write(' */\n\n')
00122 
00123 add_macro(f, "DEBUG", "Debug")
00124 add_macro(f, "INFO", "Info")
00125 add_macro(f, "WARN", "Warn")
00126 add_macro(f, "ERROR", "Error")
00127 add_macro(f, "FATAL", "Fatal")
00128 
00129 
00130 
00131 


rosconsole
Author(s): Josh Faust
autogenerated on Mon Oct 6 2014 11:46:34