User Manual, Developers Guide and API Documentation

TypeInfo.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * This file is part of openWNS (open Wireless Network Simulator)
00003  * _____________________________________________________________________________
00004  *
00005  * Copyright (C) 2004-2007
00006  * Chair of Communication Networks (ComNets)
00007  * Kopernikusstr. 16, D-52074 Aachen, Germany
00008  * phone: ++49-241-80-27910,
00009  * fax: ++49-241-80-22242
00010  * email: info@openwns.org
00011  * www: http://www.openwns.org
00012  * _____________________________________________________________________________
00013  *
00014  * openWNS is free software; you can redistribute it and/or modify it under the
00015  * terms of the GNU Lesser General Public License version 2 as published by the
00016  * Free Software Foundation;
00017  *
00018  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00019  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00020  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00021  * details.
00022  *
00023  * You should have received a copy of the GNU Lesser General Public License
00024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025  *
00026  ******************************************************************************/
00027 
00028 #ifndef WNS_TYPEINFO_HPP
00029 #define WNS_TYPEINFO_HPP
00030 
00031 #include <WNS/IOutputStreamable.hpp>
00032 #include <WNS/demangle.hpp>
00033 
00034 #include <typeinfo>
00035 #include <string>
00036 
00037 namespace wns {
00041     class NullType
00042     {};
00043 
00044 
00052     class TypeInfo :
00053         virtual public wns::IOutputStreamable
00054     {
00055     public:
00060         explicit
00061         TypeInfo(const std::type_info& type) :
00062             IOutputStreamable(),
00063             type_(&type)
00064         {}
00065 
00069         TypeInfo(const TypeInfo& other) :
00070             IOutputStreamable(other),
00071             type_(other.type_)
00072         {
00073         }
00074 
00078         TypeInfo&
00079         operator=(const TypeInfo& other)
00080         {
00081             type_ = other.type_;
00082             return *this;
00083         }
00084 
00085 
00086         // Default d'tor is ok
00087 
00095         bool
00096         before(const TypeInfo& other) const
00097         {
00098             return type_->before(*(other.type_));
00099         }
00100 
00107         const char*
00108         name() const
00109         {
00110             return type_->name();
00111         }
00113 
00118         bool
00119         operator==(const TypeInfo& other) const
00120         {
00121             return (*type_ == *(other.type_));
00122         }
00123 
00124         bool
00125         operator!=(const TypeInfo& other) const
00126         {
00127             return (*type_ != *(other.type_));
00128         }
00129 
00130         bool
00131         operator<(const TypeInfo& other) const
00132         {
00133             return before(other);
00134         }
00135 
00136         bool
00137         operator<=(const TypeInfo& other) const
00138         {
00139             return ((*this < other) || (*this == other));
00140         }
00141 
00142         bool
00143         operator>(const TypeInfo& other) const
00144         {
00145             return !((*this < other) || (*this == other));
00146         }
00147 
00148         bool
00149         operator>=(const TypeInfo& other) const
00150         {
00151             return !(*this < other);
00152         }
00154 
00159 
00164         template <typename T>
00165         static TypeInfo
00166         create()
00167         {
00168             return TypeInfo(typeid(T));
00169         }
00170 
00175         template <typename T>
00176         static TypeInfo
00177         create(const T& t)
00178         {
00179             return TypeInfo(typeid(t));
00180         }
00182 
00183     private:
00187         virtual std::string
00188         doToString() const
00189         {
00190             return wns::demangle(name());
00191         }
00192 
00196         const std::type_info* type_;
00197 
00201         TypeInfo();
00202     };
00203 }
00204 
00205 #endif // NOT defined WNS_TYPEINFO_HPP

Generated on Sat May 26 03:31:53 2012 for openWNS by  doxygen 1.5.5