OpenStructure
compound_lib.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2011 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 #ifndef OST_CONOP_COMPOUND_LIB_HH
20 #define OST_CONOP_COMPOUND_LIB_HH
21 
22 #include <map>
23 #include <boost/shared_ptr.hpp>
24 
25 // our own local copy of sqlite3
26 #include <ost/db/sqlite3.h>
27 
29 #include <ost/conop/compound.hh>
30 
31 namespace ost { namespace conop {
32 
34 
35 typedef boost::shared_ptr<CompoundLib> CompoundLibPtr;
36 typedef std::map<String, CompoundPtr> CompoundMap;
37 
39 public:
40  static CompoundLibPtr Load(const String& database, bool readonly=true);
41  static CompoundLibPtr Create(const String& database);
42  ~CompoundLib();
43 
44  CompoundPtr FindCompound(const String& id, Compound::Dialect dialect);
45  void AddCompound(const CompoundPtr& compound);
46  CompoundLibPtr Copy(const String& filename) const;
47  void ClearCache();
48 private:
49  CompoundLib();
50  void LoadAtomsFromDB(CompoundPtr comp, int pk);
51  void LoadBondsFromDB(CompoundPtr comp, int pk);
52 private:
53  CompoundMap compound_cache_;
54  sqlite3* conn_;
55 };
56 
57 }}
58 
59 #endif