2008-06-02 17:41:35 -04:00
|
|
|
/*
|
2015-10-04 14:51:05 -04:00
|
|
|
Copyright (C) 2000-2001 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.
|
|
|
|
|
|
|
|
$Id: stateful.cc 629 2006-06-21 23:01:03Z paul $
|
|
|
|
*/
|
|
|
|
|
2013-07-16 13:00:49 -04:00
|
|
|
#ifdef COMPILER_MSVC
|
|
|
|
#include <io.h> // Microsoft's nearest equivalent to <unistd.h>
|
|
|
|
#else
|
2008-06-02 17:41:35 -04:00
|
|
|
#include <unistd.h>
|
2013-07-16 13:00:49 -04:00
|
|
|
#endif
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2012-06-23 01:07:27 -04:00
|
|
|
#include <glibmm/fileutils.h>
|
|
|
|
#include <glibmm/miscutils.h>
|
|
|
|
|
2010-03-01 19:00:00 -05:00
|
|
|
#include "pbd/debug.h"
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "pbd/stateful.h"
|
2010-03-01 19:00:00 -05:00
|
|
|
#include "pbd/property_list.h"
|
|
|
|
#include "pbd/properties.h"
|
2009-12-17 13:24:23 -05:00
|
|
|
#include "pbd/destructible.h"
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "pbd/xml++.h"
|
|
|
|
#include "pbd/error.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
#include "i18n.h"
|
|
|
|
|
2009-05-12 13:03:42 -04:00
|
|
|
using namespace std;
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
namespace PBD {
|
|
|
|
|
2009-10-15 14:56:11 -04:00
|
|
|
int Stateful::current_state_version = 0;
|
|
|
|
int Stateful::loading_state_version = 0;
|
|
|
|
|
2015-11-16 21:23:39 -05:00
|
|
|
static void regular_delete (void* p) { bool* bp = reinterpret_cast<bool*> (p); delete bp; std::cerr << "Deleted RSSI bool\n"; }
|
2015-11-12 10:24:41 -05:00
|
|
|
|
2015-11-16 21:23:39 -05:00
|
|
|
Glib::Threads::Private<bool> Stateful::regenerate_xml_or_string_ids (regular_delete);
|
2015-11-12 10:24:41 -05:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
Stateful::Stateful ()
|
2015-11-06 07:16:27 -05:00
|
|
|
: _extra_xml (0)
|
|
|
|
, _instant_xml (0)
|
|
|
|
, _properties (new OwnedPropertyList)
|
2011-12-17 11:37:18 -05:00
|
|
|
, _stateful_frozen (0)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Stateful::~Stateful ()
|
|
|
|
{
|
2010-12-20 19:41:13 -05:00
|
|
|
delete _properties;
|
2010-03-01 19:00:00 -05:00
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
// Do not delete _extra_xml. The use of add_child_nocopy()
|
2008-06-02 17:41:35 -04:00
|
|
|
// means it needs to live on indefinately.
|
|
|
|
|
2008-12-18 14:31:00 -05:00
|
|
|
delete _instant_xml;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Stateful::add_extra_xml (XMLNode& node)
|
|
|
|
{
|
|
|
|
if (_extra_xml == 0) {
|
2009-02-14 22:45:00 -05:00
|
|
|
_extra_xml = new XMLNode ("Extra");
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2015-11-07 00:26:27 -05:00
|
|
|
_extra_xml->remove_nodes_and_delete (node.name());
|
2008-06-02 17:41:35 -04:00
|
|
|
_extra_xml->add_child_nocopy (node);
|
|
|
|
}
|
|
|
|
|
|
|
|
XMLNode *
|
2011-06-11 11:35:34 -04:00
|
|
|
Stateful::extra_xml (const string& str, bool add_if_missing)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2011-06-11 11:35:34 -04:00
|
|
|
XMLNode* node = 0;
|
|
|
|
|
|
|
|
if (_extra_xml) {
|
|
|
|
node = _extra_xml->child (str.c_str());
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2011-06-11 11:35:34 -04:00
|
|
|
if (!node && add_if_missing) {
|
|
|
|
node = new XMLNode (str);
|
|
|
|
add_extra_xml (*node);
|
2015-10-04 14:51:05 -04:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2011-06-11 11:35:34 -04:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Stateful::save_extra_xml (const XMLNode& node)
|
|
|
|
{
|
2015-10-04 14:51:05 -04:00
|
|
|
/* Looks for the child node called "Extra" and makes _extra_xml
|
2011-06-11 11:35:34 -04:00
|
|
|
point to a copy of it. Will delete any existing node pointed
|
|
|
|
to by _extra_xml if a new Extra node is found, but not
|
|
|
|
otherwise.
|
|
|
|
*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-06-11 11:35:34 -04:00
|
|
|
const XMLNode* xtra = node.child ("Extra");
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2011-06-11 11:35:34 -04:00
|
|
|
if (xtra) {
|
|
|
|
delete _extra_xml;
|
|
|
|
_extra_xml = new XMLNode (*xtra);
|
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-06-23 01:07:27 -04:00
|
|
|
Stateful::add_instant_xml (XMLNode& node, const std::string& directory_path)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2012-06-23 01:07:27 -04:00
|
|
|
if (!Glib::file_test (directory_path, Glib::FILE_TEST_IS_DIR)) {
|
|
|
|
if (g_mkdir_with_parents (directory_path.c_str(), 0755) != 0) {
|
|
|
|
error << string_compose(_("Error: could not create directory %1"), directory_path) << endmsg;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
if (_instant_xml == 0) {
|
|
|
|
_instant_xml = new XMLNode ("instant");
|
|
|
|
}
|
|
|
|
|
|
|
|
_instant_xml->remove_nodes_and_delete (node.name());
|
|
|
|
_instant_xml->add_child_copy (node);
|
|
|
|
|
2012-06-23 01:07:27 -04:00
|
|
|
std::string instant_xml_path = Glib::build_filename (directory_path, "instant.xml");
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
XMLTree tree;
|
2012-06-23 01:07:27 -04:00
|
|
|
tree.set_filename(instant_xml_path);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
/* Important: the destructor for an XMLTree deletes
|
|
|
|
all of its nodes, starting at _root. We therefore
|
2015-10-04 14:51:05 -04:00
|
|
|
cannot simply hand it our persistent _instant_xml
|
2008-06-02 17:41:35 -04:00
|
|
|
node as its _root, because we will lose it whenever
|
|
|
|
the Tree goes out of scope.
|
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
So instead, copy the _instant_xml node (which does
|
2008-06-02 17:41:35 -04:00
|
|
|
a deep copy), and hand that to the tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
XMLNode* copy = new XMLNode (*_instant_xml);
|
|
|
|
tree.set_root (copy);
|
|
|
|
|
|
|
|
if (!tree.write()) {
|
2012-06-23 01:07:27 -04:00
|
|
|
error << string_compose(_("Error: could not write %1"), instant_xml_path) << endmsg;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
XMLNode *
|
2012-06-23 01:07:27 -04:00
|
|
|
Stateful::instant_xml (const string& str, const std::string& directory_path)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
if (_instant_xml == 0) {
|
|
|
|
|
2012-06-23 01:07:27 -04:00
|
|
|
std::string instant_xml_path = Glib::build_filename (directory_path, "instant.xml");
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2012-06-23 01:07:27 -04:00
|
|
|
if (Glib::file_test (instant_xml_path, Glib::FILE_TEST_EXISTS)) {
|
2008-06-02 17:41:35 -04:00
|
|
|
XMLTree tree;
|
2012-06-23 01:07:27 -04:00
|
|
|
if (tree.read(instant_xml_path)) {
|
2008-06-02 17:41:35 -04:00
|
|
|
_instant_xml = new XMLNode(*(tree.root()));
|
|
|
|
} else {
|
2012-06-23 01:07:27 -04:00
|
|
|
warning << string_compose(_("Could not understand XML file %1"), instant_xml_path) << endmsg;
|
2008-06-02 17:41:35 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const XMLNodeList& nlist = _instant_xml->children();
|
|
|
|
XMLNodeConstIterator i;
|
|
|
|
|
|
|
|
for (i = nlist.begin(); i != nlist.end(); ++i) {
|
|
|
|
if ((*i)->name() == str) {
|
|
|
|
return (*i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-08-25 13:32:08 -04:00
|
|
|
/** Forget about any changes to this object's properties */
|
2010-02-09 09:44:01 -05:00
|
|
|
void
|
2010-08-25 13:32:08 -04:00
|
|
|
Stateful::clear_changes ()
|
2010-02-09 09:44:01 -05:00
|
|
|
{
|
2010-03-01 19:00:00 -05:00
|
|
|
for (OwnedPropertyList::iterator i = _properties->begin(); i != _properties->end(); ++i) {
|
2010-08-25 13:32:08 -04:00
|
|
|
i->second->clear_changes ();
|
2010-02-09 09:44:01 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-25 13:31:57 -04:00
|
|
|
PropertyList *
|
|
|
|
Stateful::get_changes_as_properties (Command* cmd) const
|
2010-02-09 09:44:01 -05:00
|
|
|
{
|
2010-08-25 13:31:57 -04:00
|
|
|
PropertyList* pl = new PropertyList;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2010-03-01 19:00:00 -05:00
|
|
|
for (OwnedPropertyList::const_iterator i = _properties->begin(); i != _properties->end(); ++i) {
|
2010-08-25 13:31:57 -04:00
|
|
|
i->second->get_changes_as_properties (*pl, cmd);
|
2010-02-09 09:44:01 -05:00
|
|
|
}
|
2010-08-25 13:31:57 -04:00
|
|
|
|
|
|
|
return pl;
|
2010-02-09 09:44:01 -05:00
|
|
|
}
|
2010-02-18 08:59:49 -05:00
|
|
|
|
2010-08-25 13:31:33 -04:00
|
|
|
/** Set our property values from an XML node.
|
2011-05-23 18:12:45 -04:00
|
|
|
* Derived types can call this from set_state() (or elsewhere)
|
2010-08-25 13:31:33 -04:00
|
|
|
* to get basic property setting done.
|
|
|
|
* @return IDs of properties that were changed.
|
2010-02-09 20:38:20 -05:00
|
|
|
*/
|
2010-02-18 08:59:49 -05:00
|
|
|
PropertyChange
|
2010-08-25 13:31:33 -04:00
|
|
|
Stateful::set_values (XMLNode const & node)
|
2010-02-09 20:38:20 -05:00
|
|
|
{
|
2010-02-19 13:09:08 -05:00
|
|
|
PropertyChange c;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2010-03-01 19:00:00 -05:00
|
|
|
for (OwnedPropertyList::iterator i = _properties->begin(); i != _properties->end(); ++i) {
|
2010-08-25 13:31:33 -04:00
|
|
|
if (i->second->set_value (node)) {
|
2010-02-19 13:09:08 -05:00
|
|
|
c.add (i->first);
|
|
|
|
}
|
2010-02-18 08:59:49 -05:00
|
|
|
}
|
|
|
|
|
2010-12-20 11:10:58 -05:00
|
|
|
post_set (c);
|
2010-02-18 08:59:49 -05:00
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyChange
|
2010-08-25 13:31:33 -04:00
|
|
|
Stateful::apply_changes (const PropertyList& property_list)
|
2010-02-18 08:59:49 -05:00
|
|
|
{
|
2010-02-19 13:09:08 -05:00
|
|
|
PropertyChange c;
|
2010-02-18 08:59:49 -05:00
|
|
|
PropertyList::const_iterator p;
|
|
|
|
|
2010-12-20 19:41:13 -05:00
|
|
|
DEBUG_TRACE (DEBUG::Stateful, string_compose ("Stateful %1 setting properties from list of %2\n", this, property_list.size()));
|
2010-03-01 19:00:00 -05:00
|
|
|
|
2010-12-20 19:41:13 -05:00
|
|
|
for (PropertyList::const_iterator pp = property_list.begin(); pp != property_list.end(); ++pp) {
|
|
|
|
DEBUG_TRACE (DEBUG::Stateful, string_compose ("in plist: %1\n", pp->second->property_name()));
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2010-12-20 19:41:13 -05:00
|
|
|
for (PropertyList::const_iterator i = property_list.begin(); i != property_list.end(); ++i) {
|
|
|
|
if ((p = _properties->find (i->first)) != _properties->end()) {
|
2010-08-25 13:31:57 -04:00
|
|
|
|
2010-12-20 19:41:13 -05:00
|
|
|
DEBUG_TRACE (
|
2010-08-25 13:31:57 -04:00
|
|
|
DEBUG::Stateful,
|
|
|
|
string_compose ("actually setting property %1 using %2\n", p->second->property_name(), i->second->property_name())
|
|
|
|
);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2010-08-25 13:31:57 -04:00
|
|
|
if (apply_changes (*i->second)) {
|
2010-02-19 13:09:08 -05:00
|
|
|
c.add (i->first);
|
|
|
|
}
|
2010-03-01 19:00:00 -05:00
|
|
|
} else {
|
2010-12-20 19:41:13 -05:00
|
|
|
DEBUG_TRACE (DEBUG::Stateful, string_compose ("passed in property %1 not found in own property list\n",
|
|
|
|
i->second->property_name()));
|
|
|
|
}
|
2010-02-09 20:38:20 -05:00
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2010-12-20 11:10:58 -05:00
|
|
|
post_set (c);
|
2010-02-09 20:38:20 -05:00
|
|
|
|
2010-04-01 20:21:08 -04:00
|
|
|
send_change (c);
|
|
|
|
|
2010-02-09 20:38:20 -05:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2010-02-18 08:59:49 -05:00
|
|
|
/** Add property states to an XML node.
|
2010-03-31 21:07:24 -04:00
|
|
|
* @param owner_state Node.
|
2010-02-09 20:38:20 -05:00
|
|
|
*/
|
|
|
|
void
|
2010-03-01 19:00:00 -05:00
|
|
|
Stateful::add_properties (XMLNode& owner_state)
|
2010-02-09 20:38:20 -05:00
|
|
|
{
|
2010-03-01 19:00:00 -05:00
|
|
|
for (OwnedPropertyList::iterator i = _properties->begin(); i != _properties->end(); ++i) {
|
2010-08-25 13:31:33 -04:00
|
|
|
i->second->get_value (owner_state);
|
2010-02-09 20:38:20 -05:00
|
|
|
}
|
|
|
|
}
|
2010-02-09 09:44:01 -05:00
|
|
|
|
2010-03-01 19:00:00 -05:00
|
|
|
void
|
|
|
|
Stateful::add_property (PropertyBase& s)
|
|
|
|
{
|
2010-12-20 19:41:13 -05:00
|
|
|
_properties->add (s);
|
2010-03-01 19:00:00 -05:00
|
|
|
}
|
|
|
|
|
2010-03-02 13:05:26 -05:00
|
|
|
void
|
|
|
|
Stateful::send_change (const PropertyChange& what_changed)
|
|
|
|
{
|
|
|
|
if (what_changed.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (_lock);
|
2011-12-17 11:37:18 -05:00
|
|
|
if (property_changes_suspended ()) {
|
2010-03-02 13:05:26 -05:00
|
|
|
_pending_changed.add (what_changed);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyChanged (what_changed);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Stateful::suspend_property_changes ()
|
|
|
|
{
|
2011-12-17 11:37:18 -05:00
|
|
|
g_atomic_int_add (&_stateful_frozen, 1);
|
2010-03-02 13:05:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Stateful::resume_property_changes ()
|
|
|
|
{
|
|
|
|
PropertyChange what_changed;
|
|
|
|
|
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (_lock);
|
2010-03-02 13:05:26 -05:00
|
|
|
|
2011-12-17 11:37:18 -05:00
|
|
|
if (property_changes_suspended() && g_atomic_int_dec_and_test (&_stateful_frozen) == FALSE) {
|
2010-03-02 13:05:26 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_pending_changed.empty()) {
|
|
|
|
what_changed = _pending_changed;
|
|
|
|
_pending_changed.clear ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-20 19:41:13 -05:00
|
|
|
mid_thaw (what_changed);
|
2010-03-02 13:05:26 -05:00
|
|
|
|
2010-12-20 19:41:13 -05:00
|
|
|
send_change (what_changed);
|
2010-03-02 13:05:26 -05:00
|
|
|
}
|
|
|
|
|
2010-03-04 08:15:04 -05:00
|
|
|
bool
|
2015-10-04 14:51:05 -04:00
|
|
|
Stateful::changed() const
|
2010-03-04 08:15:04 -05:00
|
|
|
{
|
|
|
|
for (OwnedPropertyList::const_iterator i = _properties->begin(); i != _properties->end(); ++i) {
|
2010-12-20 19:41:13 -05:00
|
|
|
if (i->second->changed()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2010-03-04 08:15:04 -05:00
|
|
|
|
2010-12-20 19:41:13 -05:00
|
|
|
return false;
|
2010-03-04 08:15:04 -05:00
|
|
|
}
|
2010-03-02 13:05:26 -05:00
|
|
|
|
2010-03-31 18:45:27 -04:00
|
|
|
bool
|
2010-08-25 13:31:57 -04:00
|
|
|
Stateful::apply_changes (const PropertyBase& prop)
|
2010-03-31 18:45:27 -04:00
|
|
|
{
|
|
|
|
OwnedPropertyList::iterator i = _properties->find (prop.property_id());
|
|
|
|
if (i == _properties->end()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-25 13:31:57 -04:00
|
|
|
i->second->apply_changes (&prop);
|
2010-03-31 18:45:27 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-25 13:31:41 -04:00
|
|
|
PropertyList*
|
|
|
|
Stateful::property_factory (const XMLNode& history_node) const
|
|
|
|
{
|
2010-12-20 19:41:13 -05:00
|
|
|
PropertyList* prop_list = new PropertyList;
|
2010-08-25 13:31:41 -04:00
|
|
|
|
2010-12-20 19:41:13 -05:00
|
|
|
for (OwnedPropertyList::const_iterator i = _properties->begin(); i != _properties->end(); ++i) {
|
|
|
|
PropertyBase* prop = i->second->clone_from_xml (history_node);
|
2010-08-25 13:31:41 -04:00
|
|
|
|
2010-12-20 19:41:13 -05:00
|
|
|
if (prop) {
|
|
|
|
prop_list->add (prop);
|
|
|
|
}
|
|
|
|
}
|
2010-08-25 13:31:41 -04:00
|
|
|
|
2010-12-20 19:41:13 -05:00
|
|
|
return prop_list;
|
2010-08-25 13:31:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-08-25 21:44:11 -04:00
|
|
|
Stateful::rdiff (vector<Command*>& cmds) const
|
2010-08-25 13:31:41 -04:00
|
|
|
{
|
|
|
|
for (OwnedPropertyList::const_iterator i = _properties->begin(); i != _properties->end(); ++i) {
|
|
|
|
i->second->rdiff (cmds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-08-25 13:32:08 -04:00
|
|
|
Stateful::clear_owned_changes ()
|
2010-08-25 13:31:41 -04:00
|
|
|
{
|
|
|
|
for (OwnedPropertyList::iterator i = _properties->begin(); i != _properties->end(); ++i) {
|
2010-08-25 13:32:08 -04:00
|
|
|
i->second->clear_owned_changes ();
|
2010-08-25 13:31:41 -04:00
|
|
|
}
|
|
|
|
}
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2011-10-18 09:18:47 -04:00
|
|
|
bool
|
2015-10-04 14:51:05 -04:00
|
|
|
Stateful::set_id (const XMLNode& node)
|
2011-10-18 09:18:47 -04:00
|
|
|
{
|
|
|
|
const XMLProperty* prop;
|
2015-11-16 21:23:39 -05:00
|
|
|
bool* regen = regenerate_xml_or_string_ids.get();
|
2011-10-18 09:18:47 -04:00
|
|
|
|
2015-11-16 21:23:39 -05:00
|
|
|
if (regen && *regen) {
|
2015-11-12 10:24:41 -05:00
|
|
|
reset_id ();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-10-18 09:18:47 -04:00
|
|
|
if ((prop = node.property ("id")) != 0) {
|
|
|
|
_id = prop->value ();
|
|
|
|
return true;
|
2015-10-04 14:51:05 -04:00
|
|
|
}
|
2011-10-18 09:18:47 -04:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Stateful::reset_id ()
|
|
|
|
{
|
|
|
|
_id = ID ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Stateful::set_id (const string& str)
|
|
|
|
{
|
2015-11-16 21:23:39 -05:00
|
|
|
bool* regen = regenerate_xml_or_string_ids.get();
|
|
|
|
|
|
|
|
if (regen && *regen) {
|
2015-11-12 10:24:41 -05:00
|
|
|
reset_id ();
|
|
|
|
} else {
|
|
|
|
_id = str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Stateful::set_regenerate_xml_and_string_ids_in_this_thread (bool yn)
|
|
|
|
{
|
|
|
|
regenerate_xml_or_string_ids.set (&yn);
|
2011-10-18 09:18:47 -04:00
|
|
|
}
|
2010-08-25 13:31:41 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
} // namespace PBD
|