torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Cloneable.hpp
Go to the documentation of this file.
1 // Torc - Copyright 2011-2013 University of Southern California. All Rights Reserved.
2 // $HeadURL$
3 // $Id$
4 
5 // This program is free software: you can redistribute it and/or modify it under the terms of the
6 // GNU General Public License as published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
11 // the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program. If
14 // not, see <http://www.gnu.org/licenses/>.
15 
16 #ifndef TORC_GENERIC_CLONEABLE_HPP
17 #define TORC_GENERIC_CLONEABLE_HPP
18 
19 //BOOST
20 #include <boost/shared_ptr.hpp>
21 
22 #ifdef GENOM_SERIALIZATION
23 #include <boost/serialization/access.hpp>
24 #include <boost/serialization/weak_ptr.hpp>
25 #endif //GENOM_SERIALIZATION
26 /**
27  * @file Cloneable.hpp
28  * @brief Interface for Cloneable
29  *
30  * This file contains the interface for the Cloneable class
31  */
32 namespace torc {
33 namespace generic {
34 
35 /**
36  * @brief Represents all EOM classes that can be cloned(copied).
37  *
38  * The Cloneable class defines a method called clone() that is overridden by derived classes to
39  * provide a polymorphic copy operation.
40  */
41 template <class _CloneableType> class Cloneable {
42 #ifdef GENOM_SERIALIZATION
43  friend class boost::serialization::access;
44 #endif
45 protected:
46  /**
47  * Constructor to be used by inheriting classes
48  */
49  Cloneable();
50 
51 public:
52  virtual ~Cloneable() throw ();
53 
54 private:
55  Cloneable(const Cloneable<_CloneableType>& source);
56 
58 
59 public:
60  /**
61  * Create a copy of this object. This method is polymorphic.
62  *
63  * @return Pointer to a copy of this object
64  */
65  virtual boost::shared_ptr<_CloneableType>
66  clone() = 0;
67 
68 #ifdef GENOM_SERIALIZATION
69  template <class Archive> void serialize(Archive& ar, unsigned int);
70 #endif //GENOM_SERIALIZATION
71 };
72 /**
73  * Constructor to be used by inheriting classes
74  */
75 template <class _CloneableType> Cloneable<_CloneableType>::Cloneable() {}
76 
77 template <class _CloneableType> Cloneable<_CloneableType>::~Cloneable() throw () {}
78 
79 #ifdef GENOM_SERIALIZATION
80 template <class _CloneableType> template <class Archive> void
81 Cloneable<_CloneableType>::serialize(Archive& ar, unsigned int) {}
82 #endif //GENOM_SERIALIZATION
83 } // namespace generic
84 } // namespace torc
85 
86 #endif // TORC_GENERIC_CLONEABLE_HPP
Cloneable< _CloneableType > & operator=(const Cloneable< _CloneableType > &source)
Represents all EOM classes that can be cloned(copied).
Definition: Cloneable.hpp:41
virtual boost::shared_ptr< _CloneableType > clone()=0