summaryrefslogtreecommitdiff
path: root/TAO/CIAO/CCF/CCF/CompilerElements/Traversal.hpp
blob: 86066ee7a636095061883d1dace2aeefbf30cc53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef TRAVERSAL_HPP
#define TRAVERSAL_HPP

#include "MSVC_Pragmas.hpp"

namespace CCF
{
  namespace Traversal
  {
    struct Visitor
    {
      virtual
      ~Visitor () /*@@= 0*/ {}
    };


    template <typename VisitorType>
    bool
    try_visit (
      void (VisitorType::*visit_func)(typename VisitorType::NodePtr const&),
      Visitor* v,
      typename VisitorType::NodePtr const& n)
    {
      VisitorType* vt = dynamic_cast<VisitorType*> (v);
      if(vt != 0)
      {
        (vt->*visit_func)(n);
        return true;
      }
      else
      {
        return false;
      }
    }
  }
}

#endif // TRAVERSAL_HPP