TypeConverter.h

Go to the documentation of this file.
00001 /*
00002  * The information in this file is
00003  * Copyright(c) 2007 Ball Aerospace & Technologies Corporation
00004  * and is subject to the terms and conditions of the
00005  * GNU Lesser General Public License Version 2.1
00006  * The license text is available from   
00007  * http://www.gnu.org/licenses/lgpl.html
00008  */
00009 
00010 #ifndef TYPECONVERTER_H
00011 #define TYPECONVERTER_H
00012 
00013 #include <string>
00014 #include <vector>
00015 
00016 /**
00017  * This namespace is a common place to put type to string conversions.
00018  *
00019  * To use, simply do the following:
00020  * @code
00021  * TypeConverter::toString<int>(); // returns "int"
00022  * DataElement *pElement;
00023  * TypeConverter::toString(pElement); // returns "DataElement"
00024  * TypeConverter::toString<std::vector<int> >(); // returns "vector<int>"
00025  * TypeConverter::toString<std::vector<DataElement*> >(); // return "vector<DataElement>"
00026  * @endcode
00027  */
00028 namespace TypeConverter
00029 {
00030    /**
00031     * Generic form of type conversion.
00032     *
00033     * This function is explicitly specialized to return type names for those
00034     * listed in \ref typeconverter_types
00035     *
00036     * @return A string containing the type name.
00037     */
00038    template<typename T>
00039    const char* toString();
00040 
00041    /**
00042     * This function is exactly like the one above it, but may be more convenient
00043     * where there is already an instance of the type desired.
00044     *
00045     * @return A string containing the type name.
00046     */
00047    template<typename T>
00048    const char* toString(const T *)
00049    {
00050       return toString<T>();
00051    }
00052 };
00053 
00054 
00055 #endif

Software Development Kit - Opticks 4.9.0 Build 16218