aboutsummaryrefslogtreecommitdiff
path: root/libxsd/xsd/cxx/tree/elements.hxx
diff options
context:
space:
mode:
Diffstat (limited to 'libxsd/xsd/cxx/tree/elements.hxx')
-rw-r--r--libxsd/xsd/cxx/tree/elements.hxx46
1 files changed, 20 insertions, 26 deletions
diff --git a/libxsd/xsd/cxx/tree/elements.hxx b/libxsd/xsd/cxx/tree/elements.hxx
index 3334d5f..c48839a 100644
--- a/libxsd/xsd/cxx/tree/elements.hxx
+++ b/libxsd/xsd/cxx/tree/elements.hxx
@@ -425,13 +425,20 @@ namespace xsd
{
if (map_.get () != 0)
{
- // Propagate our IDs to the new container.
+ // Propagate our IDs to the new root.
//
- for (map::iterator i (map_->begin ()), e (map_->end ());
- i != e; ++i)
+ container* r (c->_root ());
+
+ if (r == 0)
+ r = c;
+
+ if (r->map_.get () != 0)
{
- c->_register_id (*i->first, i->second);
+ r->map_->insert (map_->begin (), map_->end ());
+ map_.reset ();
}
+ else
+ r->map_ = map_;
}
container_ = c;
@@ -585,16 +592,13 @@ namespace xsd
void
_register_id (const identity& id, type* t)
{
+ // We should be the root.
+ //
+ assert (container_ == 0);
+
if (map_.get () == 0)
map_.reset (new map);
- // First register on our container. If there are any duplications,
- // they will be detected by this call and we don't need to clean
- // the map.
- //
- if (container_ != 0)
- container_->_register_id (id, t);
-
if (!map_->insert (
std::pair<const identity*, type*> (&id, t)).second)
{
@@ -616,22 +620,12 @@ namespace xsd
void
_unregister_id (const identity& id)
{
- if (map_.get ())
- {
- map::iterator it (map_->find (&id));
-
- if (it != map_->end ())
- {
- map_->erase (it);
-
- if (container_ != 0)
- container_->_unregister_id (id);
-
- return;
- }
- }
+ // We should be the root.
+ //
+ assert (container_ == 0);
- throw not_registered ();
+ if (map_.get () == 0 || map_->erase (&id) == 0)
+ throw not_registered ();
}
type*