torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Visitable.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_VISITABLE_HPP
17 #define TORC_GENERIC_VISITABLE_HPP
18 
19 #ifdef GENOM_SERIALIZATION
20 #include <boost/serialization/access.hpp>
21 #include <boost/serialization/is_abstract.hpp>
22 #endif //GENOM_SERIALIZATION
23 #include "torc/generic/Error.hpp"
24 
25 namespace torc { namespace generic { class BaseVisitor; } }
26 
27 namespace torc {
28 namespace generic {
29 
30 /**
31  * @brief An object that receives an inoutVisitor
32  *
33  * The Visitable class provides an interface to all classes that want to make themselves visitable
34  * by the clients. Typically such classes will be leaf types that cannot be directly accessed by
35  * clients without using a dynamic_cast. This design is loosely based on the acyclic inoutVisitor
36  * concept defined by Alexandrescu in "Modern C++ Design".
37  */
38 class Visitable {
39 #ifdef GENOM_SERIALIZATION
40  friend class boost::serialization::access;
41 #endif
42 protected:
43  Visitable();
44 
45 public:
46  virtual ~Visitable() throw ();
47 
48 private:
49  Visitable(const Visitable& source);
50 
51  Visitable& operator=(const Visitable& source);
52 
53 public:
54  /**
55  * Receive an inoutVisitor to this class. The visit method of the inoutVisitor is called and a
56  * reference to this object is passed as a parameter. It has to be noted however, that a
57  * dynamic_cast is performed inside this method. If the cast fails, an appropriate exception is
58  * thrown by this method. This situation can arise when the passed Visitor object does not
59  * inherit from the appropriate inoutVisitor specialization. See Visitor documentation for more
60  * details.
61  *
62  * @param[in,out] inoutVisitor A reference to the inoutVisitor object
63  * @exception Error Visitor type inappropriate for visiting this object or any other error
64  * thrown by the Visitor::throw() method.
65  */
66  virtual void accept(BaseVisitor& inoutVisitor) throw (Error) = 0;
67 
68 public:
69 #ifdef GENOM_SERIALIZATION
70  template <class Archive> void serialize(Archive& ar, unsigned int);
71 #endif //GENOM_SERIALIZATION
72 };
73 
74 } // namespace generic
75 } // namespace torc
76 
77 #ifdef GENOM_SERIALIZATION
78 BOOST_IS_ABSTRACT(torc::generic::Visitable)
79 #endif // GENOM_SERIALIZATION
80 #endif // TORC_GENERIC_VISITABLE_HPP
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
A base class for Visitor.
Definition: VisitorType.hpp:31
Visitable & operator=(const Visitable &source)
virtual void accept(BaseVisitor &inoutVisitor)=0
An object that receives an inoutVisitor.
Definition: Visitable.hpp:38