All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
Console.h
00001 /*********************************************************************
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 the Willow Garage 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 
00035 /* Author: Ioan Sucan */
00036 
00037 #ifndef OMPL_UTIL_CONSOLE_
00038 #define OMPL_UTIL_CONSOLE_
00039 
00040 #include <string>
00041 #include <cstdarg>
00042 
00043 namespace ompl
00044 {
00045 
00048     namespace msg
00049     {
00050 
00055         class Interface
00056         {
00057         public:
00058 
00062             explicit
00063             Interface(const std::string &prefix = "");
00064             virtual ~Interface(void);
00065 
00068             void setPrefix(const std::string &prefix);
00069 
00071             const std::string& getPrefix(void) const;
00072 
00074             void inform(const std::string &text) const;
00075 
00077             void warn(const std::string &text) const;
00078 
00080             void error(const std::string &text) const;
00081 
00083             void debug(const std::string &text) const;
00084 
00086             void inform(const char *msg, ...) const;
00087 
00089             void warn(const char *msg, ...) const;
00090 
00092             void error(const char *msg, ...) const;
00093 
00095             void debug(const char *msg, ...) const;
00096 
00097         protected:
00098 
00100             std::string prefix_;
00101         };
00102 
00111         class OutputHandler
00112         {
00113         public:
00114 
00115             OutputHandler(void)
00116             {
00117             }
00118 
00119             virtual ~OutputHandler(void)
00120             {
00121             }
00122 
00124             virtual void error(const std::string &text) = 0;
00125 
00127             virtual void warn(const std::string &text) = 0;
00128 
00130             virtual void inform(const std::string &text) = 0;
00131 
00133             virtual void debug(const std::string &text) = 0;
00134         };
00135 
00138         class OutputHandlerSTD : public OutputHandler
00139         {
00140         public:
00141 
00142             OutputHandlerSTD(void) : OutputHandler()
00143             {
00144             }
00145 
00146             virtual void error(const std::string &text);
00147 
00148             virtual void warn(const std::string &text);
00149 
00150             virtual void inform(const std::string &text);
00151 
00152             virtual void debug(const std::string &text);
00153 
00154         };
00155 
00157         class OutputHandlerFile : public OutputHandler
00158         {
00159         public:
00160 
00162             OutputHandlerFile(const char *filename);
00163 
00164             virtual ~OutputHandlerFile(void);
00165 
00166             virtual void error(const std::string &text);
00167 
00168             virtual void warn(const std::string &text);
00169 
00170             virtual void inform(const std::string &text);
00171 
00172             virtual void debug(const std::string &text);
00173 
00174         private:
00175 
00177             FILE *file_;
00178 
00179         };
00180 
00182         void noOutputHandler(void);
00183 
00185         void restorePreviousOutputHandler(void);
00186 
00188         void useOutputHandler(OutputHandler *oh);
00189 
00191         OutputHandler* getOutputHandler(void);
00192     }
00193 
00194 }
00195 
00196 #endif