[go: up one dir, main page]

Menu

[r999]: / mia2 / mia / core / iohandler.hh  Maximize  Restore  History

Download this file

93 lines (76 with data), 3.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* -*- mona-c++ -*-
*
* Copyright (c) Leipzig, Madrid 2004 - 2009
* Max-Planck-Institute for Human Cognitive and Brain Science
* Max-Planck-Institute for Evolutionary Anthropology
* BIT, ETSI Telecomunicacion, UPM
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PUcRPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef ph_IOhandler_hh
#define ph_IOhandler_hh
#include <set>
#include <mia/core/handler.hh>
#include <mia/core/ioplugin.hh>
NS_MIA_BEGIN
/**
Input/Output plugin handler base class, derived privately from the standart plug-in handler to hide
its interface.
Class \a I, the interface class needs to be derived from \a TIOPlugin.
*/
template <class I>
class EXPORT_HANDLER TIOPluginHandler: public TPluginHandler<I> {
public:
typedef typename I::Data Data;
typedef typename ::boost::shared_ptr<Data> PData;
typedef typename TPluginHandler<I>::Interface Interface;
typedef typename TPluginHandler<I>::const_iterator const_iterator;
/**
Load data from a file. The suffix of \a fname is used to derive a preffered plug-in,
which is then tried first. If this fails, all other plug-ins are tried as well.
\param fname the file name
\returns a shared pointer to the loaded data or an empty shared pointer
if no data could be loaded.
*/
PData load(const std::string& fname) const;
/**
Save the data to a file. If type is empty, then the output plugin is derived from
the fname suffix. if this fails, saving fails. If type is provided, the output plugin
is selected accordingly.
\param type output plugin name - leave empty to derive from fname suffix
\param fname output file name
\param data the data to be saved
\returns true if saving is successfull, false otherwise.
*/
bool save(const std::string& type, const std::string& fname, const Data& data) const;
/**
\param fname a file name
\returns the plug-in that is preferred for the suffix of \a fname
*/
const typename TIOPluginHandler<I>::Interface *prefered_plugin_ptr(const std::string& fname) const;
const typename TIOPluginHandler<I>::Interface& prefered_plugin(const std::string& fname) const;
protected:
/**
constructor that is provided with a list of plugin search path.
*/
TIOPluginHandler(const std::list< ::boost::filesystem::path>& searchpath);
private:
// a map of plugins
std::multimap<std::string, std::string> _M_suffixmap;
std::set<std::string> _M_compress_sfx;
};
NS_MIA_END
#endif