| 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 | */ |
| 22 | #ifndef __LIBT2N_CONTAINER |
| 23 | #define __LIBT2N_CONTAINER |
| 24 | |
| 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 | |
| 31 | #include "command.hxx" |
| 32 | #include "t2n_exception.hxx" |
| 33 | |
| 34 | #include <iostream> |
| 35 | |
| 36 | namespace libt2n |
| 37 | { |
| 38 | |
| 39 | /** @brief contains the result (return value as libt2n::result or an libt2n::t2n_exception) of a executed command |
| 40 | */ |
| 41 | class result_container |
| 42 | { |
| 43 | private: |
| 44 | enum result_type_t { regular, exception } result_type; |
| 45 | |
| 46 | result *res; |
| 47 | t2n_exception *ex; |
| 48 | |
| 49 | friend class boost::serialization::access; |
| 50 | template<class Archive> |
| 51 | void serialize(Archive & ar, const unsigned int version); |
| 52 | |
| 53 | public: |
| 54 | result_container() |
| 55 | : res(NULL) |
| 56 | , ex(NULL) |
| 57 | , result_type(regular) |
| 58 | { |
| 59 | } |
| 60 | |
| 61 | result_container(result *_res) |
| 62 | : res(_res) |
| 63 | , ex(NULL) |
| 64 | , result_type(regular) |
| 65 | { |
| 66 | } |
| 67 | |
| 68 | result_container(t2n_exception *_ex) |
| 69 | : res(NULL) |
| 70 | , ex(_ex) |
| 71 | , result_type(exception) |
| 72 | { |
| 73 | } |
| 74 | |
| 75 | ~result_container(); |
| 76 | |
| 77 | void set_result(result *_res) |
| 78 | { res=_res; ex=0; result_type=regular; } |
| 79 | |
| 80 | void set_exception(t2n_exception *_ex) |
| 81 | { res=0; ex=_ex; result_type=exception; } |
| 82 | |
| 83 | result* get_result(void); |
| 84 | |
| 85 | bool has_exception() |
| 86 | { return (result_type==exception && ex != NULL); } |
| 87 | bool has_result() |
| 88 | { return (result_type==regular && res != NULL); } |
| 89 | }; |
| 90 | |
| 91 | /** @brief contains a libt2n::command |
| 92 | */ |
| 93 | class command_container |
| 94 | { |
| 95 | private: |
| 96 | command *cmd; |
| 97 | |
| 98 | friend class boost::serialization::access; |
| 99 | template<class Archive> |
| 100 | void serialize(Archive & ar, const unsigned int version); |
| 101 | |
| 102 | public: |
| 103 | command_container() |
| 104 | : cmd(NULL) |
| 105 | {} |
| 106 | |
| 107 | command_container(command *_cmd) |
| 108 | : cmd(_cmd) |
| 109 | {} |
| 110 | |
| 111 | ~command_container(); |
| 112 | |
| 113 | /// return the contained command |
| 114 | command* get_command() |
| 115 | { return cmd; } |
| 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 | |
| 123 | #include "container.tcc" |
| 124 | |
| 125 | #endif |
| 126 | |