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

View File

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

View File

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

View File

@ -60,8 +60,6 @@ struct Data: private boost::noncopyable {
NodeMap templates;
NodeMap components;
Modifications modifications;
static rtl::OUString createSegment(
@ -91,6 +89,8 @@ struct Data: private boost::noncopyable {
rtl::Reference< Node > getTemplate(
int layer, rtl::OUString const & fullName) const;
NodeMap & getComponents() const;
Additions * addExtensionXcuAdditions(
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);
}
NodeMap * GroupNode::getMemberMap() {
return &members_;
NodeMap & GroupNode::getMembers() {
return members_;
}
rtl::OUString GroupNode::getTemplateName() const {

View File

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

View File

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

View File

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

View File

@ -30,7 +30,11 @@
#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/ustring.h"
#include "rtl/ustring.hxx"
#include "data.hxx"
@ -39,15 +43,17 @@
namespace configmgr {
NodeMap const & Node::getMembers() const {
NodeMap * members = const_cast< Node * >(this)->getMemberMap();
assert(members != 0);
return *members;
namespace {
namespace css = com::sun::star;
}
NodeMap * Node::getMemberMap() {
NodeMap & Node::getMembers() {
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 {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -586,7 +586,8 @@ void writeModFile(
{
writeModifications(
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);
}
writeData(tmp.handle, RTL_CONSTASCII_STRINGPARAM("</oor:items>"));

View File

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

View File

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