Chaste Release::3.1
|
00001 /* 00002 00003 Copyright (c) 2005-2012, University of Oxford. 00004 All rights reserved. 00005 00006 University of Oxford means the Chancellor, Masters and Scholars of the 00007 University of Oxford, having an administrative office at Wellington 00008 Square, Oxford OX1 2JD, UK. 00009 00010 This file is part of Chaste. 00011 00012 Redistribution and use in source and binary forms, with or without 00013 modification, are permitted provided that the following conditions are met: 00014 * Redistributions of source code must retain the above copyright notice, 00015 this list of conditions and the following disclaimer. 00016 * Redistributions in binary form must reproduce the above copyright notice, 00017 this list of conditions and the following disclaimer in the documentation 00018 and/or other materials provided with the distribution. 00019 * Neither the name of the University of Oxford nor the names of its 00020 contributors may be used to endorse or promote products derived from this 00021 software without specific prior written permission. 00022 00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 00034 */ 00035 00036 #include "Identifiable.hpp" 00037 00038 #include <algorithm> 00039 #include <typeinfo> 00040 00041 #include <boost/serialization/extended_type_info.hpp> 00042 #include <boost/serialization/extended_type_info_typeid.hpp> 00043 #include <boost/serialization/extended_type_info_no_rtti.hpp> 00044 #include <boost/serialization/type_info_implementation.hpp> 00045 00046 std::string Identifiable::TidyTemplatedExportIdentifier(std::string identifier) const 00047 { 00048 // First remove spaces, so identifier now takes the form "pack<void(NameOfDerivedType<DIM>)>::type" 00049 std::string::iterator end_pos = std::remove(identifier.begin(), identifier.end(), ' '); 00050 identifier.erase(end_pos, identifier.end()); 00051 00052 // Then remove "pack<void(", so identifier now takes the form "NameOfDerivedType<DIM>)>::type" 00053 const std::string s_pack = "pack<void("; 00054 std::string::size_type i = identifier.find(s_pack); 00055 if (i != identifier.npos) 00056 { 00057 identifier.erase(i, s_pack.length()); 00058 } 00059 00060 // Then replace "<" with "-", so identifier now takes the form "NameOfDerivedType-DIM>)>::type" 00061 const std::string s_open = "<"; 00062 const std::string s_dash = "-"; 00063 i = identifier.find(s_open); 00064 if (i != identifier.npos) 00065 { 00066 identifier.replace(i, s_open.length(), s_dash); 00067 } 00068 00069 // Then replace "," with "-" to account for multiple template parameters 00070 const std::string s_comma = ","; 00071 i = identifier.find(s_comma); 00072 while (i != identifier.npos) 00073 { 00074 identifier.replace(i, s_comma.length(), s_dash); 00075 i = identifier.find(s_comma, i); 00076 } 00077 00078 // Finally remove ">)>::type", so that identifier now takes the form "NameOfDerivedType-DIM" 00079 const std::string s_end = ">)>::type"; 00080 i = identifier.find(s_end); 00081 if (i != identifier.npos) 00082 { 00083 identifier.erase(i, s_end.length()); 00084 } 00085 00086 return identifier; 00087 } 00088 00089 Identifiable::~Identifiable() 00090 { 00091 } 00092 00093 std::string Identifiable::GetIdentifier() const 00094 { 00095 std::string id; 00096 #if BOOST_VERSION >= 103700 00097 id = boost::serialization::type_info_implementation<Identifiable>::type::get_const_instance().get_derived_extended_type_info(*this)->get_key(); 00098 #else 00099 id = boost::serialization::type_info_implementation<Identifiable>::type::get_derived_extended_type_info(*this)->get_key(); 00100 #endif 00101 return TidyTemplatedExportIdentifier(id); 00102 }