Chemical Data Processing Library C++ API - Version 1.4.0
FragmentLibrary.hpp
Go to the documentation of this file.
1 /*
2  * FragmentLibrary.hpp
3  *
4  * This file is part of the Chemical Data Processing Toolkit
5  *
6  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; see the file COPYING. If not, write to
20  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
29 #ifndef CDPL_CONFGEN_FRAGMENTLIBRARY_HPP
30 #define CDPL_CONFGEN_FRAGMENTLIBRARY_HPP
31 
32 #include <iosfwd>
33 #include <cstddef>
34 #include <unordered_map>
35 #include <mutex>
36 #include <memory>
37 
40 
41 
42 namespace CDPL
43 {
44 
45  namespace ConfGen
46  {
47 
60  {
61 
62  typedef std::unordered_map<std::uint64_t, FragmentLibraryEntry::SharedPointer> HashToEntryMap;
63 
64  public:
68  typedef std::shared_ptr<FragmentLibrary> SharedPointer;
69 
73  typedef HashToEntryMap::value_type Entry;
74 
78  typedef HashToEntryMap::const_iterator ConstEntryIterator;
79 
83  typedef HashToEntryMap::iterator EntryIterator;
84 
89 
95 
100 
107 
112  void addEntries(const FragmentLibrary& lib);
113 
120 
127  const FragmentLibraryEntry::SharedPointer& getEntry(std::uint64_t hash_code) const;
128 
134  bool containsEntry(std::uint64_t hash_code) const;
135 
140  std::size_t getNumEntries() const;
141 
145  void clear();
146 
152  bool removeEntry(std::uint64_t hash_code);
153 
160 
166 
172 
178 
184 
190 
196 
202 
208 
213  void load(std::istream& is);
214 
219  void save(std::ostream& os) const;
220 
224  void loadDefaults();
225 
230  std::mutex& getMutex();
231 
236  static void set(const SharedPointer& lib);
237 
242  static const SharedPointer& get();
243 
244  private:
245  static SharedPointer defaultLib;
246  mutable HashToEntryMap hashToEntryMap;
247  mutable std::mutex mutex;
248  };
249  } // namespace ConfGen
250 } // namespace CDPL
251 
252 #endif // CDPL_CONFGEN_FRAGMENTLIBRARY_HPP
Definition of the preprocessor macro CDPL_CONFGEN_API.
#define CDPL_CONFGEN_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
Definition of class CDPL::ConfGen::FragmentLibraryEntry.
std::shared_ptr< FragmentLibraryEntry > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated FragmentLibraryEntry instances.
Definition: FragmentLibraryEntry.hpp:62
Data structure representing a library of pre-generated molecular fragment conformer ensembles.
Definition: FragmentLibrary.hpp:60
std::shared_ptr< FragmentLibrary > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated FragmentLibrary instances.
Definition: FragmentLibrary.hpp:68
EntryIterator end()
Returns a mutable iterator pointing one past the last entry of the library (range-based for support).
ConstEntryIterator end() const
Returns a constant iterator pointing one past the last entry of the library (range-based for support)...
std::size_t getNumEntries() const
Returns the number of entries stored in the library.
void clear()
Removes all entries from the library.
HashToEntryMap::value_type Entry
The type of a stored hash-code-to-entry pair.
Definition: FragmentLibrary.hpp:73
HashToEntryMap::iterator EntryIterator
A mutable iterator over the stored entries.
Definition: FragmentLibrary.hpp:83
std::mutex & getMutex()
Returns the mutex protecting the library state for use by external multi-threaded callers.
bool containsEntry(std::uint64_t hash_code) const
Tells whether the library contains an entry with the specified hash code.
bool removeEntry(std::uint64_t hash_code)
Removes the entry with the specified hash code.
static void set(const SharedPointer &lib)
Sets the process-wide default fragment library used by ConfGen routines.
const FragmentLibraryEntry::SharedPointer & getEntry(std::uint64_t hash_code) const
Returns the entry with the specified hash code.
EntryIterator removeEntry(const EntryIterator &it)
Removes the entry referenced by the given iterator.
static const SharedPointer & get()
Returns the process-wide default fragment library.
EntryIterator begin()
Returns a mutable iterator pointing to the first entry of the library (range-based for support).
void save(std::ostream &os) const
Writes the contents of the library to the output stream os.
FragmentLibrary & operator=(const FragmentLibrary &lib)
Replaces the contents of this library with a copy of the contents of lib.
FragmentLibrary(const FragmentLibrary &lib)
Constructs a copy of the FragmentLibrary instance lib.
void loadDefaults()
Loads the default fragment library bundled with CDPKit.
void addEntries(const FragmentLibrary &lib)
Adds all entries from lib to this library.
bool addEntry(const FragmentLibraryEntry::SharedPointer &entry)
Adds the given entry to the library.
ConstEntryIterator getEntriesBegin() const
Returns a constant iterator pointing to the first entry of the library.
EntryIterator getEntriesBegin()
Returns a mutable iterator pointing to the first entry of the library.
ConstEntryIterator getEntriesEnd() const
Returns a constant iterator pointing one past the last entry of the library.
void load(std::istream &is)
Loads the contents of the library from the input stream is.
HashToEntryMap::const_iterator ConstEntryIterator
A constant iterator over the stored entries.
Definition: FragmentLibrary.hpp:78
FragmentLibrary()
Constructs an empty FragmentLibrary instance.
EntryIterator getEntriesEnd()
Returns a mutable iterator pointing one past the last entry of the library.
ConstEntryIterator begin() const
Returns a constant iterator pointing to the first entry of the library (range-based for support).
The namespace of the Chemical Data Processing Library.