Commit | Line | Data |
---|---|---|
7087e187 GE |
1 | /*************************************************************************** |
2 | * Copyright (C) 2006 by Gerd v. Egidy * | |
3 | * gve@intra2net.com * | |
4 | * * | |
5 | * This library is free software; you can redistribute it and/or modify * | |
6 | * it under the terms of the GNU Lesser General Public License version * | |
7 | * 2.1 as published by the Free Software Foundation. * | |
8 | * * | |
9 | * This library is distributed in the hope that it will be useful, * | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
12 | * GNU Lesser General Public License for more details. * | |
13 | * * | |
14 | * You should have received a copy of the GNU Lesser General Public * | |
15 | * License along with this program; if not, write to the * | |
16 | * Free Software Foundation, Inc., * | |
17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | |
18 | ***************************************************************************/ | |
19 | #ifndef __LIBT2N_CONTAINER | |
20 | #define __LIBT2N_CONTAINER | |
21 | ||
a7170401 GE |
22 | #include <boost/archive/binary_oarchive.hpp> |
23 | #include <boost/archive/binary_iarchive.hpp> | |
24 | #include <boost/archive/xml_oarchive.hpp> | |
25 | #include <boost/archive/xml_iarchive.hpp> | |
26 | #include <boost/serialization/serialization.hpp> | |
27 | ||
7087e187 GE |
28 | #include "command.hxx" |
29 | #include "t2n_exception.hxx" | |
30 | ||
d184c648 GE |
31 | #include <iostream> |
32 | ||
7087e187 GE |
33 | namespace libt2n |
34 | { | |
35 | ||
1e1f17bf | 36 | /** @brief contains the result (return value as libt2n::result or an libt2n::t2n_exception) of a executed command |
7087e187 GE |
37 | */ |
38 | class result_container | |
39 | { | |
40 | private: | |
41 | enum result_type_t { regular, exception } result_type; | |
42 | ||
43 | result *res; | |
44 | t2n_exception *ex; | |
45 | ||
46 | friend class boost::serialization::access; | |
7087e187 | 47 | template<class Archive> |
a7170401 | 48 | void serialize(Archive & ar, const unsigned int version); |
7087e187 GE |
49 | |
50 | public: | |
51 | result_container() | |
c72238fb TJ |
52 | : res(NULL) |
53 | , ex(NULL) | |
54 | , result_type(regular) | |
55 | { | |
56 | } | |
7087e187 GE |
57 | |
58 | result_container(result *_res) | |
c72238fb TJ |
59 | : res(_res) |
60 | , ex(NULL) | |
61 | , result_type(regular) | |
62 | { | |
63 | } | |
64 | ||
7087e187 | 65 | result_container(t2n_exception *_ex) |
c72238fb TJ |
66 | : res(NULL) |
67 | , ex(_ex) | |
68 | , result_type(exception) | |
69 | { | |
70 | } | |
7087e187 | 71 | |
a7170401 GE |
72 | ~result_container(); |
73 | ||
7087e187 GE |
74 | void set_result(result *_res) |
75 | { res=_res; ex=0; result_type=regular; } | |
c72238fb | 76 | |
7087e187 GE |
77 | void set_exception(t2n_exception *_ex) |
78 | { res=0; ex=_ex; result_type=exception; } | |
79 | ||
a7170401 | 80 | result* get_result(void); |
01a46463 GE |
81 | |
82 | bool has_exception() | |
9e76c815 | 83 | { return (result_type==exception && ex != NULL); } |
01a46463 | 84 | bool has_result() |
9e76c815 | 85 | { return (result_type==regular && res != NULL); } |
7087e187 GE |
86 | }; |
87 | ||
1e1f17bf | 88 | /** @brief contains a libt2n::command |
7087e187 GE |
89 | */ |
90 | class command_container | |
91 | { | |
92 | private: | |
93 | command *cmd; | |
94 | ||
95 | friend class boost::serialization::access; | |
96 | template<class Archive> | |
a7170401 | 97 | void serialize(Archive & ar, const unsigned int version); |
7087e187 GE |
98 | |
99 | public: | |
100 | command_container() | |
c72238fb TJ |
101 | : cmd(NULL) |
102 | {} | |
103 | ||
7087e187 | 104 | command_container(command *_cmd) |
c72238fb TJ |
105 | : cmd(_cmd) |
106 | {} | |
7087e187 | 107 | |
a7170401 GE |
108 | ~command_container(); |
109 | ||
7087e187 GE |
110 | /// return the contained command |
111 | command* get_command() | |
112 | { return cmd; } | |
7087e187 GE |
113 | }; |
114 | ||
115 | } // namespace libt2n | |
116 | ||
117 | BOOST_CLASS_TRACKING(libt2n::result_container, boost::serialization::track_never) | |
118 | BOOST_CLASS_TRACKING(libt2n::command_container, boost::serialization::track_never) | |
119 | ||
d2cb39bb RP |
120 | #include "container.tcc" |
121 | ||
7087e187 GE |
122 | #endif |
123 |