1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: valueref.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef CONFIGMGR_CONFIGVALUEREF_HXX_
32 #define CONFIGMGR_CONFIGVALUEREF_HXX_
34 #include "noderef.hxx"
38 namespace node
{ struct Attributes
; }
40 namespace configuration
42 //-------------------------------------------------------------------------
44 //-------------------------------------------------------------------------
46 /// represents a value node in some tree
50 /// constructs an empty (invalid) node
53 ValueRef(rtl::OUString
const& aName
, unsigned int nParentPos
);
55 /// copy a node (with reference semantics)
56 ValueRef(ValueRef
const& rOther
);
57 /// copy a node (with reference semantics)
58 ValueRef
& operator=(ValueRef
const& rOther
);
60 void swap(ValueRef
& rOther
);
64 /// checks, if this represents an existing node
65 inline bool isValid() const;
67 bool checkValidState() const;
69 rtl::OUString m_sNodeName
;
70 unsigned int m_nParentPos
;
72 //-------------------------------------------------------------------------
74 /** extract the value from a plain value
77 com::sun::star::uno::Any
getSimpleValue(rtl::Reference
< Tree
> const& aTree
, ValueRef
const& aNode
)
78 { return aTree
->getNodeValue( aNode
); }
80 //-------------------------------------------------------------------------
81 inline bool ValueRef::isValid() const
83 OSL_ASSERT( m_nParentPos
== 0 || checkValidState() );
84 return m_nParentPos
!= 0;
87 //-------------------------------------------------------------------------
92 static SubNodeID
createEmpty() { return SubNodeID(); }
93 SubNodeID(rtl::Reference
< Tree
> const& rTree
, NodeRef
const& rParentNode
, rtl::OUString
const& aName
);
94 SubNodeID(NodeID
const& rParentNodeID
, rtl::OUString
const& aName
);
98 friend bool operator==(SubNodeID
const& lhs
, SubNodeID
const& rhs
)
99 { return lhs
.m_aParentID
== rhs
.m_aParentID
&& lhs
.m_sNodeName
== rhs
.m_sNodeName
; }
101 friend bool operator < (SubNodeID
const& lhs
, SubNodeID
const& rhs
);
103 bool isValidNode() const;
105 size_t hashCode() const { return m_aParentID
.hashCode() + 5*m_sNodeName
.hashCode(); }
106 // containing node this
107 NodeID
getParentID() const { return m_aParentID
; }
108 // containing node this
109 rtl::OUString
getNodeName() const { return m_sNodeName
; }
111 SubNodeID(); // create an empty one
112 rtl::OUString m_sNodeName
;
115 //-------------------------------------------------------------------------
117 void getAllChildrenHelper(NodeID
const& aNode
, std::vector
<SubNodeID
>& aList
);
119 //-------------------------------------------------------------------------
120 inline bool operator!=(SubNodeID
const& lhs
, SubNodeID
const& rhs
)
121 { return !(lhs
== rhs
); }
122 //---------------------------------------------------------------------
124 inline bool operator>=(SubNodeID
const& lhs
, SubNodeID
const& rhs
)
125 { return !(lhs
< rhs
); }
126 //---------------------------------------------------------------------
127 inline bool operator > (SubNodeID
const& lhs
, SubNodeID
const& rhs
)
128 { return (rhs
< lhs
); }
129 inline bool operator<=(SubNodeID
const& lhs
, SubNodeID
const& rhs
)
130 { return !(rhs
< lhs
); }
131 //-------------------------------------------------------------------------
135 #endif // CONFIGMGR_CONFIGVALUENODE_HXX_