blob: a5c4d2aa29dcd16ba4c77c0060b255746af251db (
plain)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
/**
* @module cfile
* @author Guenther Neuwirth (0626638), Manuel Mausz (0728348)
* @brief Abstract class for handling files.
* Needed for generic use in CScriptparser.
* @date 17.04.2009
*/
#ifndef CFILE_H
#define CFILE_H
#include <string>
#include <set>
#include <list>
#include <fstream>
#include <stdexcept>
/**
* @class CFile
* @brief Abstract class for handling files. Needed for generic use in
* CScriptparser.
*
* In order for CScriptparser to determine which instance of CFile supports
* which filetype, every implemententation need to insert their filetypes to
* the member m_types in their constructor.
*
* On error throw FileError.
*/
class CFile
{
public:
/**
* @class FileError
* @brief Exception thrown by implemententations of CFile
*/
class FileError : public std::invalid_argument {
public:
/**
* @method FileError
* @brief Default exception ctor
* @param what message to pass along
* @return -
* @globalvars none
* @exception none
* @conditions none
*/
FileError(const std::string& what)
: std::invalid_argument(what)
{}
};
/**
* @method ~CFile
* @brief Default dtor (virtual)
* @param -
* @return -
* @globalvars none
* @exception none
* @conditions none
*/
virtual ~CFile()
{};
/**
* @method read
* @brief Pure virtual method (interface). Should read data from filestream.
* @param in filestream to read data from
* @return -
* @globalvars none
* @exception FileError
* @conditions none
*/
virtual void read(std::ifstream& in) = 0;
/**
* @method write
* @brief Pure virtual method (interface). Should write data to filestream.
* @param out filestream to write data to
* @return -
* @globalvars none
* @exception FileError
* @conditions none
*/
virtual void write(std::ofstream& out) = 0;
/**
* @method callFunc
* @brief Pure virtual method (interface). Should delegate the function
* and its parameters to the correct internal method.
* @param func function name
* @param params function parameters as list
* @return -
* @globalvars none
* @exception FileError
* @conditions none
*/
virtual void callFunc(const std::string& func, const std::list<std::string>& params) = 0;
/**
* @method supportsType
* @brief Check if filetype is supported by this implementation.
* @param type filetype
* @return true if filetype is supported. false otherwise
* @globalvars none
* @exception none
* @conditions none
*/
bool supportsType(const std::string& type)
{
return (m_types.find(type) == m_types.end()) ? false : true;
}
protected:
/* members */
/** set of filetypes suppported by this implementation */
std::set<std::string> m_types;
};
#endif
/* vim: set et sw=2 ts=2: */
|