1 |
gezelter |
3057 |
/********************************************************************** |
2 |
|
|
dlhandler.h - Dynamic loader for file format modules. |
3 |
|
|
|
4 |
|
|
Copyright (C) 2004-2005 by Chris Morley |
5 |
|
|
|
6 |
|
|
This file is part of the Open Babel project. |
7 |
|
|
For more information, see <http://openbabel.sourceforge.net/> |
8 |
|
|
|
9 |
|
|
This program is free software; you can redistribute it and/or modify |
10 |
|
|
it under the terms of the GNU General Public License as published by |
11 |
|
|
the Free Software Foundation version 2 of the License. |
12 |
|
|
|
13 |
|
|
This program 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 |
16 |
|
|
GNU General Public License for more details. |
17 |
|
|
***********************************************************************/ |
18 |
|
|
|
19 |
|
|
#ifndef OB_DLHANDLER_H |
20 |
|
|
#define OB_DLHANDLER_H |
21 |
|
|
|
22 |
|
|
#include "config.h" |
23 |
|
|
|
24 |
|
|
#include <string> |
25 |
|
|
#include <vector> |
26 |
|
|
|
27 |
|
|
// These macros are used in DLL builds. If they have not |
28 |
|
|
// been set in babelconfig.h, define them as nothing. |
29 |
|
|
#ifndef OBCONV |
30 |
|
|
#define OBCONV |
31 |
|
|
#endif |
32 |
|
|
#ifndef OBDLL |
33 |
|
|
#define OBDLL |
34 |
|
|
#endif |
35 |
|
|
|
36 |
|
|
//! \brief Interface for dynamic libraries. |
37 |
|
|
//! |
38 |
|
|
//! This class defines an interface for finding and opening dynamic |
39 |
|
|
//! loadable libraries on different platforms (e.g., modular plugins) |
40 |
|
|
//! via different source code files. |
41 |
|
|
//! It has only what is needed for OpenBabel and is not intended to be |
42 |
|
|
//! general purpose. Internally, it is used for dynamic loading and unloading |
43 |
|
|
//! OBFormat file translation modules. |
44 |
|
|
class OBCONV DLHandler |
45 |
|
|
{ |
46 |
|
|
public: |
47 |
|
|
|
48 |
|
|
/** Provides the path from which the conversion dynamic library, |
49 |
|
|
* (OBConv.dll in Windows) was loaded. |
50 |
|
|
* This is the default directory for the format files (*.obf in Windows) |
51 |
|
|
*/ |
52 |
|
|
static bool getConvDirectory(std::string& convPath); |
53 |
|
|
|
54 |
|
|
/** Searches a directory specified by path for files whose name matches |
55 |
|
|
* a pattern which can include * as a wildcard. |
56 |
|
|
* The path name should include a final separator (\ or /). |
57 |
|
|
* The routine fills a vector of strings with the matching file names (including path). |
58 |
|
|
* Note that this is not recursive: it only matches files in the specified path. |
59 |
|
|
* For example, if path = e:\\path\\to\\ and pattern = *.obf it will return |
60 |
|
|
* vector entries lik e:\\path\\to\\cmlformat.obf |
61 |
|
|
* \return the number of valid files. |
62 |
|
|
*/ |
63 |
|
|
static int findFiles (std::vector <std::string>& file_list, |
64 |
|
|
const std::string& pattern, const std::string& path); |
65 |
|
|
|
66 |
|
|
/** Searches for files which match a full filename (including the path) which |
67 |
|
|
* contains a wildcard. |
68 |
|
|
* The routine adds matching file names (including path) to a vector of strings . |
69 |
|
|
* \return the number of matching files. |
70 |
|
|
* If no wildcard in name adds name to vector and returns -1. |
71 |
|
|
*/ |
72 |
|
|
static int findFiles (std::vector<std::string>& file_list,const std::string &filename); |
73 |
|
|
|
74 |
|
|
/** Opens a dynamic library */ |
75 |
|
|
static bool openLib(const std::string& lib_name); |
76 |
|
|
|
77 |
|
|
//To select OB format files |
78 |
|
|
static const char* getFormatFilePattern(); |
79 |
|
|
|
80 |
|
|
static char getSeparator(); |
81 |
|
|
static void Sleep(int n); |
82 |
|
|
|
83 |
|
|
}; |
84 |
|
|
|
85 |
|
|
#endif /* DLHANDLER_H*/ |
86 |
|
|
|
87 |
|
|
//! \file dlhandler.h |
88 |
|
|
//! \brief Dynamic loader for file format modules. |