Change license from LGPL to GPL version 2 + linking exception. This fixes C++ templat...
[libt2n] / src / t2n_exception.hxx
index 7b68c21..4ca7c07 100644 (file)
@@ -1,21 +1,24 @@
-/***************************************************************************
- *   Copyright (C) 2006 by Gerd v. Egidy                                   *
- *   gve@intra2net.com                                                     *
- *                                                                         *
- *   This library is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU Lesser General Public License version   *
- *   2.1 as published by the Free Software Foundation.                     *
- *                                                                         *
- *   This library is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU Lesser General Public License for more details.                   *
- *                                                                         *
- *   You should have received a copy of the GNU Lesser General Public      *
- *   License along with this program; if not, write to the                 *
- *   Free Software Foundation, Inc.,                                       *
- *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
- ***************************************************************************/
+/*
+Copyright (C) 2006 by Intra2net AG - Gerd v. Egidy
+
+The software in this package is distributed under the GNU General
+Public License version 2 (with a special exception described below).
+
+A copy of GNU General Public License (GPL) is included in this distribution,
+in the file COPYING.GPL.
+
+As a special exception, if other files instantiate templates or use macros
+or inline functions from this file, or you compile this file and link it
+with other works to produce a work based on this file, this file
+does not by itself cause the resulting work to be covered
+by the GNU General Public License.
+
+However the source code for this file must still be made available
+in accordance with section (3) of the GNU General Public License.
+
+This exception does not invalidate any other reasons why a work based
+on this file might be covered by the GNU General Public License.
+*/
 #ifndef __LIBT2N_T2N_EXCEPTION
 #define __LIBT2N_T2N_EXCEPTION
 
 #include <string>
 
 #include <boost/serialization/serialization.hpp>
-#include <boost/serialization/export.hpp>
 
-// serialization for std::exception
 namespace boost {
 namespace serialization {
 
+// make std::exception serializable
 template<class Archive>
 void serialize(Archive & ar, std::exception & g, const unsigned int version)
 {
@@ -39,8 +41,10 @@ void serialize(Archive & ar, std::exception & g, const unsigned int version)
 
 namespace libt2n
 {
-
-/// a generic exception that can be handeled with libt2n
+/** @brief a generic exception that can be handeled with libt2n
+    @note don't derive the exceptions your application generates directly from this one
+          but use libt2n::t2n_runtime_error for this
+*/
 class t2n_exception : public std::exception
 {
     private:
@@ -48,11 +52,7 @@ class t2n_exception : public std::exception
 
         friend class boost::serialization::access;
         template<class Archive>
-        void serialize(Archive & ar, const unsigned int version)
-        {
-            ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(exception);
-            ar & BOOST_SERIALIZATION_NVP(message);
-        }
+        void serialize(Archive & ar, const unsigned int version);
 
     public:
         t2n_exception(const std::string& _message)
@@ -73,7 +73,6 @@ class t2n_exception : public std::exception
         virtual void do_throw()
             { throw *this; }
 };
-BOOST_CLASS_EXPORT(t2n_exception)
 
 /// a (unspecified) problem with libt2n communication
 class t2n_communication_error : public t2n_exception
@@ -81,10 +80,7 @@ class t2n_communication_error : public t2n_exception
     private:
         friend class boost::serialization::access;
         template<class Archive>
-        void serialize(Archive & ar, const unsigned int version)
-        {
-            ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_exception);
-        }
+        void serialize(Archive & ar, const unsigned int version);
 
     public:
         t2n_communication_error(const std::string& _message)
@@ -100,7 +96,6 @@ class t2n_communication_error : public t2n_exception
         void do_throw()
             { throw *this; }
 };
-BOOST_CLASS_EXPORT(t2n_communication_error)
 
 /// can't connect to libt2n server
 class t2n_connect_error : public t2n_communication_error
@@ -108,10 +103,7 @@ class t2n_connect_error : public t2n_communication_error
     private:
         friend class boost::serialization::access;
         template<class Archive>
-        void serialize(Archive & ar, const unsigned int version)
-        {
-            ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_communication_error);
-        }
+        void serialize(Archive & ar, const unsigned int version);
 
     public:
         t2n_connect_error(const std::string& _message)
@@ -127,7 +119,6 @@ class t2n_connect_error : public t2n_communication_error
         void do_throw()
             { throw *this; }
 };
