00001 //------------------------------------------------------------------------------ 00002 // This file is part of the OpenStructure project <www.openstructure.org> 00003 // 00004 // Copyright (C) 2008-2011 by the OpenStructure authors 00005 // 00006 // This library is free software; you can redistribute it and/or modify it under 00007 // the terms of the GNU Lesser General Public License as published by the Free 00008 // Software Foundation; either version 3.0 of the License, or (at your option) 00009 // any later version. 00010 // This library is distributed in the hope that it will be useful, but WITHOUT 00011 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00012 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00013 // details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public License 00016 // along with this library; if not, write to the Free Software Foundation, Inc., 00017 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00018 //------------------------------------------------------------------------------ 00019 #ifndef OST_BOND_TABLE_HH 00020 #define OST_BOND_TABLE_HH 00021 00022 #include <map> 00023 00024 #include <ost/mol/impl/connector_impl_fw.hh> 00025 #include <ost/mol/bond_handle.hh> 00026 00027 namespace ost { namespace mol { 00028 00029 template <typename ATOM> 00030 struct BondTableEntry { 00031 BondTableEntry(const BondHandle& b, const ATOM& atom) 00032 : bond(b) { 00033 atoms[0]=atom; 00034 } 00035 BondHandle bond; 00036 ATOM atoms[2]; 00037 bool IsComplete() const { 00038 return atoms[1].IsValid(); 00039 } 00040 }; 00041 00042 template <typename ATOM> 00043 struct BondTable { 00044 typedef BondTableEntry<ATOM> EntryType; 00045 typedef typename std::map<impl::ConnectorImpl*, EntryType> MapType; 00046 MapType bonds; 00047 void Update(const BondHandle& bond, const ATOM& a) { 00048 if(!bond.IsValid()) return; 00049 typename MapType::iterator i=bonds.find(bond.Impl().get()); 00050 if (i!=bonds.end()) { 00051 i->second.atoms[1]=a; 00052 } else { 00053 bonds.insert(std::make_pair(bond.Impl().get(), EntryType(bond, a))); 00054 } 00055 } 00056 00057 }; 00058 00059 }} 00060 #endif