diff options
author | Jörg Barfurth <jb@openoffice.org> | 2001-06-20 19:19:26 +0000 |
---|---|---|
committer | Jörg Barfurth <jb@openoffice.org> | 2001-06-20 19:19:26 +0000 |
commit | 43c5825ecb1649867046021da2ed2e429419f276 (patch) | |
tree | ccefb9927d7e39b04e14005398602869fb8d300b /configmgr/source | |
parent | 1fb37f698619762ce3b49cd60680f661f9709194 (diff) |
#88036# Changed interface of view layer; Prepared for path syntax change
Diffstat (limited to 'configmgr/source')
-rw-r--r-- | configmgr/source/inc/anynoderef.hxx | 236 | ||||
-rw-r--r-- | configmgr/source/inc/noderef.hxx | 276 | ||||
-rw-r--r-- | configmgr/source/inc/valueref.hxx | 188 |
3 files changed, 600 insertions, 100 deletions
diff --git a/configmgr/source/inc/anynoderef.hxx b/configmgr/source/inc/anynoderef.hxx new file mode 100644 index 000000000000..fe7310efac28 --- /dev/null +++ b/configmgr/source/inc/anynoderef.hxx @@ -0,0 +1,236 @@ +/************************************************************************* + * + * $RCSfile: anynoderef.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jb $ $Date: 2001-06-20 20:19:26 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef CONFIGMGR_CONFIGANYNODE_HXX_ +#define CONFIGMGR_CONFIGANYNODE_HXX_ + +#ifndef CONFIGMGR_CONFIGNODE_HXX_ +#include "noderef.hxx" +#endif + +namespace configmgr +{ + namespace configapi { class Factory; } + + namespace configuration + { + //------------------------------------------------------------------------- + class Name; + struct Attributes; + //------------------------------------------------------------------------- + + namespace argument { struct NoValidate; } + + typedef com::sun::star::uno::Type UnoType; + typedef com::sun::star::uno::Any UnoAny; + //------------------------------------------------------------------------- + + class NodeRef; + class ValueRef; + class AnyNodeRef; + class NodeID; + + class Tree; + + class Node; + class TreeImpl; + + typedef unsigned int NodeOffset; + typedef unsigned int TreeDepth; + //------------------------------------------------------------------------- + + /// represents any node in some tree + class AnyNodeRef + { + public: + /// constructs an empty (invalid) node + AnyNodeRef(); + + /// converts an inner node + explicit AnyNodeRef(NodeRef const& aInnerNode); + /// converts a value node + explicit AnyNodeRef(ValueRef const& aValueNode); + + /// copy a node (with reference semantics) + AnyNodeRef(AnyNodeRef const& rOther); + /// copy a node (with reference semantics) + AnyNodeRef& operator=(AnyNodeRef const& rOther); + + void swap(AnyNodeRef& rOther); + + ~AnyNodeRef(); + + /// checks, if this represents an existing node + inline bool isValid() const; + + /// checks if this a node (rather than a value only) + bool isNode() const; + + /// converts this, if it is a value + ValueRef toValue() const; + + /// converts this, if it is a inner node + NodeRef toNode() const; + + private: + friend class Tree; + friend class TreeImplHelper; + AnyNodeRef(Node* pImpl, NodeOffset nParentPos, TreeDepth m_nDepth); + AnyNodeRef(Name const& aName, Node* pParentImpl, NodeOffset nParentPos); + + bool checkValidState() const; + private: + Name m_sNodeName; + Node* m_pUsedImpl; + NodeOffset m_nUsedPos; + TreeDepth m_nDepth; + }; + //------------------------------------------------------------------------- + + /** checks whether there are any immediate children of <var>aNode</var> (which is in <var>aTree</var>) + + @return + <TRUE/> if a child node exists + <FALSE/> otherwise + */ + inline + bool hasChildOrElement(Tree const& aTree, AnyNodeRef const& aNode) + { return aNode.isNode() && hasChildOrElement(aTree,aNode.toNode()); } + + /** checks whether there is an immediate child of <var>aNode</var> (which is in <var>aTree</var>) + specified by <var>aName</var> + + @return + <TRUE/> if the child node exists + <FALSE/> otherwise + */ + inline + bool hasChildOrElement(Tree const& aTree, AnyNodeRef const& aNode, Name const& aName) + { return aNode.isNode() && hasChildOrElement(aTree,aNode.toNode(),aName); } + + /** tries to find the immediate child of <var>aNode</var> (which is in <var>aTree</var>) + specified by <var>aName</var> + <p> On return <var>aNode</var> is modified to refer to the node found and + <var>aTree</var> will then refer to the tree that node is in. + <p/> + + @return The requested child node, if it exists + (then <var>aTree</var> refers to the tree containing the desired node), + */ + AnyNodeRef getChildOrElement(Tree& aTree, NodeRef const& aParentNode, Name const& aName); + + /** tries to find the immediate child of <var>aNode</var> (which is in <var>aTree</var>) + specified by <var>aName</var> + <p> On return <var>aNode</var> is modified to refer to the node found and + <var>aTree</var> will then refer to the tree that node is in. + <p/> + <p>Caution: May miss an existing child unless the child has been accessed before.</p> + + @return The requested child node, if it exists + (then <var>aTree</var> refers to the tree containing the desired node) + + @see NodeRef::getAvailableChild + */ + AnyNodeRef getAvailableChildOrElement(Tree& aTree, NodeRef const& aNode, Name const& aName); + + /** tries to find the descendant of <var>aNode</var> (which is in <var>aTree</var>) specified by <var>aPath</var> + <p> This function follows the given path stepwise, until a requested node is missing in the tree.</p> + <p> On return <var>aNode</var> is modified to refer to the last inner node found and + <var>aTree</var> will then refer to the tree that node is in. + <p/> + <p> Also, <var>aPath</var> is modified to contain the unresolved part of the original path. + </p> + + @return the requested node, if the path could be resolved completely + (so <var>aNode</var> and <var>aTree</var> refer to the desired node or its parent, + and <var>aPath</var> is empty)<BR/> + an invalid node otherwise + */ + AnyNodeRef getDescendant(Tree& aTree, NodeRef& aNode, RelativePath& aPath); + + /** tries to find the descendant of <var>aNode</var> (which is in <var>aTree</var>) specified by <var>aPath</var> + <p> This function follows the given path stepwise, until a requested node is missing in the tree.</p> + <p> On return <var>aNode</var> is modified to refer to the last inner node found and + <var>aTree</var> will then refer to the tree that node is in. + <p/> + <p> Also, <var>aPath</var> is modified to contain the unresolved part of the original path. + </p> + <p>Caution: May miss existing descendants unless the node has been accessed before.</p> + + @return the requested node, if the path could be resolved completely + (so <var>aNode</var> and <var>aTree</var> refer to the desired node or its parent, + and <var>aPath</var> is empty)<BR/> + an invalid node otherwise + */ + AnyNodeRef getDescendantAvailable(Tree& aTree, NodeRef& aNode, RelativePath& aPath); + + //------------------------------------------------------------------------- + inline bool AnyNodeRef::isValid() const + { + OSL_ASSERT( m_pUsedImpl == 0 || checkValidState() ); + return m_pUsedImpl != 0; + } + + //------------------------------------------------------------------------- + } +} + +#endif // CONFIGMGR_CONFIGANYNODE_HXX_ diff --git a/configmgr/source/inc/noderef.hxx b/configmgr/source/inc/noderef.hxx index a64cd4f820d9..afcc5b69cec8 100644 --- a/configmgr/source/inc/noderef.hxx +++ b/configmgr/source/inc/noderef.hxx @@ -2,9 +2,9 @@ * * $RCSfile: noderef.hxx,v $ * - * $Revision: 1.8 $ + * $Revision: 1.9 $ * - * last change: $Author: jb $ $Date: 2001-02-13 16:13:26 $ + * last change: $Author: jb $ $Date: 2001-06-20 20:19:26 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -62,14 +62,15 @@ #ifndef CONFIGMGR_CONFIGNODE_HXX_ #define CONFIGMGR_CONFIGNODE_HXX_ -#ifndef _OSL_DIAGNOSE_H_ -#include <osl/diagnose.h> -#endif - #include "apitypes.hxx" #include "configexcept.hxx" +#include "configpath.hxx" #include <vector> +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif + namespace configmgr { class INode; @@ -83,7 +84,6 @@ namespace configmgr class AbsolutePath; class RelativePath; - struct NodeInfo; struct Attributes; class NodeChange; @@ -97,14 +97,12 @@ namespace configmgr typedef com::sun::star::uno::Any UnoAny; //------------------------------------------------------------------------- - struct NodeState - { - enum State { eDEFAULT, eREPLACING, eMODIFYING, eREMOVING, eUNCHANGED = -1 }; - }; - //------------------------------------------------------------------------- + class NodeRef; + class ValueRef; + class AnyNodeRef; + class ElementRef; class NodeID; - class NodeRef; class Tree; class Node; @@ -115,17 +113,19 @@ namespace configmgr const TreeDepth C_TreeDepthAll = ~0u; //------------------------------------------------------------------------- - /// interface for a class that can be used to do some operation on a set of <type>NodeRef</type>s. + /// interface for a class that can be used to do some operation on a set of <type>NodeRef</type>s and <type>ValueRef</type>s. struct NodeVisitor { /// returned from <method>handle</method> to indicate whether the operation is complete or should continue enum Result { DONE, CONTINUE }; /// do the operation on <var>aNode</var>. needs to be implemented by concrete visitor classes - virtual Result handle(NodeRef const& aNode) = 0; + virtual Result handle(Tree const& aTree, NodeRef const& aNode) = 0; + /// do the operation on <var>aValue</var>. needs to be implemented by concrete visitor classes + virtual Result handle(Tree const& aTree, ValueRef const& aValue) = 0; }; //------------------------------------------------------------------------- - /// represents a node position in some tree + /// represents a inner node position in some tree class NodeRef { public: @@ -144,50 +144,10 @@ namespace configmgr /// checks, if this represents an existing node inline bool isValid() const; - /// checks whether this node has any child nodes (of its own). - bool hasChildren() const; - - /// checks whether this node owns a child node named <var>aName</var>. - bool hasChild(Name const& aName) const; - - /** gets the owned child node named <var>aName</var> of this node. - <p>Also sets <var>aTree<var/> to point to the tree containing that node.</p> - <p>PRE: <code>hasChild(aName) == true</code></p> - <p>If there is no such node, may return an empty node or raise an exception (?)</p> - - @throws InvalidName - if <var>aName</var> is not a valid child name for this node - */ - NodeRef getChild(Name const& aName, Tree& aTree) const; - - /** gets the owned child node named <var>aName</var> of this node, if it is available. - <p>Also sets <var>aTree<var/> to point to the tree containing that node.</p> - <p>If there is no such node, returns an empty node.</p> - <p>Caution: May miss existing children unless hasChild/getChild has been called before.</p> - - @throws InvalidName - if <var>aName</var> is not a valid child name for this node - */ - NodeRef getAvailableChild(Name const& aName, Tree& aTree) const; - - /// return a <type>NodeInfo</type> showing the attributes of this - NodeInfo getInfo() const; - - /// return a <type>NodeInfo</type> showing the attributes of this - Attributes getAttributes() const; - - /// return the local <type>Name</type> of this (or an empty name, if there isn't one) - Name getName() const; - - /// get the Uno <type scope='com::sun::star::uno'>Type</type> of the object represented by this node - UnoType getUnoType() const; - - /// dispatch this node to a Visitor - NodeVisitor::Result accept(NodeVisitor& aVisitor) const { return aVisitor.handle(*this); } - private: friend class Tree; friend class TreeImplHelper; + friend class AnyNodeRef; NodeRef(Node* pImpl, NodeOffset nPos, TreeDepth nDepth); private: Node* m_pImpl; @@ -196,7 +156,7 @@ namespace configmgr }; //------------------------------------------------------------------------- - /** represents a hierarchy of config entries (identified by <type>NodeRef</type>s) + /** represents a hierarchy of config entries (identified by <type>NodeRef</type>s and <type>ValueRef</type>s) <p>Examples for trees include</p> <ulist> @@ -225,54 +185,163 @@ namespace configmgr // releases the data this tree operates on void disposeData(); - /// retrieves the number of immediately contained nodes - NodeOffset getContainedNodeCount() const; + /// retrieves the number of immediately contained (subtree) nodes + NodeOffset getContainedInnerNodeCount() const; + + /// checks whether the node <var>aNode</var> is a valid inner node in this tree. + bool isValidNode(AnyNodeRef const& aNode) const; - /// checks whether the node <var>aNode</var> is a valid node in this tree. + /// checks whether the node <var>aNode</var> is a valid inner node in this tree. bool isValidNode(NodeRef const& aNode) const; + /// checks whether the node <var>aNode</var> is a valid value node in this tree. + bool isValidNode(ValueRef const& aNode) const; + + /// checks whether the node <var>aNode</var> has any element nodes (of its own). + bool hasElements(NodeRef const& aNode) const; + + /// checks whether the node <var>aNode</var> has a element node named <var>aName</var>. + bool hasElement(NodeRef const& aNode, Name const& aName) const; + + /** gets the element named <var>aName</var> of node <var>aNode</var>. + <p>PRE: <code>hasElement(aNode,aName) == true</code></p> + <p>If there is no such element, may return an empty node or raise an exception (?)</p> + + @throws InvalidName + if <var>aName</var> is not a valid child name for this node + */ + ElementRef getElement(NodeRef const& aNode, Name const& aName) const; + + /** gets the element named <var>aName</var> of node <var>aNode</var>, if it is available. + <p>PRE: <code>hasElement(aNode,aName) == true</code></p> + <p>If there is no such element, may return an empty node or raise an exception (?)</p> + <p>Caution: May miss existing children unless hasChild/getChild has been called before.</p> + + @throws InvalidName + if <var>aName</var> is not a valid child name for this node + */ + ElementRef getAvailableElement(NodeRef const& aNode, Name const& aName) const; + + /// checks whether the node <var>aNode</var> has any child value (in this tree). + bool hasChildValues(NodeRef const& aNode) const; + + /// checks whether the node <var>aNode</var> has any child subtrees (in this tree). + bool hasChildNodes(NodeRef const& aNode) const; + /// checks whether the node <var>aNode</var> has any child nodes (in this tree). bool hasChildren(NodeRef const& aNode) const; - /// checks whether the node <var>aNode</var> have a child node (in this tree) named <var>aName</var>. + /// checks whether the node <var>aNode</var> has a child value (in this tree) named <var>aName</var>. + bool hasChildValue(NodeRef const& aNode, Name const& aName) const; + + /// checks whether the node <var>aNode</var> has a child subtree (in this tree) named <var>aName</var>. + bool hasChildNode(NodeRef const& aNode, Name const& aName) const; + + /// checks whether the node <var>aNode</var> has a child node (in this tree) named <var>aName</var>. bool hasChild(NodeRef const& aNode, Name const& aName) const; - /** gets the child node (in this tree) named <var>aName</var> of node <var>aNode</var>. - <p>PRE: <code>hasChild(aNode,aName) == true</code></p> + /** gets the child value (in this tree) named <var>aName</var> of node <var>aNode</var>. + <p>PRE: <code>hasChildValue(aNode,aName) == true</code></p> + <P>If there is no such node, may return an empty node or raise an exception (?)</p> + + @throws InvalidName + if <var>aName</var> is not a valid child name for this node + */ + ValueRef getChildValue(NodeRef const& aNode, Name const& aName) const; + + /** gets the child value (in this tree) named <var>aName</var> of node <var>aNode</var>. + <p>PRE: <code>hasChildNode(aNode,aName) == true</code></p> <P>If there is no such node, may return an empty node or raise an exception (?)</p> @throws InvalidName if <var>aName</var> is not a valid child name for this node */ - NodeRef getChild(NodeRef const& aNode, Name const& aName) const; + NodeRef getChildNode(NodeRef const& aNode, Name const& aName) const; + + /** gets the child value (in this tree) named <var>aName</var> of node <var>aNode</var>. + <p>PRE: <code>hasChildNode(aNode,aName) == true</code></p> + <P>If there is no such node, may return an empty node or raise an exception (?)</p> + + @throws InvalidName + if <var>aName</var> is not a valid child name for this node + */ + AnyNodeRef getAnyChild(NodeRef const& aNode, Name const& aName) const; + + /// return the local <type>Name</type> of the root node of this tree + Name getRootName() const; + + /// return the local <type>Name</type> of node <var>aNode</var> in this tree + Name getName(NodeRef const& aNode) const; + + /// return the local <type>Name</type> of node <var>aNode</var> in this tree + Name getName(AnyNodeRef const& aNode) const; + + /// return the local <type>Name</type> of value <var>aValue</var> in this tree + Name getName(ValueRef const& aValue) const; + + /// return the <type>Attributes</type> of node <var>aNode</var> in this tree + Attributes getAttributes(NodeRef const& aNode) const; + + /// return the <type>Attributes</type> of node <var>aNode</var> in this tree + Attributes getAttributes(AnyNodeRef const& aNode) const; + + /// return the <type>Attributes</type> of value <var>aValue</var> in this tree + Attributes getAttributes(ValueRef const& aValue) const; + + /// get the Uno <type scope='com::sun::star::uno'>Type</type> of value <var>aValue</var> in this tree + UnoType getUnoType(ValueRef const& aValue) const; // Parent/NodeRef context handling public: /// return the parent <type>NodeRef</type> of <var>aNode</var> (or an empty node, if it is the tree root) - NodeRef getParent(NodeRef const& aNode) const; + NodeRef getParent(AnyNodeRef const& aNode) const; + + /// return the parent <type>NodeRef</type> of <var>aNode</var> (or an empty node, if it is the tree root) + NodeRef getParent(NodeRef const& aNode) const; + + /// return the parent <type>NodeRef</type> of <var>aValue</var> (or an empty node, if it is the tree root) + NodeRef getParent(ValueRef const& aValue) const; /// return the <type>Path</type> of <var>aNode</var>, relative to the tree root (or an empty path if it is empty) RelativePath getLocalPath(NodeRef const& aNode) const; + /// return the <type>Path</type> of <var>aNode</var> + RelativePath getLocalPath(ValueRef const& aNode) const; + /// gets the root node of this tree NodeRef getRootNode() const; /// checks whether <var>aNode</var> is the root node of this tree bool isRootNode(NodeRef const& aNode) const; - // default value handling public: + // value handling + /** retrieves the current value for <var>aNode</var>, provided there is one and it + is available. + */ + UnoAny getNodeValue(ValueRef const& aNode) const; // only works for value nodes + + // default value handling /// ensure default values are available for nodes where they can be provided at all void ensureDefaults() const; /// checks whether <var>aNode</var> assumes its default value - bool isNodeDefault(NodeRef const& aNode) const; // only works for value nodes + bool isNodeDefault(ValueRef const& aNode) const; // only works for value nodes + + /// checks whether <var>aNode</var> assumes its default state + bool isNodeDefault(AnyNodeRef const& aNode) const; /** retrieves the default value for <var>aNode</var>, provided there is one and it is available. <p>call <method>Tree::ensureDefaults</method> first to achieve best results</p> */ - UnoAny getNodeDefault(NodeRef const& aNode) const; // only works for value nodes + UnoAny getNodeDefault(ValueRef const& aNode) const; // only works for value nodes + + /** retrieves the default value for <var>aNode</var>, provided there is one and it + is available. + <p>call <method>Tree::ensureDefaults</method> first to achieve best results</p> + */ + UnoAny getNodeDefault(AnyNodeRef const& aNode) const; // Tree context handling public: @@ -294,6 +363,9 @@ namespace configmgr /// applies <var>aChange</var> to <var>aNode</var> within this tree void integrate(NodeChange& aChange, NodeRef const& aNode, bool bLocal) const; + /// applies <var>aChange</var> to <var>aNode</var> within this tree + void integrate(NodeChange& aChange, ValueRef const& aNode, bool bLocal) const; + /// applies <var>aChanges</var> to the children or descendants of <var>aNode</var> within this tree void integrate(NodeChanges& aChanges, NodeRef const& aNode, bool bLocal) const; @@ -302,6 +374,17 @@ namespace configmgr // Visitor handling public: + /// dispatch node <var>aNode</var> to a Visitor + NodeVisitor::Result visit(NodeRef const& aNode, NodeVisitor& aVisitor) const + { return aVisitor.handle(*this,aNode); } + + /// dispatch node <var>aNode</var> to a Visitor + NodeVisitor::Result visit(ValueRef const& aNode, NodeVisitor& aVisitor) const + { return aVisitor.handle(*this,aNode); } + + /// dispatch node <var>aNode</var> to a Visitor + NodeVisitor::Result visit(AnyNodeRef const& aNode, NodeVisitor& aVisitor) const; + /** lets <var>aVisitor</var> visit the child nodes of <var>aNode</var> <p>The order in which nodes are visited is repeatable (but currently unspecified)</p> <p> Visits nodes until NodeVisitor::DONE is returned, then returns NodeVisitor::DONE.<BR/> @@ -310,6 +393,15 @@ namespace configmgr </p> */ NodeVisitor::Result dispatchToChildren(NodeRef const& aNode, NodeVisitor& aVisitor) const; + + /** lets <var>aVisitor</var> visit the child nodes of <var>aNode</var> + <p>The order in which nodes are visited is repeatable (but currently unspecified)</p> + <p> Visits nodes until NodeVisitor::DONE is returned, then returns NodeVisitor::DONE.<BR/> + If all visits return NodeVisitor::CONTINUE, returns NodeVisitor::CONTINUE.<BR/> + If no children are present, returns NodeVisitor::CONTINUE + </p> + */ + NodeVisitor::Result dispatchToChildren(AnyNodeRef const& aNode, NodeVisitor& aVisitor) const; // More NodeRef handling public: NodeRef bind(NodeOffset nNode) const; @@ -368,24 +460,13 @@ namespace configmgr */ RelativePath reduceRelativePath(OUString const& aPath, Tree const& aTree, NodeRef const& aBaseNode); - /* * reduce <var>aPath</var> to be a path relative to (<var>aTree<var/>,<var>aNode<var/>) - - @returns - <var>aPath<var/> if it already is a relative path or the part of it relative to <var>aNode<var/> - if it is an absolute path that to a descendant of <var>aNode<var/> - - @returns - an empty path, if <var>aPath<var/> is an absolute path that is not to a descendant of <var>aNode<var/> - RelativePath reduceRelativePath(OUString const& aPath, Tree const& aTree, NodeRef const& aBaseNode, argument::NoValidate); - */ - /** checks whether there are any immediate children of <var>aNode</var> (which is in <var>aTree</var>) @return <TRUE/> if a child node exists <FALSE/> otherwise */ - bool hasChildNode(Tree const& aTree, NodeRef const& aNode); + bool hasChildOrElement(Tree const& aTree, NodeRef const& aNode); /** checks whether there is an immediate child of <var>aNode</var> (which is in <var>aTree</var>) specified by <var>aName</var> @@ -394,7 +475,7 @@ namespace configmgr <TRUE/> if the child node exists <FALSE/> otherwise */ - bool hasChildNode(Tree const& aTree, NodeRef const& aNode, Name const& aName); + bool hasChildOrElement(Tree const& aTree, NodeRef const& aNode, Name const& aName); /** tries to find the immediate child of <var>aNode</var> (which is in <var>aTree</var>) specified by <var>aName</var> @@ -407,7 +488,7 @@ namespace configmgr (so <var>aNode</var> and <var>aTree</var> refer to the desired node), <FALSE/> otherwise */ - bool findChildNode(Tree& aTree, NodeRef& aNode, Name const& aName); + bool findInnerChildNode(Tree& aTree, NodeRef& aNode, Name const& aName); /** tries to find the immediate child of <var>aNode</var> (which is in <var>aTree</var>) specified by <var>aName</var> @@ -423,7 +504,7 @@ namespace configmgr @see NodeRef::getAvailableChild */ - bool findAvailableChildNode(Tree& aTree, NodeRef& aNode, Name const& aName); + bool findInnerAvailableChildNode(Tree& aTree, NodeRef& aNode, Name const& aName); /** tries to find the descendant of <var>aNode</var> (which is in <var>aTree</var>) specified by <var>aPath</var> <p> This function follows the given path stepwise, until a requested node is missing in the tree.</p> @@ -439,7 +520,7 @@ namespace configmgr <var>aPath</var> is empty)<BR/> <FALSE/> otherwise */ - bool findDescendantNode(Tree& aTree, NodeRef& aNode, RelativePath& aPath); + bool findInnerDescendantNode(Tree& aTree, NodeRef& aNode, RelativePath& aPath); /** tries to find the descendant of <var>aNode</var> (which is in <var>aTree</var>) specified by <var>aPath</var> <p> This function follows the given path stepwise, until a requested node is miss in the tree, @@ -458,32 +539,26 @@ namespace configmgr <var>aPath</var> is empty)<BR/> <FALSE/> otherwise */ - bool findDescendantAvailable(Tree& aTree, NodeRef& aNode, RelativePath& aPath); + bool findInnerDescendantAvailable(Tree& aTree, NodeRef& aNode, RelativePath& aPath); - /// test whether the given node is a plain value - bool isSimpleValue(Tree const& aTree, NodeRef const& aNode); + /// test whether the given node is a structural (inner) node + bool isStructuralNode(Tree const& aTree, NodeRef const& aNode); - /// test whether the given node is a inner group node + /// test whether the given inner node is a group node bool isGroupNode(Tree const& aTree, NodeRef const& aNode); - /// test whether the given node is a inner set node - bool isSetNode(Tree const& aTree, NodeRef const& aNode); + /// get the value for a node that is a simple value (as tree element) + UnoAny getSimpleElementValue(Tree const& aTree, NodeRef const& aNode); - /** extract the value from a plain value - <p> PRE: <code>isSimpleValue(aTree,aNode)</code> - </p> - */ - UnoAny getSimpleValue(Tree const& aTree, NodeRef const& aNode); + /// test whether the given inner node is a set node + bool isSetNode(Tree const& aTree, NodeRef const& aNode); ISynchronizedData* getRootLock(Tree const& aTree); typedef std::vector<NodeID> NodeIDList; void getAllContainedNodes(Tree const& aTree, NodeIDList& aList); - void getAllChildrenHelper(NodeID const& aNode, NodeIDList& aList); - NodeID getParentHelper(NodeID const& aNode); - NodeID findNeighbor(NodeID const& aNode, NodeOffset nIndex); - NodeID findNodeFromIndex(NodeID const& aNode, NodeOffset nIndex); + NodeID findNodeFromIndex(Tree const& aTree, NodeOffset nIndex); //------------------------------------------------------------------------- inline bool NodeRef::isValid() const @@ -492,6 +567,7 @@ namespace configmgr return m_pImpl != 0; } + //------------------------------------------------------------------------- inline bool operator!=(NodeID const& lhs, NodeID const& rhs) { return !(lhs == rhs); } //--------------------------------------------------------------------- diff --git a/configmgr/source/inc/valueref.hxx b/configmgr/source/inc/valueref.hxx new file mode 100644 index 000000000000..c843bb938c9c --- /dev/null +++ b/configmgr/source/inc/valueref.hxx @@ -0,0 +1,188 @@ +/************************************************************************* + * + * $RCSfile: valueref.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jb $ $Date: 2001-06-20 20:19:26 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef CONFIGMGR_CONFIGVALUEREF_HXX_ +#define CONFIGMGR_CONFIGVALUEREF_HXX_ + +#ifndef CONFIGMGR_CONFIGNODE_HXX_ +#include "noderef.hxx" +#endif + +namespace configmgr +{ + namespace configuration + { + //------------------------------------------------------------------------- + class Name; + struct Attributes; + //------------------------------------------------------------------------- + + namespace argument { struct NoValidate; } + + typedef com::sun::star::uno::Type UnoType; + typedef com::sun::star::uno::Any UnoAny; + //------------------------------------------------------------------------- + + class Node; + class TreeImpl; + + typedef unsigned int NodeOffset; + //------------------------------------------------------------------------- + + /// represents a value node in some tree + class ValueRef + { + public: + /// constructs an empty (invalid) node + ValueRef(); + + /// copy a node (with reference semantics) + ValueRef(ValueRef const& rOther); + /// copy a node (with reference semantics) + ValueRef& operator=(ValueRef const& rOther); + + void swap(ValueRef& rOther); + + ~ValueRef(); + + /// checks, if this represents an existing node + inline bool isValid() const; + + private: + friend class Tree; + friend class TreeImplHelper; + ValueRef(Name const& aName, Node* pParentImpl, NodeOffset nParentPos); + + bool checkValidState() const; + private: + Name m_sNodeName; + Node* m_pParentImpl; + NodeOffset m_nParentPos; + }; + //------------------------------------------------------------------------- + + /** extract the value from a plain value + */ + inline + UnoAny getSimpleValue(Tree const& aTree, ValueRef const& aNode) + { return aTree.getNodeValue( aNode ); } + + //------------------------------------------------------------------------- + inline bool ValueRef::isValid() const + { + OSL_ASSERT( m_pParentImpl == 0 || checkValidState() ); + return m_pParentImpl != 0; + } + + //------------------------------------------------------------------------- + + class SubNodeID + { + public: + static SubNodeID createEmpty() { return SubNodeID(); } + SubNodeID(Tree const& rTree, ValueRef const& rNode); + SubNodeID(Tree const& rTree, NodeRef const& rParentNode, Name const& aName); + SubNodeID(NodeID const& rParentNodeID, Name const& aName); + + // comparison + // equality + friend bool operator==(SubNodeID const& lhs, SubNodeID const& rhs) + { return lhs.m_aParentID == rhs.m_aParentID && lhs.m_sNodeName == rhs.m_sNodeName; } + // ordering + friend bool operator < (SubNodeID const& lhs, SubNodeID const& rhs); + // checking + bool isEmpty() const; + // checking + bool isValidNode() const; + // hashing + size_t hashCode() const; + // containing node this + NodeID getParentID() const { return m_aParentID; } + // containing node this + Name getNodeName() const { return m_sNodeName; } + private: + SubNodeID(); // create an empty one + friend class TreeImplHelper; + Name m_sNodeName; + NodeID m_aParentID; + }; + //------------------------------------------------------------------------- + + typedef std::vector<SubNodeID> SubNodeIDList; + void getAllChildrenHelper(NodeID const& aNode, SubNodeIDList& aList); + + //------------------------------------------------------------------------- + inline bool operator!=(SubNodeID const& lhs, SubNodeID const& rhs) + { return !(lhs == rhs); } + //--------------------------------------------------------------------- + + inline bool operator>=(SubNodeID const& lhs, SubNodeID const& rhs) + { return !(lhs < rhs); } + //--------------------------------------------------------------------- + inline bool operator > (SubNodeID const& lhs, SubNodeID const& rhs) + { return (rhs < lhs); } + inline bool operator<=(SubNodeID const& lhs, SubNodeID const& rhs) + { return !(rhs < lhs); } + //------------------------------------------------------------------------- + } +} + +#endif // CONFIGMGR_CONFIGVALUENODE_HXX_ |