diff options
| author | manuel <manuel@nc8430.lan> | 2009-04-27 00:25:16 +0200 |
|---|---|---|
| committer | manuel <manuel@nc8430.lan> | 2009-04-27 00:25:16 +0200 |
| commit | aa139a7d2b3f26af7590edbf413df67195c5d900 (patch) | |
| tree | ba99ea3b2af9aa191386550f025520117f18f4f8 /ue2/imgsynth2/cfile.h | |
| parent | 384539f7cc9feaa7ef7cee385cce472c6966c843 (diff) | |
| download | ooprog-aa139a7d2b3f26af7590edbf413df67195c5d900.tar.gz ooprog-aa139a7d2b3f26af7590edbf413df67195c5d900.tar.bz2 ooprog-aa139a7d2b3f26af7590edbf413df67195c5d900.zip | |
Adding ue2
Diffstat (limited to 'ue2/imgsynth2/cfile.h')
| -rw-r--r-- | ue2/imgsynth2/cfile.h | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/ue2/imgsynth2/cfile.h b/ue2/imgsynth2/cfile.h new file mode 100644 index 0000000..a5c4d2a --- /dev/null +++ b/ue2/imgsynth2/cfile.h | |||
| @@ -0,0 +1,121 @@ | |||
| 1 | /** | ||
| 2 | * @module cfile | ||
| 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) | ||
| 4 | * @brief Abstract class for handling files. | ||
| 5 | * Needed for generic use in CScriptparser. | ||
| 6 | * @date 17.04.2009 | ||
| 7 | */ | ||
| 8 | |||
| 9 | #ifndef CFILE_H | ||
| 10 | #define CFILE_H | ||
| 11 | |||
| 12 | #include <string> | ||
| 13 | #include <set> | ||
| 14 | #include <list> | ||
| 15 | #include <fstream> | ||
| 16 | #include <stdexcept> | ||
| 17 | |||
| 18 | /** | ||
| 19 | * @class CFile | ||
| 20 | * @brief Abstract class for handling files. Needed for generic use in | ||
| 21 | * CScriptparser. | ||
| 22 | * | ||
| 23 | * In order for CScriptparser to determine which instance of CFile supports | ||
| 24 | * which filetype, every implemententation need to insert their filetypes to | ||
| 25 | * the member m_types in their constructor. | ||
| 26 | * | ||
| 27 | * On error throw FileError. | ||
| 28 | */ | ||
| 29 | class CFile | ||
| 30 | { | ||
| 31 | public: | ||
| 32 | /** | ||
| 33 | * @class FileError | ||
| 34 | * @brief Exception thrown by implemententations of CFile | ||
| 35 | */ | ||
| 36 | class FileError : public std::invalid_argument { | ||
| 37 | public: | ||
| 38 | /** | ||
| 39 | * @method FileError | ||
| 40 | * @brief Default exception ctor | ||
| 41 | * @param what message to pass along | ||
| 42 | * @return - | ||
| 43 | * @globalvars none | ||
| 44 | * @exception none | ||
| 45 | * @conditions none | ||
| 46 | */ | ||
| 47 | FileError(const std::string& what) | ||
| 48 | : std::invalid_argument(what) | ||
| 49 | {} | ||
| 50 | }; | ||
| 51 | |||
| 52 | /** | ||
| 53 | * @method ~CFile | ||
| 54 | * @brief Default dtor (virtual) | ||
| 55 | * @param - | ||
| 56 | * @return - | ||
| 57 | * @globalvars none | ||
| 58 | * @exception none | ||
| 59 | * @conditions none | ||
| 60 | */ | ||
| 61 | virtual ~CFile() | ||
| 62 | {}; | ||
| 63 | |||
| 64 | /** | ||
| 65 | * @method read | ||
| 66 | * @brief Pure virtual method (interface). Should read data from filestream. | ||
| 67 | * @param in filestream to read data from | ||
| 68 | * @return - | ||
| 69 | * @globalvars none | ||
| 70 | * @exception FileError | ||
| 71 | * @conditions none | ||
| 72 | */ | ||
| 73 | virtual void read(std::ifstream& in) = 0; | ||
| 74 | |||
| 75 | /** | ||
| 76 | * @method write | ||
| 77 | * @brief Pure virtual method (interface). Should write data to filestream. | ||
| 78 | * @param out filestream to write data to | ||
| 79 | * @return - | ||
| 80 | * @globalvars none | ||
| 81 | * @exception FileError | ||
| 82 | * @conditions none | ||
| 83 | */ | ||
| 84 | virtual void write(std::ofstream& out) = 0; | ||
| 85 | |||
| 86 | /** | ||
| 87 | * @method callFunc | ||
| 88 | * @brief Pure virtual method (interface). Should delegate the function | ||
| 89 | * and its parameters to the correct internal method. | ||
| 90 | * @param func function name | ||
| 91 | * @param params function parameters as list | ||
| 92 | * @return - | ||
| 93 | * @globalvars none | ||
| 94 | * @exception FileError | ||
| 95 | * @conditions none | ||
| 96 | */ | ||
| 97 | virtual void callFunc(const std::string& func, const std::list<std::string>& params) = 0; | ||
| 98 | |||
| 99 | /** | ||
| 100 | * @method supportsType | ||
| 101 | * @brief Check if filetype is supported by this implementation. | ||
| 102 | * @param type filetype | ||
| 103 | * @return true if filetype is supported. false otherwise | ||
| 104 | * @globalvars none | ||
| 105 | * @exception none | ||
| 106 | * @conditions none | ||
| 107 | */ | ||
| 108 | bool supportsType(const std::string& type) | ||
| 109 | { | ||
| 110 | return (m_types.find(type) == m_types.end()) ? false : true; | ||
| 111 | } | ||
| 112 | |||
| 113 | protected: | ||
| 114 | /* members */ | ||
| 115 | /** set of filetypes suppported by this implementation */ | ||
| 116 | std::set<std::string> m_types; | ||
| 117 | }; | ||
| 118 | |||
| 119 | #endif | ||
| 120 | |||
| 121 | /* vim: set et sw=2 ts=2: */ | ||
