Unified configmgr::Node::getMember{s,Map} again.

(With the insight that Data::components is RootNode::members.)
This commit is contained in:
Stephan Bergmann 2011-12-13 22:16:31 +01:00
parent 39cbce553d
commit db4bc6812d
18 changed files with 97 additions and 112 deletions

View File

@ -1607,30 +1607,27 @@ void Access::commitChildChanges(
// children); clarify what exactly should happen here for // children); clarify what exactly should happen here for
// directly inserted children // directly inserted children
} }
NodeMap * members = getNode()->getMemberMap(); NodeMap & members = getNode()->getMembers();
if (members != 0) { NodeMap::iterator j(members.find(i->first));
NodeMap::iterator j(members->find(i->first));
if (child.is()) { if (child.is()) {
// Inserted: // Inserted:
if (j != members->end()) { if (j != members.end()) {
childValid = childValid && childValid = childValid &&
j->second->getFinalized() == Data::NO_LAYER; j->second->getFinalized() == Data::NO_LAYER;
if (childValid) { if (childValid) {
child->getNode()->setMandatory( child->getNode()->setMandatory(j->second->getMandatory());
j->second->getMandatory());
} }
} }
if (childValid) { if (childValid) {
(*members)[i->first] = child->getNode(); members[i->first] = child->getNode();
} }
} else { } else {
// Removed: // Removed:
childValid = childValid && j != members->end() && childValid = childValid && j != members.end() &&
j->second->getFinalized() == Data::NO_LAYER && j->second->getFinalized() == Data::NO_LAYER &&
j->second->getMandatory() == Data::NO_LAYER; j->second->getMandatory() == Data::NO_LAYER;
if (childValid) { if (childValid) {
members->erase(j); members.erase(j);
}
} }
} }
if (childValid && i->second.directlyModified) { if (childValid && i->second.directlyModified) {

View File

@ -385,7 +385,7 @@ void Components::removeExtensionXcuFile(
i != item->additions.rend(); ++i) i != item->additions.rend(); ++i)
{ {
rtl::Reference< Node > parent; rtl::Reference< Node > parent;
NodeMap const * map = &data_.components; NodeMap const * map = &data_.getComponents();
rtl::Reference< Node > node; rtl::Reference< Node > node;
for (Path::const_iterator j(i->begin()); j != i->end(); ++j) { for (Path::const_iterator j(i->begin()); j != i->end(); ++j) {
parent = node; parent = node;
@ -402,9 +402,7 @@ void Components::removeExtensionXcuFile(
node->kind() == Node::KIND_GROUP || node->kind() == Node::KIND_GROUP ||
node->kind() == Node::KIND_SET); node->kind() == Node::KIND_SET);
if (canRemoveFromLayer(item->layer, node)) { if (canRemoveFromLayer(item->layer, node)) {
NodeMap * members = parent->getMemberMap(); parent->getMembers().erase(i->back());
assert(members != 0);
members->erase(i->back());
data_.modifications.remove(*i); data_.modifications.remove(*i);
modifications->add(*i); modifications->add(*i);
} }

View File

@ -208,7 +208,7 @@ rtl::Reference< Node > Data::findNode(
? rtl::Reference< Node >() : i->second; ? rtl::Reference< Node >() : i->second;
} }
Data::Data(): root_(new RootNode(components)) {} Data::Data(): root_(new RootNode) {}
rtl::Reference< Node > Data::resolvePathRepresentation( rtl::Reference< Node > Data::resolvePathRepresentation(
rtl::OUString const & pathRepresentation, rtl::OUString const & pathRepresentation,
@ -244,6 +244,7 @@ rtl::Reference< Node > Data::resolvePathRepresentation(
pathRepresentation), pathRepresentation),
css::uno::Reference< css::uno::XInterface >()); css::uno::Reference< css::uno::XInterface >());
} }
NodeMap const & components = getComponents();
NodeMap::const_iterator i(components.find(seg)); NodeMap::const_iterator i(components.find(seg));
rtl::OUStringBuffer canonic; rtl::OUStringBuffer canonic;
rtl::Reference< Node > parent; rtl::Reference< Node > parent;
@ -340,6 +341,10 @@ rtl::Reference< Node > Data::getTemplate(
return findNode(layer, templates, fullName); return findNode(layer, templates, fullName);
} }
NodeMap & Data::getComponents() const {
return root_->getMembers();
}
Additions * Data::addExtensionXcuAdditions( Additions * Data::addExtensionXcuAdditions(
rtl::OUString const & url, int layer) rtl::OUString const & url, int layer)
{ {

View File

@ -60,8 +60,6 @@ struct Data: private boost::noncopyable {
NodeMap templates; NodeMap templates;
NodeMap components;
Modifications modifications; Modifications modifications;
static rtl::OUString createSegment( static rtl::OUString createSegment(
@ -91,6 +89,8 @@ struct Data: private boost::noncopyable {
rtl::Reference< Node > getTemplate( rtl::Reference< Node > getTemplate(
int layer, rtl::OUString const & fullName) const; int layer, rtl::OUString const & fullName) const;
NodeMap & getComponents() const;
Additions * addExtensionXcuAdditions( Additions * addExtensionXcuAdditions(
rtl::OUString const & url, int layer); rtl::OUString const & url, int layer);

View File

@ -48,8 +48,8 @@ rtl::Reference< Node > GroupNode::clone(bool keepTemplateName) const {
return new GroupNode(*this, keepTemplateName); return new GroupNode(*this, keepTemplateName);
} }
NodeMap * GroupNode::getMemberMap() { NodeMap & GroupNode::getMembers() {
return &members_; return members_;
} }
rtl::OUString GroupNode::getTemplateName() const { rtl::OUString GroupNode::getTemplateName() const {

View File

@ -45,7 +45,7 @@ public:
virtual rtl::Reference< Node > clone(bool keepTemplateName) const; virtual rtl::Reference< Node > clone(bool keepTemplateName) const;
virtual NodeMap * getMemberMap(); virtual NodeMap & getMembers();
virtual rtl::OUString getTemplateName() const; virtual rtl::OUString getTemplateName() const;

View File

@ -55,8 +55,8 @@ rtl::Reference< Node > LocalizedPropertyNode::clone(bool) const {
return new LocalizedPropertyNode(*this); return new LocalizedPropertyNode(*this);
} }
NodeMap * LocalizedPropertyNode::getMemberMap() { NodeMap & LocalizedPropertyNode::getMembers() {
return &members_; return members_;
} }
Type LocalizedPropertyNode::getStaticType() const { Type LocalizedPropertyNode::getStaticType() const {

View File

@ -50,7 +50,7 @@ public:
virtual rtl::Reference< Node > clone(bool keepTemplateName) const; virtual rtl::Reference< Node > clone(bool keepTemplateName) const;
virtual NodeMap * getMemberMap(); virtual NodeMap & getMembers();
Type getStaticType() const; Type getStaticType() const;

View File

@ -30,7 +30,11 @@
#include <cassert> #include <cassert>
#include "com/sun/star/uno/Reference.hxx"
#include "com/sun/star/uno/RuntimeException.hpp"
#include "com/sun/star/uno/XInterface.hpp"
#include "rtl/ref.hxx" #include "rtl/ref.hxx"
#include "rtl/ustring.h"
#include "rtl/ustring.hxx" #include "rtl/ustring.hxx"
#include "data.hxx" #include "data.hxx"
@ -39,15 +43,17 @@
namespace configmgr { namespace configmgr {
NodeMap const & Node::getMembers() const { namespace {
NodeMap * members = const_cast< Node * >(this)->getMemberMap();
assert(members != 0); namespace css = com::sun::star;
return *members;
} }
NodeMap * Node::getMemberMap() { NodeMap & Node::getMembers() {
assert(false); assert(false);
return 0; throw css::uno::RuntimeException(
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("this cannot happen")),
css::uno::Reference< css::uno::XInterface >());
} }
rtl::OUString Node::getTemplateName() const { rtl::OUString Node::getTemplateName() const {

View File

@ -50,8 +50,7 @@ public:
virtual rtl::Reference< Node > clone(bool keepTemplateName) const = 0; virtual rtl::Reference< Node > clone(bool keepTemplateName) const = 0;
virtual NodeMap const & getMembers() const; virtual NodeMap & getMembers();
virtual NodeMap * getMemberMap();
virtual rtl::OUString getTemplateName() const; virtual rtl::OUString getTemplateName() const;
virtual void setMandatory(int layer); virtual void setMandatory(int layer);

View File

@ -38,9 +38,7 @@
namespace configmgr { namespace configmgr {
RootNode::RootNode(NodeMap const & members): RootNode::RootNode(): Node(Data::NO_LAYER) {}
Node(Data::NO_LAYER), members_(members)
{}
RootNode::~RootNode() {} RootNode::~RootNode() {}
@ -53,14 +51,10 @@ rtl::Reference< Node > RootNode::clone(bool) const {
return rtl::Reference< Node >(); return rtl::Reference< Node >();
} }
NodeMap const & RootNode::getMembers() const { NodeMap & RootNode::getMembers() {
return members_; return members_;
} }
NodeMap * RootNode::getMemberMap() {
return 0;
}
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -41,21 +41,18 @@ namespace configmgr {
class RootNode: public Node { class RootNode: public Node {
public: public:
RootNode(NodeMap const & members); RootNode();
private: private:
RootNode(RootNode const & other);
virtual ~RootNode(); virtual ~RootNode();
virtual Kind kind() const; virtual Kind kind() const;
virtual rtl::Reference< Node > clone(bool keepTemplateName) const; virtual rtl::Reference< Node > clone(bool keepTemplateName) const;
virtual NodeMap const & getMembers() const; virtual NodeMap & getMembers();
virtual NodeMap * getMemberMap();
NodeMap const & members_; NodeMap members_;
}; };
} }

View File

@ -73,8 +73,8 @@ rtl::Reference< Node > SetNode::clone(bool keepTemplateName) const {
return new SetNode(*this, keepTemplateName); return new SetNode(*this, keepTemplateName);
} }
NodeMap * SetNode::getMemberMap() { NodeMap & SetNode::getMembers() {
return &members_; return members_;
} }
rtl::OUString SetNode::getTemplateName() const { rtl::OUString SetNode::getTemplateName() const {

View File

@ -49,7 +49,7 @@ public:
virtual rtl::Reference< Node > clone(bool keepTemplateName) const; virtual rtl::Reference< Node > clone(bool keepTemplateName) const;
virtual NodeMap * getMemberMap(); virtual NodeMap & getMembers();
virtual rtl::OUString getTemplateName() const; virtual rtl::OUString getTemplateName() const;

View File

@ -413,11 +413,10 @@ bool ValueParser::endElement() {
break; break;
case Node::KIND_LOCALIZED_PROPERTY: case Node::KIND_LOCALIZED_PROPERTY:
{ {
NodeMap * members = node_->getMemberMap(); NodeMap & members = node_->getMembers();
assert(members != 0); NodeMap::iterator i(members.find(localizedName_));
NodeMap::iterator i(members->find(localizedName_)); if (i == members.end()) {
if (i == members->end()) { members.insert(
members->insert(
NodeMap::value_type( NodeMap::value_type(
localizedName_, localizedName_,
new LocalizedValueNode(layer_, value))); new LocalizedValueNode(layer_, value)));

View File

@ -586,7 +586,8 @@ void writeModFile(
{ {
writeModifications( writeModifications(
components, tmp.handle, rtl::OUString(), rtl::Reference< Node >(), components, tmp.handle, rtl::OUString(), rtl::Reference< Node >(),
j->first, Data::findNode(Data::NO_LAYER, data.components, j->first), j->first,
Data::findNode(Data::NO_LAYER, data.getComponents(), j->first),
j->second); j->second);
} }
writeData(tmp.handle, RTL_CONSTASCII_STRINGPARAM("</oor:items>")); writeData(tmp.handle, RTL_CONSTASCII_STRINGPARAM("</oor:items>"));

View File

@ -82,15 +82,14 @@ void merge(
for (NodeMap::const_iterator i2(update->getMembers().begin()); for (NodeMap::const_iterator i2(update->getMembers().begin());
i2 != update->getMembers().end(); ++i2) i2 != update->getMembers().end(); ++i2)
{ {
NodeMap * members = original->getMemberMap(); NodeMap & members = original->getMembers();
assert(members != 0); NodeMap::iterator i1(members.find(i2->first));
NodeMap::iterator i1(members->find(i2->first)); if (i1 == members.end()) {
if (i1 == members->end()) {
if (i2->second->kind() == Node::KIND_PROPERTY && if (i2->second->kind() == Node::KIND_PROPERTY &&
dynamic_cast< GroupNode * >( dynamic_cast< GroupNode * >(
original.get())->isExtensible()) original.get())->isExtensible())
{ {
members->insert(*i2); members.insert(*i2);
} }
} else if (i2->second->kind() == i1->second->kind()) { } else if (i2->second->kind() == i1->second->kind()) {
merge(i1->second, i2->second); merge(i1->second, i2->second);
@ -101,14 +100,13 @@ void merge(
for (NodeMap::const_iterator i2(update->getMembers().begin()); for (NodeMap::const_iterator i2(update->getMembers().begin());
i2 != update->getMembers().end(); ++i2) i2 != update->getMembers().end(); ++i2)
{ {
NodeMap * members = original->getMemberMap(); NodeMap & members = original->getMembers();
assert(members != 0); NodeMap::iterator i1(members.find(i2->first));
NodeMap::iterator i1(members->find(i2->first)); if (i1 == members.end()) {
if (i1 == members->end()) {
if (dynamic_cast< SetNode * >(original.get())-> if (dynamic_cast< SetNode * >(original.get())->
isValidTemplate(i2->second->getTemplateName())) isValidTemplate(i2->second->getTemplateName()))
{ {
members->insert(*i2); members.insert(*i2);
} }
} else if (i2->second->kind() == i1->second->kind() && } else if (i2->second->kind() == i1->second->kind() &&
(i2->second->getTemplateName() == (i2->second->getTemplateName() ==
@ -298,9 +296,10 @@ void XcsParser::endElement(xmlreader::XmlReader const & reader) {
break; break;
case STATE_COMPONENT: case STATE_COMPONENT:
{ {
NodeMap::iterator i(data_.components.find(top.name)); NodeMap & components = data_.getComponents();
if (i == data_.components.end()) { NodeMap::iterator i(components.find(top.name));
data_.components.insert( if (i == components.end()) {
components.insert(
NodeMap::value_type(top.name, top.node)); NodeMap::value_type(top.name, top.node));
} else { } else {
merge(i->second, top.node); merge(i->second, top.node);
@ -316,10 +315,8 @@ void XcsParser::endElement(xmlreader::XmlReader const & reader) {
css::uno::Reference< css::uno::XInterface >()); css::uno::Reference< css::uno::XInterface >());
} }
} else { } else {
NodeMap * members = elements_.top().node->getMemberMap(); if (!elements_.top().node->getMembers().insert(
assert(members != 0); NodeMap::value_type(top.name, top.node)).second)
if (!members->insert(NodeMap::value_type(top.name, top.node)).
second)
{ {
throw css::uno::RuntimeException( throw css::uno::RuntimeException(
(rtl::OUString( (rtl::OUString(

View File

@ -242,9 +242,7 @@ void XcuParser::endElement(xmlreader::XmlReader const &) {
state_.pop(); state_.pop();
if (insert.is()) { if (insert.is()) {
assert(!state_.empty() && state_.top().node.is()); assert(!state_.empty() && state_.top().node.is());
NodeMap * members = state_.top().node->getMemberMap(); state_.top().node->getMembers()[name] = insert;
assert(members != 0);
(*members)[name] = insert;
} }
if (pop && !path_.empty()) { if (pop && !path_.empty()) {
path_.pop_back(); path_.pop_back();
@ -358,7 +356,7 @@ void XcuParser::handleComponentData(xmlreader::XmlReader & reader) {
} }
rtl::Reference< Node > node( rtl::Reference< Node > node(
Data::findNode( Data::findNode(
valueParser_.getLayer(), data_.components, componentName_)); valueParser_.getLayer(), data_.getComponents(), componentName_));
if (!node.is()) { if (!node.is()) {
SAL_WARN( SAL_WARN(
"configmgr", "configmgr",
@ -595,11 +593,9 @@ void XcuParser::handleLocpropValue(
return; return;
} }
} }
NodeMap * members = locprop->getMemberMap(); NodeMap & members = locprop->getMembers();
assert(members != 0); NodeMap::iterator i(members.find(name));
NodeMap::iterator i(members->find(name)); if (i != members.end() && i->second->getLayer() > valueParser_.getLayer()) {
if (i != members->end() && i->second->getLayer() > valueParser_.getLayer())
{
state_.push(State(true)); // ignored state_.push(State(true)); // ignored
return; return;
} }
@ -616,8 +612,8 @@ void XcuParser::handleLocpropValue(
{ {
bool pop = false; bool pop = false;
if (nil) { if (nil) {
if (i == members->end()) { if (i == members.end()) {
(*members)[name] = new LocalizedValueNode( members[name] = new LocalizedValueNode(
valueParser_.getLayer(), css::uno::Any()); valueParser_.getLayer(), css::uno::Any());
} else { } else {
dynamic_cast< LocalizedValueNode * >( dynamic_cast< LocalizedValueNode * >(
@ -641,8 +637,8 @@ void XcuParser::handleLocpropValue(
case OPERATION_REMOVE: case OPERATION_REMOVE:
//TODO: only allow if parent.op == OPERATION_FUSE //TODO: only allow if parent.op == OPERATION_FUSE
//TODO: disallow removing when e.g. lang=""? //TODO: disallow removing when e.g. lang=""?
if (i != members->end()) { if (i != members.end()) {
members->erase(i); members.erase(i);
} }
state_.push(State(true)); state_.push(State(true));
recordModification(false); recordModification(false);
@ -708,10 +704,9 @@ void XcuParser::handleGroupProp(
return; return;
} }
} }
NodeMap * members = group->getMemberMap(); NodeMap & members = group->getMembers();
assert(members != 0); NodeMap::iterator i(members.find(name));
NodeMap::iterator i(members->find(name)); if (i == members.end()) {
if (i == members->end()) {
handleUnknownGroupProp(reader, group, name, type, op, finalized); handleUnknownGroupProp(reader, group, name, type, op, finalized);
} else { } else {
switch (i->second->kind()) { switch (i->second->kind()) {
@ -822,9 +817,7 @@ void XcuParser::handlePlainGroupProp(
reader.getUrl()), reader.getUrl()),
css::uno::Reference< css::uno::XInterface >()); css::uno::Reference< css::uno::XInterface >());
} }
NodeMap * members = group->getMemberMap(); group->getMembers().erase(propertyIndex);
assert(members != 0);
members->erase(propertyIndex);
state_.push(State(true)); // ignore children state_.push(State(true)); // ignore children
recordModification(false); recordModification(false);
break; break;
@ -1045,10 +1038,9 @@ void XcuParser::handleSetNode(xmlreader::XmlReader & reader, SetNode * set) {
} }
int finalizedLayer = finalized ? valueParser_.getLayer() : Data::NO_LAYER; int finalizedLayer = finalized ? valueParser_.getLayer() : Data::NO_LAYER;
int mandatoryLayer = mandatory ? valueParser_.getLayer() : Data::NO_LAYER; int mandatoryLayer = mandatory ? valueParser_.getLayer() : Data::NO_LAYER;
NodeMap * members = set->getMemberMap(); NodeMap & members = set->getMembers();
assert(members != 0); NodeMap::iterator i(members.find(name));
NodeMap::iterator i(members->find(name)); if (i != members.end()) {
if (i != members->end()) {
finalizedLayer = std::min(finalizedLayer, i->second->getFinalized()); finalizedLayer = std::min(finalizedLayer, i->second->getFinalized());
i->second->setFinalized(finalizedLayer); i->second->setFinalized(finalizedLayer);
mandatoryLayer = std::min(mandatoryLayer, i->second->getMandatory()); mandatoryLayer = std::min(mandatoryLayer, i->second->getMandatory());
@ -1060,7 +1052,7 @@ void XcuParser::handleSetNode(xmlreader::XmlReader & reader, SetNode * set) {
} }
switch (op) { switch (op) {
case OPERATION_MODIFY: case OPERATION_MODIFY:
if (i == members->end()) { if (i == members.end()) {
SAL_WARN( SAL_WARN(
"configmgr", "configmgr",
"ignoring modify of unknown set member node \"" << name "ignoring modify of unknown set member node \"" << name
@ -1083,11 +1075,11 @@ void XcuParser::handleSetNode(xmlreader::XmlReader & reader, SetNode * set) {
member->setFinalized(finalizedLayer); member->setFinalized(finalizedLayer);
member->setMandatory(mandatoryLayer); member->setMandatory(mandatoryLayer);
state_.push(State(member, name, false)); state_.push(State(member, name, false));
recordModification(i == members->end()); recordModification(i == members.end());
} }
break; break;
case OPERATION_FUSE: case OPERATION_FUSE:
if (i == members->end()) { if (i == members.end()) {
if (state_.top().locked || finalizedLayer < valueParser_.getLayer()) if (state_.top().locked || finalizedLayer < valueParser_.getLayer())
{ {
state_.push(State(true)); // ignored state_.push(State(true)); // ignored
@ -1114,13 +1106,13 @@ void XcuParser::handleSetNode(xmlreader::XmlReader & reader, SetNode * set) {
// forget about user-layer removals that no longer remove anything // forget about user-layer removals that no longer remove anything
// (so that paired additions/removals in the user layer do not grow // (so that paired additions/removals in the user layer do not grow
// registrymodifications.xcu unbounded): // registrymodifications.xcu unbounded):
bool known = i != members->end(); bool known = i != members.end();
if (known && !state_.top().locked && if (known && !state_.top().locked &&
finalizedLayer >= valueParser_.getLayer() && finalizedLayer >= valueParser_.getLayer() &&
(mandatoryLayer == Data::NO_LAYER || (mandatoryLayer == Data::NO_LAYER ||
mandatoryLayer > valueParser_.getLayer())) mandatoryLayer > valueParser_.getLayer()))
{ {
members->erase(i); members.erase(i);
} }
state_.push(State(true)); state_.push(State(true));
if (known) { if (known) {