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 
00040 std::string Identifiable::TidyTemplatedExportIdentifier(std::string identifier) const
00041 {
00042     // First remove spaces, so identifier now takes the form "pack<void(NameOfDerivedType<DIM>)>::type"
00043     std::string::iterator end_pos = std::remove(identifier.begin(), identifier.end(), ' ');
00044     identifier.erase(end_pos, identifier.end());
00045 
00046     // Then remove "pack<void(", so identifier now takes the form "NameOfDerivedType<DIM>)>::type"
00047     const std::string s_pack = "pack<void(";
00048     std::string::size_type i = identifier.find(s_pack);
00049     if (i != identifier.npos)
00050     {
00051         identifier.erase(i, s_pack.length());
00052     }
00053 
00054     // Then replace "<" with "-", so identifier now takes the form "NameOfDerivedType-DIM>)>::type"
00055     const std::string s_open = "<";
00056     const std::string s_dash = "-";
00057     i = identifier.find(s_open);
00058     if (i != identifier.npos)
00059     {
00060         identifier.replace(i, s_open.length(), s_dash);
00061     }
00062 
00063     // Then replace "," with "-" to account for multiple template parameters
00064     const std::string s_comma = ",";
00065     i = identifier.find(s_comma);
00066     assert( i == identifier.npos ); 
00067     
00075     // Finally remove ">)>::type", so that identifier now takes the form "NameOfDerivedType-DIM"
00076     const std::string s_end = ">)>::type";
00077     i = identifier.find(s_end);
00078     if (i != identifier.npos)
00079     {
00080         identifier.erase(i, s_end.length());
00081     }
00082 
00083     return identifier;
00084 }
00085 
00086 Identifiable::~Identifiable()
00087 {
00088 }
00089 
00090 std::string Identifiable::GetIdentifier() const
00091 {
00092     std::string id;
00093 #if BOOST_VERSION >= 103700
00094     id = boost::serialization::type_info_implementation<Identifiable>::type::get_const_instance().get_derived_extended_type_info(*this)->get_key();
00095 #else
00096     id = boost::serialization::type_info_implementation<Identifiable>::type::get_derived_extended_type_info(*this)->get_key();
00097 #endif
00098     return TidyTemplatedExportIdentifier(id);
00099 }

Generated on Tue May 31 14:31:41 2011 for Chaste by  doxygen 1.5.5