00001 // Torc - Copyright 2011 University of Southern California. All Rights Reserved. 00002 // $HeadURL: https://torc-isi.svn.sourceforge.net/svnroot/torc-isi/branches/staging/0.9/src/torc/generic/om/Visitable.hpp $ 00003 // $Id: Visitable.hpp 10 2011-10-12 18:40:16Z nsteiner $ 00004 00005 // This program is free software: you can redistribute it and/or modify it under the terms of the 00006 // GNU General Public License as published by the Free Software Foundation, either version 3 of the 00007 // License, or (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 00010 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 00011 // the GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License along with this program. If 00014 // not, see <http://www.gnu.org/licenses/>. 00015 00016 #ifndef TORC_GENERIC_OM_VISITABLE_HPP 00017 #define TORC_GENERIC_OM_VISITABLE_HPP 00018 00019 #include "torc/generic/om/DumpRestoreConfig.hpp" 00020 00021 #ifdef GENOM_SERIALIZATION 00022 #include <boost/serialization/access.hpp> 00023 #include <boost/serialization/is_abstract.hpp> 00024 #endif //GENOM_SERIALIZATION 00025 00026 #include "torc/generic/util/Error.hpp" 00027 00028 namespace torc { namespace generic { class BaseVisitor; } } 00029 00030 namespace torc { 00031 00032 namespace generic { 00033 00034 /** 00035 * @brief An object that receives a inoutVisitor 00036 * 00037 * The Visitable class provides an interface to all classes that want to make themselves visitable by the clients. Typically such classes will be leaf types that cannot be directly accessed by clients without using a dynamic_cast. This design is loosely based on the acyclic inoutVisitor concept defined by Alexandrescu in "Modern C++ Design". 00038 */ 00039 class Visitable 00040 { 00041 #ifdef GENOM_SERIALIZATION 00042 friend class boost::serialization::access; 00043 #endif 00044 protected: 00045 Visitable(); 00046 00047 00048 public: 00049 virtual 00050 ~Visitable() throw(); 00051 00052 00053 private: 00054 Visitable(const Visitable & source) throw(); 00055 00056 Visitable & operator=(const Visitable & source) throw(); 00057 00058 00059 public: 00060 /** 00061 * Recive a inoutVisitor to this class. The visit method of the inoutVisitor is called and a reference to this object is passed as a parameter. It has to be noted however, that a dynamic_cast is performed inside this method. If the cast fails, an appropriate exception is thrown by this method. This sitation can arise when the passed Visitor object does not inherit from the appropriate inoutVisitor specialization. See Visitor documentation for more details. 00062 * 00063 * @param[in,out] inoutVisitor A reference to the inoutVisitor object 00064 * @exception Error Visitor type inappropriate for visiting this object or any other error thrown by the Visitor::throw() method. 00065 */ 00066 virtual void 00067 accept(BaseVisitor & inoutVisitor) throw(Error) = 0; 00068 00069 public: 00070 #ifdef GENOM_SERIALIZATION 00071 template<class Archive> void 00072 serialize( Archive &ar, unsigned int ); 00073 #endif //GENOM_SERIALIZATION 00074 00075 }; 00076 00077 } // namespace torc::generic 00078 00079 } // namespace torc 00080 00081 #ifdef GENOM_SERIALIZATION 00082 BOOST_IS_ABSTRACT( torc::generic::Visitable ) 00083 #endif //GENOM_SERIALIZATION 00084 00085 #endif // TORC_GENERIC_OM_VISITABLE_HPP