last update 20 Sep 2009 |
00001 /* 00002 * Copyright (C) 1998-2004 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * 00006 * This file is part of the Computer Vision and Robotics Library (CVR-Lib) 00007 * 00008 * The CVR-Lib is free software; you can redistribute it and/or 00009 * modify it under the terms of the BSD License. 00010 * 00011 * All rights reserved. 00012 * 00013 * Redistribution and use in source and binary forms, with or without 00014 * modification, are permitted provided that the following conditions are met: 00015 * 00016 * 1. Redistributions of source code must retain the above copyright notice, 00017 * this list of conditions and the following disclaimer. 00018 * 00019 * 2. Redistributions in binary form must reproduce the above copyright notice, 00020 * this list of conditions and the following disclaimer in the documentation 00021 * and/or other materials provided with the distribution. 00022 * 00023 * 3. Neither the name of the authors nor the names of its contributors may be 00024 * used to endorse or promote products derived from this software without 00025 * specific prior written permission. 00026 * 00027 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00028 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00029 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00030 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00031 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00032 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00033 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00034 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00035 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00036 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00037 * POSSIBILITY OF SUCH DAMAGE. 00038 */ 00039 00040 00041 /** 00042 * \file cvrClassName.h 00043 * Defines the class className to gain the fully qualified name of 00044 * a class inherited from cvr::object. 00045 * \author Jochen Wickel 00046 * \date 01.04.99 00047 * 00048 * $Id: cvrClassName.h,v 1.5 2005/01/17 13:57:18 alvarado Exp $ 00049 */ 00050 00051 #ifndef _CVR_CLASSNAME_H_ 00052 #define _CVR_CLASSNAME_H_ 00053 00054 #include "cvrObject.h" 00055 #include <string> 00056 00057 namespace cvr { 00058 /** 00059 * Provides methods for getting the class names of cvr::objects. 00060 * 00061 * This class uses the std::string container to avoid possible 00062 * memory leaks. 00063 */ 00064 class className { 00065 public: 00066 /** 00067 * Default constructor 00068 */ 00069 className(); 00070 00071 /** 00072 * Destructor 00073 */ 00074 ~className(); 00075 00076 /** 00077 * Return the name of the given type. 00078 * 00079 * This class uses the std::typeinfo functions, but it "demangles" the 00080 * output to produce a valid C++ type name, i.e. the returned string 00081 * considers the template arguments and is usually fully qualified. 00082 * 00083 * The implementations should ensure that the returned name has the 00084 * following format: 00085 * 00086 * <namespace>::<classname>::<innerclassname>::... 00087 * 00088 * Example: 00089 * \code 00090 * cvr::boundingBox<double>::parameters 00091 * \endcode 00092 * 00093 * \warning The function returns a pointer to an internal class 00094 * member. So, the pointer is only valid for the lifetime of this 00095 * object or until the next time \c get is called, whatever occurs 00096 * first. 00097 */ 00098 static std::string get(const object* o); 00099 00100 /** 00101 * Return the name of the given object. 00102 * 00103 * @see get(const object*) 00104 */ 00105 static std::string get(const object& o); 00106 00107 /** 00108 * Return the name of the given type. 00109 * 00110 * This class uses the std::typeinfo functions, but it "demangles" the 00111 * output to produce a valid C++ type name, i.e. the returned string 00112 * considers the template arguments and is usually fully qualified. 00113 * 00114 * The implementations should ensure that the returned name has the 00115 * following format: 00116 * 00117 * <namespace>::<classname>::<innerclassname>::... 00118 * 00119 * Example: 00120 * \code 00121 * cvr::boundingBox<double>::parameters 00122 * \endcode 00123 * 00124 * 00125 * The name is returned in the result parameter. This is a much safer 00126 * method than the method returning a pointer. 00127 */ 00128 static void get(const object& o, std::string& result); 00129 00130 /** 00131 * Return the name of the given type. 00132 * 00133 * This class uses the std::typeinfo functions, but it "demangles" the 00134 * output to produce a valid C++ type name, i.e. the returned string 00135 * considers the template arguments and is usually fully qualified. 00136 * 00137 * The implementations should ensure that the returned name has the 00138 * following format: 00139 * 00140 * <namespace>::<classname>::<innerclassname>::... 00141 * 00142 * Example: 00143 * \code 00144 * cvr::boundingBox<double>::parameters 00145 * \endcode 00146 * 00147 * The name is returned in the result parameter. This is a much safer 00148 * method than the method returning a pointer. 00149 */ 00150 static void get(const object* o, std::string& result); 00151 00152 /** 00153 * Demangle 00154 * 00155 * You can use this methods to gain the name of a class that is not 00156 * inherited from cvr::object. 00157 * 00158 * The input is the one given by typeid().name() 00159 * 00160 * Example: 00161 * \code 00162 * cvr::point<float> p; 00163 * std::string typeOfP = className::demangle(typeid(p).name()); 00164 * \endcode 00165 * 00166 * \warning Remember that the pointer returned by typeid belongs to the 00167 * system. You should never delete that pointer. 00168 */ 00169 static std::string demangle(const std::string& mangled); 00170 00171 private: 00172 /** 00173 * Demangle the given string using OS/Compiler dependent code. 00174 * 00175 * This method is highly recursive, so that the current positions in the 00176 * source and destination strings have to be maintained. 00177 * 00178 * @param mangled mangled string 00179 * @param pos start position in \a mangled to be analyzed 00180 * @param demangled demangled string 00181 */ 00182 static void decode(const std::string& mangled, 00183 std::string& demangled); 00184 00185 /** 00186 * Strip name. 00187 * 00188 * All spaces are eliminated 00189 */ 00190 static void strip(std::string& complete); 00191 00192 00193 }; 00194 } 00195 00196 #endif