2006-01-02 10:54:13 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// The Loki Library
|
|
|
|
|
// Copyright (c) 2006 Peter K<>mmel
|
|
|
|
|
// Permission to use, copy, modify, distribute and sell this software for any
|
|
|
|
|
// purpose is hereby granted without fee, provided that the above copyright
|
|
|
|
|
// notice appear in all copies and that both that copyright notice and this
|
|
|
|
|
// permission notice appear in supporting documentation.
|
|
|
|
|
// The author makes no representations about the
|
|
|
|
|
// suitability of this software for any purpose. It is provided "as is"
|
|
|
|
|
// without express or implied warranty.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2006-01-25 18:34:11 +00:00
|
|
|
|
// $Header$
|
2006-01-02 10:54:13 +00:00
|
|
|
|
|
|
|
|
|
#include <loki/Visitor.h>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Base : public Loki::BaseVisitable<>
|
|
|
|
|
{
|
|
|
|
|
public:
|
2006-01-09 07:27:01 +00:00
|
|
|
|
LOKI_DEFINE_VISITABLE()
|
2006-01-02 10:54:13 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Type1 : public Base
|
|
|
|
|
{
|
|
|
|
|
public:
|
2006-01-09 07:27:01 +00:00
|
|
|
|
LOKI_DEFINE_VISITABLE()
|
2006-01-02 10:54:13 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class VariableVisitor :
|
2006-01-09 07:27:01 +00:00
|
|
|
|
public Loki::BaseVisitor,
|
|
|
|
|
//public Loki::Visitor<Base>,
|
|
|
|
|
//public Loki::Visitor<Type1>
|
|
|
|
|
public Loki::Visitor<LOKI_TYPELIST_2(Base,Type1)>
|
|
|
|
|
//public Loki::Visitor<Loki::Seq<Base,Type1>::Type>
|
2006-01-02 10:54:13 +00:00
|
|
|
|
{
|
|
|
|
|
public:
|
2006-01-09 07:27:01 +00:00
|
|
|
|
void Visit(Base&){std::cout << "void Visit(Base&)\n";}
|
|
|
|
|
void Visit(Type1&){std::cout << "void Visit(Type1&)\n";}
|
2006-01-02 10:54:13 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CBase : public Loki::BaseVisitable<void, Loki::DefaultCatchAll, true>
|
|
|
|
|
{
|
|
|
|
|
public:
|
2006-01-09 07:27:01 +00:00
|
|
|
|
LOKI_DEFINE_CONST_VISITABLE()
|
2006-01-02 10:54:13 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class CType1 : public CBase
|
|
|
|
|
{
|
|
|
|
|
public:
|
2006-01-09 07:27:01 +00:00
|
|
|
|
LOKI_DEFINE_CONST_VISITABLE()
|
2006-01-02 10:54:13 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class CVariableVisitor :
|
2006-01-09 07:27:01 +00:00
|
|
|
|
public Loki::BaseVisitor,
|
|
|
|
|
//public Loki::Visitor<CBase,void,true>,
|
|
|
|
|
//public Loki::Visitor<CType1,void,true>
|
|
|
|
|
public Loki::Visitor<LOKI_TYPELIST_2(CBase,CType1),void,true>
|
|
|
|
|
//public Loki::Visitor<Loki::Seq<CBase,CType1>::Type,void,true>
|
2006-01-02 10:54:13 +00:00
|
|
|
|
{
|
|
|
|
|
public:
|
2006-01-09 07:27:01 +00:00
|
|
|
|
void Visit(const CBase&){std::cout << "void Visit(CBase&)\n";}
|
|
|
|
|
void Visit(const CType1&){std::cout << "void Visit(CType1&)\n";}
|
2006-01-02 10:54:13 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
2006-01-09 07:27:01 +00:00
|
|
|
|
VariableVisitor visitor;
|
|
|
|
|
Type1 type1;
|
|
|
|
|
Base* dyn = &type1;
|
|
|
|
|
dyn->Accept(visitor);
|
2006-01-02 10:54:13 +00:00
|
|
|
|
|
2006-01-09 07:27:01 +00:00
|
|
|
|
CVariableVisitor cvisitor;
|
|
|
|
|
CType1 ctype1;
|
|
|
|
|
CBase* cdyn = &ctype1;
|
|
|
|
|
cdyn->Accept(cvisitor);
|
2006-01-05 17:21:13 +00:00
|
|
|
|
|
|
|
|
|
#if defined(__BORLANDC__) || defined(_MSC_VER)
|
|
|
|
|
system("PAUSE");
|
|
|
|
|
#endif
|
|
|
|
|
|
2006-01-02 10:54:13 +00:00
|
|
|
|
}
|