2008-06-02 17:41:35 -04:00
|
|
|
/*
|
2010-02-09 09:44:01 -05:00
|
|
|
Copyright (C) 2000-2010 Paul Davis
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __pbd_stateful_h__
|
|
|
|
#define __pbd_stateful_h__
|
|
|
|
|
|
|
|
#include <string>
|
2010-02-18 08:59:49 -05:00
|
|
|
#include <list>
|
2010-02-09 09:44:01 -05:00
|
|
|
#include <cassert>
|
2010-02-19 13:09:08 -05:00
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "pbd/id.h"
|
2010-02-09 09:44:01 -05:00
|
|
|
#include "pbd/xml++.h"
|
2010-03-01 19:00:00 -05:00
|
|
|
#include "pbd/property_basics.h"
|
2010-02-19 13:09:08 -05:00
|
|
|
#include "pbd/signals.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
class XMLNode;
|
|
|
|
|
|
|
|
namespace PBD {
|
|
|
|
|
|
|
|
namespace sys {
|
|
|
|
class path;
|
|
|
|
}
|
|
|
|
|
2010-03-01 19:00:00 -05:00
|
|
|
class PropertyList;
|
|
|
|
class OwnedPropertyList;
|
|
|
|
|
2010-02-09 09:44:01 -05:00
|
|
|
/** Base class for objects with saveable and undoable state */
|
2008-06-02 17:41:35 -04:00
|
|
|
class Stateful {
|
|
|
|
public:
|
2010-02-09 09:44:01 -05:00
|
|
|
Stateful ();
|
2008-06-02 17:41:35 -04:00
|
|
|
virtual ~Stateful();
|
|
|
|
|
|
|
|
virtual XMLNode& get_state (void) = 0;
|
2009-10-15 14:56:11 -04:00
|
|
|
virtual int set_state (const XMLNode&, int version) = 0;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2010-08-25 13:31:57 -04:00
|
|
|
virtual bool apply_changes (PropertyBase const &);
|
2010-08-25 13:31:33 -04:00
|
|
|
PropertyChange apply_changes (PropertyList const &);
|
|
|
|
|
2010-03-01 19:00:00 -05:00
|
|
|
const OwnedPropertyList& properties() const { return *_properties; }
|
2010-02-18 08:59:49 -05:00
|
|
|
|
2010-03-01 19:00:00 -05:00
|
|
|
void add_property (PropertyBase& s);
|
2010-02-09 09:44:01 -05:00
|
|
|
|
2010-02-18 08:59:49 -05:00
|
|
|
/* Extra XML node: so that 3rd parties can attach state to the XMLNode
|
|
|
|
representing the state of this object.
|
|
|
|
*/
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
void add_extra_xml (XMLNode&);
|
2011-06-11 11:35:34 -04:00
|
|
|
XMLNode *extra_xml (const std::string& str, bool add_if_missing = false);
|
|
|
|
void save_extra_xml (const XMLNode&);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
const PBD::ID& id() const { return _id; }
|
2011-10-18 09:18:47 -04:00
|
|
|
bool set_id (const XMLNode&);
|
|
|
|
void set_id (const std::string&);
|
|
|
|
void reset_id ();
|
|
|
|
|
2010-03-01 19:00:00 -05:00
|
|
|
/* history management */
|
|
|
|
|
2010-08-25 13:32:08 -04:00
|
|
|
void clear_changes ();
|
|
|
|
virtual void clear_owned_changes ();
|
2010-08-25 13:31:57 -04:00
|
|
|
PropertyList* get_changes_as_properties (Command *) const;
|
2010-08-25 21:44:11 -04:00
|
|
|
virtual void rdiff (std::vector<Command*> &) const;
|
2010-03-04 08:15:04 -05:00
|
|
|
bool changed() const;
|
|
|
|
|
2010-03-01 19:00:00 -05:00
|
|
|
/* create a property list from an XMLNode
|
|
|
|
*/
|
2010-08-25 13:31:41 -04:00
|
|
|
virtual PropertyList* property_factory (const XMLNode&) const;
|
2010-02-09 09:44:01 -05:00
|
|
|
|
2010-02-19 13:09:08 -05:00
|
|
|
/* How stateful's notify of changes to their properties
|
|
|
|
*/
|
|
|
|
PBD::Signal1<void,const PropertyChange&> PropertyChanged;
|
|
|
|
|
2009-10-15 14:56:11 -04:00
|
|
|
static int current_state_version;
|
|
|
|
static int loading_state_version;
|
|
|
|
|
2010-03-02 13:05:26 -05:00
|
|
|
virtual void suspend_property_changes ();
|
|
|
|
virtual void resume_property_changes ();
|
|
|
|
|
2012-10-29 12:13:33 -04:00
|
|
|
bool property_changes_suspended() const { return g_atomic_int_get (const_cast<gint*>(&_stateful_frozen)) > 0; }
|
2011-12-17 11:37:18 -05:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
protected:
|
|
|
|
|
2012-06-23 01:07:27 -04:00
|
|
|
void add_instant_xml (XMLNode&, const std::string& directory_path);
|
|
|
|
XMLNode *instant_xml (const std::string& str, const std::string& directory_path);
|
2010-02-18 08:59:49 -05:00
|
|
|
void add_properties (XMLNode &);
|
2010-08-25 13:31:33 -04:00
|
|
|
|
|
|
|
PropertyChange set_values (XMLNode const &);
|
2010-02-18 08:59:49 -05:00
|
|
|
|
|
|
|
/* derived classes can implement this to do cross-checking
|
|
|
|
of property values after either a PropertyList or XML
|
|
|
|
driven property change.
|
|
|
|
*/
|
2010-12-20 11:10:58 -05:00
|
|
|
virtual void post_set (const PropertyChange&) { };
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
XMLNode *_extra_xml;
|
|
|
|
XMLNode *_instant_xml;
|
2010-03-02 13:05:26 -05:00
|
|
|
PBD::PropertyChange _pending_changed;
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex _lock;
|
2010-02-09 09:44:01 -05:00
|
|
|
|
|
|
|
std::string _xml_node_name; ///< name of node to use for this object in XML
|
2010-03-01 19:00:00 -05:00
|
|
|
OwnedPropertyList* _properties;
|
2010-03-02 13:05:26 -05:00
|
|
|
|
|
|
|
virtual void send_change (const PropertyChange&);
|
|
|
|
/** derived classes can implement this in order to process a property change
|
|
|
|
within thaw() just before send_change() is called.
|
|
|
|
*/
|
|
|
|
virtual void mid_thaw (const PropertyChange&) { }
|
2011-10-18 09:18:47 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
PBD::ID _id;
|
2012-10-29 12:13:33 -04:00
|
|
|
gint _stateful_frozen;
|
2008-06-02 17:41:35 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace PBD
|
|
|
|
|
|
|
|
#endif /* __pbd_stateful_h__ */
|
|
|
|
|