2007-11-28 04:19:21 +01:00
|
|
|
/*
|
|
|
|
|
VISITOR.hpp - Acyclic Visitor library
|
|
|
|
|
|
|
|
|
|
Copyright (C) CinelerraCV
|
|
|
|
|
2007, Hermann Vosseler <Ichthyostega@web.de>
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
|
|
|
|
published by the Free Software Foundation; either version 2 of the
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
|
|
====================================================================
|
|
|
|
|
This code is heavily inspired by
|
|
|
|
|
The Loki Library (loki-lib/trunk/include/loki/Visitor.h)
|
|
|
|
|
Copyright (c) 2001 by Andrei Alexandrescu
|
|
|
|
|
This Loki code accompanies the book:
|
|
|
|
|
Alexandrescu, Andrei. "Modern C++ Design: Generic Programming
|
|
|
|
|
and Design Patterns Applied".
|
|
|
|
|
Copyright (c) 2001. Addison-Wesley. ISBN 0201704315
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef CINELERRA_VISITORPOLICIES_H
|
|
|
|
|
#define CINELERRA_VISITORPOLICIES_H
|
|
|
|
|
|
|
|
|
|
#include "common/error.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace cinelerra
|
|
|
|
|
{
|
|
|
|
|
namespace visitor
|
|
|
|
|
{
|
|
|
|
|
/* == several Policies usable in conjunction with cinelerra::visitor::Visitable == */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Policy returning just the default return value in case
|
|
|
|
|
* of encountering an unknown Visitor (typically caused by
|
|
|
|
|
* adding a new class to the visitable hierarchy)
|
|
|
|
|
*/
|
2007-11-29 07:07:14 +01:00
|
|
|
template<typename RET,class TAR,class TOOL>
|
2007-11-28 04:19:21 +01:00
|
|
|
struct UseDefault
|
|
|
|
|
{
|
|
|
|
|
static RET onUnknown (TAR&, TOOL&)
|
|
|
|
|
{
|
|
|
|
|
return RET();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Policy to throw when encountering an unknown visiting tool
|
|
|
|
|
*/
|
2007-11-29 07:07:14 +01:00
|
|
|
template<typename RET,class TAR,class TOOL>
|
2007-11-28 04:19:21 +01:00
|
|
|
struct ThrowException
|
|
|
|
|
{
|
|
|
|
|
static RET onUnknown (TAR&, TOOL&)
|
|
|
|
|
{
|
|
|
|
|
throw cinelerra::error::Config("unable to decide what tool operation to call");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Policy invoking an catch-all function for processing
|
|
|
|
|
* an unknown tool / target pair
|
2007-11-29 07:07:14 +01:00
|
|
|
* @note using this policy effectively enforces
|
|
|
|
|
* implementing a catch-all function \c treat(TAR&)
|
2007-11-28 04:19:21 +01:00
|
|
|
*/
|
2007-11-29 07:07:14 +01:00
|
|
|
template<typename RET,class TAR,class TOOL>
|
2007-11-28 04:19:21 +01:00
|
|
|
struct InvokeCatchAllFunction
|
|
|
|
|
{
|
|
|
|
|
static RET onUnknown (TAR& target,TOOL& tool)
|
|
|
|
|
{
|
2007-12-22 08:45:09 +01:00
|
|
|
//tool.treat (target);
|
|
|
|
|
tool.catchy (target);
|
2007-11-28 04:19:21 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace visitor
|
|
|
|
|
|
|
|
|
|
} // namespace cinelerra
|
|
|
|
|
#endif
|