-BOOST_CLASS_EXPORT(t2n_connect_error)
 
 /// error establishing a socket on the server (only thrown on the server-side)
 class t2n_server_error : public t2n_communication_error
@@ -135,10 +126,7 @@ class t2n_server_error : public t2n_communication_error
     private:
         friend class boost::serialization::access;
         template<class Archive>
-        void serialize(Archive & ar, const unsigned int version)
-        {
-            ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_communication_error);
-        }
+        void serialize(Archive & ar, const unsigned int version);
 
     public:
         t2n_server_error(const std::string& _message)
@@ -154,7 +142,6 @@ class t2n_server_error : public t2n_communication_error
         void do_throw()
             { throw *this; }
 };
-BOOST_CLASS_EXPORT(t2n_server_error)
 
 /// error transmitting or receiving libt2n messages
 class t2n_transfer_error : public t2n_communication_error
@@ -162,10 +149,7 @@ class t2n_transfer_error : public t2n_communication_error
     private:
         friend class boost::serialization::access;
         template<class Archive>
-        void serialize(Archive & ar, const unsigned int version)
-        {
-            ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_communication_error);
-        }
+        void serialize(Archive & ar, const unsigned int version);
 
     public:
         t2n_transfer_error(const std::string& _message)
@@ -181,7 +165,6 @@ class t2n_transfer_error : public t2n_communication_error
         void do_throw()
             { throw *this; }
 };
-BOOST_CLASS_EXPORT(t2n_transfer_error)
 
 /// tried to talk to an incompatible libt2n version
 class t2n_version_mismatch : public t2n_communication_error
@@ -189,10 +172,7 @@ class t2n_version_mismatch : public t2n_communication_error
     private:
         friend class boost::serialization::access;
         template<class Archive>
-        void serialize(Archive & ar, const unsigned int version)
-        {
-            ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_communication_error);
-        }
+        void serialize(Archive & ar, const unsigned int version);
 
     public:
         t2n_version_mismatch(const std::string& _message)
@@ -208,7 +188,6 @@ class t2n_version_mismatch : public t2n_communication_error
         void do_throw()
             { throw *this; }
 };
-BOOST_CLASS_EXPORT(t2n_version_mismatch)
 
 /// illegal libt2n command received
 class t2n_command_error : public t2n_exception
@@ -216,10 +195,7 @@ class t2n_command_error : public t2n_exception
     private:
         friend class boost::serialization::access;
         template<class Archive>
-        void serialize(Archive & ar, const unsigned int version)
-        {
-            ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_exception);
-        }
+        void serialize(Archive & ar, const unsigned int version);
 
     public:
         t2n_command_error(const std::string& _message)
@@ -235,7 +211,6 @@ class t2n_command_error : public t2n_exception
         void do_throw()
             { throw *this; }
 };
-BOOST_CLASS_EXPORT(t2n_command_error)
 
 /// error serializing or deserializing a libt2n command packet
 class t2n_serialization_error : public t2n_exception
@@ -243,10 +218,7 @@ class t2n_serialization_error : public t2n_exception
     private:
         friend class boost::serialization::access;
         template<class Archive>
-        void serialize(Archive & ar, const unsigned int version)
-        {
-            ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_exception);
-        }
+        void serialize(Archive & ar, const unsigned int version);
 
     public:
         t2n_serialization_error(const std::string& _message)
@@ -262,21 +234,18 @@ class t2n_serialization_error : public t2n_exception
         void do_throw()
             { throw *this; }
 };
-BOOST_CLASS_EXPORT(t2n_serialization_error)
 
-/**
- a runtime error within the remote function
+/** @brief a runtime error within the remote function.
  derive your own custom exceptions from this one
+
+ @note you must override the virtual clone method if you do so (used by libt2n::command_server::handle())
 */
 class t2n_runtime_error : public t2n_exception
 {
     private:
         friend class boost::serialization::access;
         template<class Archive>
-        void serialize(Archive & ar, const unsigned int version)
-        {
-            ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_exception);
-        }
+        void serialize(Archive & ar, const unsigned int version);
 
     public:
         t2n_runtime_error(const std::string& _message)
@@ -292,8 +261,9 @@ class t2n_runtime_error : public t2n_exception
         void do_throw()
             { throw *this; }
 };
-BOOST_CLASS_EXPORT(t2n_runtime_error)
 
-}
+}  // namespace libt2n
+
+#include "t2n_exception.tcc"
 
 #endif