Identifiable.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
00026 
00027 */
00028 
00029 #include "Identifiable.hpp"
00030 
00031 #include <algorithm>
00032 #include <typeinfo>
00033 
00034 #include <boost/serialization/extended_type_info.hpp>
00035 #include <boost/serialization/extended_type_info_typeid.hpp>
00036 #include <boost/serialization/extended_type_info_no_rtti.hpp>
00037 #include <boost/serialization/type_info_implementation.hpp>
00038 
00039 std::string Identifiable::TidyTemplatedExportIdentifier(std::string identifier) const
00040 {
00041     // First remove spaces, so identifier now takes the form "pack<void(NameOfDerivedType<DIM>)>::type"
00042     std::string::iterator end_pos = std::remove(identifier.begin(), identifier.end(), ' ');
00043     identifier.erase(end_pos, identifier.end());
00044 
00045     // Then remove "pack<void(", so identifier now takes the form "NameOfDerivedType<DIM>)>::type"
00046     const std::string s_pack = "pack<void(";
00047     std::string::size_type i = identifier.find(s_pack);
00048     if (i != identifier.npos)
00049     {
00050         identifier.erase(i, s_pack.length());
00051     }
00052 
00053     // Then replace "<" with "-", so identifier now takes the form "NameOfDerivedType-DIM>)>::type"
00054     const std::string s_open = "<";
00055     const std::string s_dash = "-";
00056     i = identifier.find(s_open);
00057     if (i != identifier.npos)
00058     {
00059         identifier.replace(i, s_open.length(), s_dash);
00060     }
00061 
00062     // Then replace "," with "-" to account for multiple template parameters
00063     const std::string s_comma = ",";
00064     i = identifier.find(s_comma);
00065     assert( i == identifier.npos ); 
00066 
00074     // Finally remove ">)>::type", so that identifier now takes the form "NameOfDerivedType-DIM"
00075     const std::string s_end = ">)>::type";
00076     i = identifier.find(s_end);
00077     if (i != identifier.npos)
00078     {
00079         identifier.erase(i, s_end.length());
00080     }
00081 
00082     return identifier;
00083 }
00084 
00085 Identifiable::~Identifiable()
00086 {
00087 }
00088 
00089 std::string Identifiable::GetIdentifier() const
00090 {
00091     std::string id;
00092 #if BOOST_VERSION >= 103700
00093     id = boost::serialization::type_info_implementation<Identifiable>::type::get_const_instance().get_derived_extended_type_info(*this)->get_key();
00094 #else
00095     id = boost::serialization::type_info_implementation<Identifiable>::type::get_derived_extended_type_info(*this)->get_key();
00096 #endif
00097     return TidyTemplatedExportIdentifier(id);
00098 }
Generated on Thu Dec 22 13:00:05 2011 for Chaste by  doxygen 1.6.3