2008-01-14 01:01:11 +01:00
|
|
|
/*
|
|
|
|
|
DEFSMANAGER.hpp - access to preconfigured default objects and definitions
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2008-03-10 08:38:59 +01:00
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2008, Hermann Vosseler <Ichthyostega@web.de>
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2008-01-14 01:01:11 +01:00
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
2010-12-17 23:28:49 +01:00
|
|
|
published by the Free Software Foundation; either version 2 of
|
|
|
|
|
the License, or (at your option) any later version.
|
|
|
|
|
|
2008-01-14 01:01:11 +01:00
|
|
|
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.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2008-01-14 01:01:11 +01:00
|
|
|
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.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2008-01-14 01:01:11 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef MOBJECT_SESSION_DEFSMANAGER_H
|
|
|
|
|
#define MOBJECT_SESSION_DEFSMANAGER_H
|
|
|
|
|
|
|
|
|
|
|
2008-12-17 17:53:32 +01:00
|
|
|
#include "lib/p.hpp"
|
|
|
|
|
#include "lib/query.hpp"
|
2008-01-14 01:01:11 +01:00
|
|
|
|
2008-03-31 03:21:28 +02:00
|
|
|
#include <boost/scoped_ptr.hpp>
|
2010-06-20 04:30:42 +02:00
|
|
|
#include <boost/noncopyable.hpp>
|
2008-01-14 01:01:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-09-09 06:16:42 +02:00
|
|
|
namespace mobject {
|
|
|
|
|
namespace session {
|
|
|
|
|
|
|
|
|
|
|
2008-05-19 08:46:19 +02:00
|
|
|
using lumiera::P;
|
2008-03-31 03:21:28 +02:00
|
|
|
using boost::scoped_ptr;
|
|
|
|
|
|
2008-09-10 04:42:09 +02:00
|
|
|
namespace impl { class DefsRegistry; }
|
2008-01-14 01:01:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-12-28 05:36:37 +01:00
|
|
|
* Organise a collection of preconfigured default objects.
|
|
|
|
|
* For various kinds of objects we can tweak the default parametrisation
|
2008-01-14 01:01:11 +01:00
|
|
|
* as part of the general session configuration. A ref to an instance of
|
|
|
|
|
* this class is accessible through the current session and can be used
|
|
|
|
|
* to fill in parts of the configuration of new objects, if the user
|
|
|
|
|
* code didn't give more specific parameters. Necessary sub-objects
|
|
|
|
|
* will be created on demand, and any default configuration, once
|
|
|
|
|
* found, will be remembered and stored with the current session.
|
2009-12-12 03:50:41 +01:00
|
|
|
*
|
|
|
|
|
* @note while the logic of defaults handling can be considered
|
|
|
|
|
* roughly final, as of 12/09 most of the actual object
|
|
|
|
|
* handling is placeholder code.
|
2008-01-14 01:01:11 +01:00
|
|
|
*/
|
2008-03-31 03:21:28 +02:00
|
|
|
class DefsManager : private boost::noncopyable
|
2008-01-14 01:01:11 +01:00
|
|
|
{
|
2008-09-10 04:42:09 +02:00
|
|
|
scoped_ptr<impl::DefsRegistry> defsRegistry;
|
2008-03-31 03:21:28 +02:00
|
|
|
|
2009-11-09 07:35:08 +01:00
|
|
|
public:
|
2008-01-14 01:01:11 +01:00
|
|
|
|
|
|
|
|
DefsManager () throw();
|
2008-09-09 06:16:42 +02:00
|
|
|
~DefsManager ();
|
|
|
|
|
|
2008-02-29 04:27:24 +01:00
|
|
|
/** common access point: retrieve the default object fulfilling
|
|
|
|
|
* some given conditions. May silently trigger object creation.
|
|
|
|
|
* @throw error::Config in case no solution is possible, which
|
|
|
|
|
* is considered \e misconfiguration.
|
|
|
|
|
*/
|
2008-01-14 01:01:11 +01:00
|
|
|
template<class TAR>
|
2010-10-24 06:50:00 +02:00
|
|
|
P<TAR> operator() (lumiera::Query<TAR> const&);
|
2008-01-14 01:01:11 +01:00
|
|
|
|
2008-03-31 03:21:28 +02:00
|
|
|
|
2008-02-29 04:27:24 +01:00
|
|
|
/** search through the registered defaults, never create anything.
|
|
|
|
|
* @return object fulfilling the query, \c empty ptr if not found.
|
|
|
|
|
*/
|
|
|
|
|
template<class TAR>
|
2010-10-24 06:50:00 +02:00
|
|
|
P<TAR> search (lumiera::Query<TAR> const&);
|
2008-02-29 04:27:24 +01:00
|
|
|
|
|
|
|
|
/** retrieve an object fulfilling the query and register it as default.
|
|
|
|
|
* The resolution is delegated to the ConfigQuery system (which may cause
|
|
|
|
|
* creation of new object instances)
|
|
|
|
|
* @return object fulfilling the query, \c empty ptr if no solution.
|
|
|
|
|
*/
|
|
|
|
|
template<class TAR>
|
2010-10-24 06:50:00 +02:00
|
|
|
P<TAR> create (lumiera::Query<TAR> const&);
|
2008-02-29 04:27:24 +01:00
|
|
|
|
2008-12-28 05:36:37 +01:00
|
|
|
/** register the given object as default, after ensuring it fulfils the
|
2008-02-29 04:27:24 +01:00
|
|
|
* query. The latter may cause some properties of the object to be set,
|
|
|
|
|
* trigger creation of additional objects, and may fail altogether.
|
2008-12-28 05:36:37 +01:00
|
|
|
* @return true if query was successful and object is registered as default
|
2008-02-29 04:27:24 +01:00
|
|
|
* @note only a weak ref to the object is stored
|
|
|
|
|
*/
|
|
|
|
|
template<class TAR>
|
2010-11-05 04:32:35 +01:00
|
|
|
bool define (P<TAR> const&, lumiera::Query<TAR> const& =lumiera::Query<TAR>());
|
2008-02-29 04:27:24 +01:00
|
|
|
|
|
|
|
|
/** remove the defaults registration of the given object, if there was such
|
|
|
|
|
* @return false if nothing has been changed because the object wasn't registered
|
|
|
|
|
*/
|
|
|
|
|
template<class TAR>
|
2010-10-24 06:50:00 +02:00
|
|
|
bool forget (P<TAR> const&);
|
2008-02-29 04:27:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// Q: can we have something along the line of...?
|
|
|
|
|
//
|
2008-01-28 06:05:46 +01:00
|
|
|
// template
|
|
|
|
|
// < class TAR, ///< the target to query for
|
|
|
|
|
// template <class> class SMP ///< smart pointer class to wrap the result
|
|
|
|
|
// >
|
2008-03-10 08:38:59 +01:00
|
|
|
// SMP<TAR> operator() (const lumiera::Query<TAR>&);
|
2009-12-12 03:50:41 +01:00
|
|
|
|
|
|
|
|
// 12/09: according to my current knowledge of template metaprogramming, the answer is "no",
|
|
|
|
|
// but we could use a traits template to set up a fixed association of smart pointers
|
|
|
|
|
// and kinds of target object. This would allow to define a templated operator() returning
|
|
|
|
|
// the result wrapped into the right holder. But currently I don't see how to build a sensible
|
|
|
|
|
// implementation infrastructure backing such an interface.
|
|
|
|
|
//////////TICKET #452
|
2008-01-28 06:05:46 +01:00
|
|
|
|
2008-01-14 01:01:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace mobject::session
|
|
|
|
|
|
|
|
|
|
} // namespace mobject
|
|
|
|
|
#endif
|