Commit | Line | Data |
---|---|---|
19facd85 TJ |
1 | /* |
2 | Copyright (C) 2006 by Intra2net AG - Gerd v. Egidy | |
3 | ||
4 | The software in this package is distributed under the GNU General | |
5 | Public License version 2 (with a special exception described below). | |
6 | ||
7 | A copy of GNU General Public License (GPL) is included in this distribution, | |
8 | in the file COPYING.GPL. | |
9 | ||
10 | As a special exception, if other files instantiate templates or use macros | |
11 | or inline functions from this file, or you compile this file and link it | |
12 | with other works to produce a work based on this file, this file | |
13 | does not by itself cause the resulting work to be covered | |
14 | by the GNU General Public License. | |
15 | ||
16 | However the source code for this file must still be made available | |
17 | in accordance with section (3) of the GNU General Public License. | |
18 | ||
19 | This exception does not invalidate any other reasons why a work based | |
20 | on this file might be covered by the GNU General Public License. | |
21 | */ | |
7087e187 GE |
22 | #ifndef __LIBT2N_CONTAINER |
23 | #define __LIBT2N_CONTAINER | |
24 | ||
a7170401 GE |
25 | #include <boost/archive/binary_oarchive.hpp> |
26 | #include <boost/archive/binary_iarchive.hpp> | |
27 | #include <boost/archive/xml_oarchive.hpp> | |
28 | #include <boost/archive/xml_iarchive.hpp> | |
29 | #include <boost/serialization/serialization.hpp> | |
30 | ||
7087e187 GE |
31 | #include "command.hxx" |
32 | #include "t2n_exception.hxx" | |
33 | ||
d184c648 GE |
34 | #include <iostream> |
35 | ||
7087e187 GE |
36 | namespace libt2n |
37 | { | |
38 | ||
1e1f17bf | 39 | /** @brief contains the result (return value as libt2n::result or an libt2n::t2n_exception) of a executed command |
7087e187 GE |
40 | */ |
41 | class result_container | |
42 | { | |
43 | private: | |
7087e187 GE |
44 | result *res; |
45 | t2n_exception *ex; | |
46 | ||
2d5dd128 TJ |
47 | enum result_type_t { regular, exception } result_type; |
48 | ||
7087e187 | 49 | friend class boost::serialization::access; |
7087e187 | 50 | template<class Archive> |
a7170401 | 51 | void serialize(Archive & ar, const unsigned int version); |
7087e187 GE |
52 | |
53 | public: | |
54 | result_container() | |
c72238fb TJ |
55 | : res(NULL) |
56 | , ex(NULL) | |
57 | , result_type(regular) | |
58 | { | |
59 | } | |
7087e187 GE |
60 | |
61 | result_container(result *_res) | |
c72238fb TJ |
62 | : res(_res) |
63 | , ex(NULL) | |
64 | , result_type(regular) | |
65 | { | |
66 | } | |
67 | ||
7087e187 | 68 | result_container(t2n_exception *_ex) |
c72238fb TJ |
69 | : res(NULL) |
70 | , ex(_ex) | |
71 | , result_type(exception) | |
72 | { | |
73 | } | |
7087e187 | 74 | |
a7170401 GE |
75 | ~result_container(); |
76 | ||
7087e187 GE |
77 | void set_result(result *_res) |
78 | { res=_res; ex=0; result_type=regular; } | |
c72238fb | 79 | |
7087e187 GE |
80 | void set_exception(t2n_exception *_ex) |
81 | { res=0; ex=_ex; result_type=exception; } | |
82 | ||
a7170401 | 83 | result* get_result(void); |
01a46463 GE |
84 | |
85 | bool has_exception() | |
9e76c815 | 86 | { return (result_type==exception && ex != NULL); } |
01a46463 | 87 | bool has_result() |
9e76c815 | 88 | { return (result_type==regular && res != NULL); } |
7087e187 GE |
89 | }; |
90 | ||
1e1f17bf | 91 | /** @brief contains a libt2n::command |
7087e187 GE |
92 | */ |
93 | class command_container | |
94 | { | |
95 | private: | |
96 | command *cmd; | |
97 | ||
98 | friend class boost::serialization::access; | |
99 | template<class Archive> | |
a7170401 | 100 | void serialize(Archive & ar, const unsigned int version); |
7087e187 GE |
101 | |
102 | public: | |
103 | command_container() | |
c72238fb TJ |
104 | : cmd(NULL) |
105 | {} | |
106 | ||
7087e187 | 107 | command_container(command *_cmd) |
c72238fb TJ |
108 | : cmd(_cmd) |
109 | {} | |
7087e187 | 110 | |
a7170401 GE |
111 | ~command_container(); |
112 | ||
7087e187 GE |
113 | /// return the contained command |
114 | command* get_command() | |
115 | { return cmd; } | |
7087e187 GE |
116 | }; |
117 | ||
118 | } // namespace libt2n | |
119 | ||
120 | BOOST_CLASS_TRACKING(libt2n::result_container, boost::serialization::track_never) | |
121 | BOOST_CLASS_TRACKING(libt2n::command_container, boost::serialization::track_never) | |
122 | ||
d2cb39bb RP |
123 | #include "container.tcc" |
124 | ||
7087e187 GE |
125 | #endif |
126 |