| 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 | |
| 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 | |
| 28 | #include "command.hxx" |
| 29 | #include "t2n_exception.hxx" |
| 30 | |
| 31 | #include <iostream> |
| 32 | |
| 33 | namespace libt2n |
| 34 | { |
| 35 | |
| 36 | /** @brief contains the result (return value as libt2n::result or an libt2n::t2n_exception) of a executed command |
| 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; |
| 47 | template<class Archive> |
| 48 | void serialize(Archive & ar, const unsigned int version); |
| 49 | |
| 50 | public: |
| 51 | result_container() |
| 52 | { res=0; ex=0; } |
| 53 | |
| 54 | result_container(result *_res) |
| 55 | { set_result(_res); } |
| 56 | result_container(t2n_exception *_ex) |
| 57 | { set_exception(_ex); } |
| 58 | |
| 59 | ~result_container(); |
| 60 | |
| 61 | void set_result(result *_res) |
| 62 | { res=_res; ex=0; result_type=regular; } |
| 63 | void set_exception(t2n_exception *_ex) |
| 64 | { res=0; ex=_ex; result_type=exception; } |
| 65 | |
| 66 | result* get_result(void); |
| 67 | |
| 68 | bool has_exception() |
| 69 | { return (result_type==exception); } |
| 70 | bool has_result() |
| 71 | { return (result_type==regular); } |
| 72 | }; |
| 73 | |
| 74 | /** @brief contains a libt2n::command |
| 75 | */ |
| 76 | class command_container |
| 77 | { |
| 78 | private: |
| 79 | command *cmd; |
| 80 | |
| 81 | friend class boost::serialization::access; |
| 82 | template<class Archive> |
| 83 | void serialize(Archive & ar, const unsigned int version); |
| 84 | |
| 85 | public: |
| 86 | command_container() |
| 87 | { cmd=0; } |
| 88 | command_container(command *_cmd) |
| 89 | { cmd=_cmd; } |
| 90 | |
| 91 | ~command_container(); |
| 92 | |
| 93 | /// return the contained command |
| 94 | command* get_command() |
| 95 | { return cmd; } |
| 96 | }; |
| 97 | |
| 98 | } // namespace libt2n |
| 99 | |
| 100 | BOOST_CLASS_TRACKING(libt2n::result_container, boost::serialization::track_never) |
| 101 | BOOST_CLASS_TRACKING(libt2n::command_container, boost::serialization::track_never) |
| 102 | |
| 103 | #endif |
| 104 | |