BaseVisitable.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/common/BaseVisitable.h
22 
23  \brief The root of all hierarchies that can be visited.
24 */
25 
26 #ifndef __TERRALIB_COMMON_INTERNAL_BASEVISITABLE_H
27 #define __TERRALIB_COMMON_INTERNAL_BASEVISITABLE_H
28 
29 namespace te
30 {
31  namespace common
32  {
33  /*!
34  \class BaseVisitable
35 
36  \brief The root of all hierarchies that can be visited.
37 
38  This class defines a pure virtual function that subclasses must implement
39  in order to be visited.
40 
41  This function may return values (see the R type in template declaration).
42 
43  Requirements on types:
44  <ul>
45  <li>T: the type of visitor;</li>
46  <li>R: the return type for the accept method.</li>
47  </ul>
48 
49  \ingroup common
50 
51  \sa BaseVisitor, Visitor
52  */
53  template<class T, class R = void> class BaseVisitable
54  {
55  public:
56 
57  typedef T VisitorType;
58  typedef R ReturnType;
59 
60  /*!
61  \brief It call the visit method from the guest object.
62 
63  \param guest The guest or visitor.
64 
65  \return Any valid value define by the template type R.
66  */
67  virtual ReturnType accept(VisitorType& guest) const = 0;
68 
69  protected:
70 
71  /*! \brief Destructor. */
72  virtual ~BaseVisitable() {}
73  };
74 
75 #define TE_DEFINE_VISITABLE \
76  virtual ReturnType accept(VisitorType& guest) const \
77  { return guest.visit(*this); }
78 
79  } // end namespace common
80 } // end namespace te
81 
82 #endif // __TERRALIB_COMMON_INTERNAL_BASEVISITABLE_H
83 
84 
85 
virtual ~BaseVisitable()
Destructor.
Definition: BaseVisitable.h:72
The root of all hierarchies that can be visited.
Definition: BaseVisitable.h:53
URI C++ Library.
virtual ReturnType accept(VisitorType &guest) const =0
It call the visit method from the guest object.