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: node.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 INCLUDED_SHARABLE_NODE_HXX
32 #define INCLUDED_SHARABLE_NODE_HXX
34 #include "rtl/ustring.hxx"
37 #include "anydata.hxx"
41 //-----------------------------------------------------------------------------
42 namespace node
{ struct Attributes
; }
43 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
52 sal_uInt16 parent
; // always counts backwards
54 sal_uInt8 type
; // contains discriminator for union
56 rtl::OUString
getName() const;
57 node::Attributes
getNodeInfoAttributes() const;
58 bool isDefault() const;
59 bool isLocalized() const;
61 void markAsDefault(bool bDefault
= true);
63 //-----------------------------------------------------------------------------
67 sal_uInt16 numDescendants
; // = number of descendants
69 bool hasDefaultsAvailable() const;
71 Node
* getFirstChild() const;
72 Node
* getNextChild(Node
* child
) const;
73 Node
* getChild(rtl::OUString
const & name
) const;
75 static inline GroupNode
* from(Node
* node
);
77 //-----------------------------------------------------------------------------
82 sal_uInt8
* elementType
; // points to template [MM:SetNode *?]
83 TreeFragment
* elements
; // points to first element (TreeFragmentHeader)
85 rtl::OUString
getElementTemplateName() const;
86 rtl::OUString
getElementTemplateModule() const;
88 TreeFragment
* getFirstElement() const;
89 TreeFragment
* getNextElement(TreeFragment
* _pElement
) const;
90 TreeFragment
* getElement(rtl::OUString
const & name
) const;
92 void addElement(TreeFragment
* newElement
);
93 TreeFragment
* removeElement(rtl::OUString
const & name
);
95 static inline SetNode
* from(Node
* node
);
97 // low-level helper for template data abstraction
99 sal_uInt8
* allocTemplateData(const rtl::OUString
&rName
,
100 const rtl::OUString
&rModule
);
102 sal_uInt8
* copyTemplateData(sal_uInt8
* _aTemplateData
);
104 void releaseTemplateData(sal_uInt8
* _aTemplateData
);
106 //-----------------------------------------------------------------------------
111 AnyData defaultValue
;
114 bool hasUsableDefault() const;
116 com::sun::star::uno::Any
getValue() const;
117 com::sun::star::uno::Type
getValueType() const;
118 com::sun::star::uno::Any
getUserValue() const;
119 com::sun::star::uno::Any
getDefaultValue() const;
121 void setValue(com::sun::star::uno::Any
const & newValue
);
123 void changeDefault(com::sun::star::uno::Any
const & newDefault
);
125 static inline ValueNode
* from(Node
* node
);
129 sal_uInt8
adaptType(com::sun::star::uno::Any
const & newValue
);
131 //-----------------------------------------------------------------------------
132 // TODO: optimized representation of localized values (now as set; mapping locale->element-name)
133 // TODO (?): better representation of sets of values
134 //-----------------------------------------------------------------------------
143 bool isNamed(rtl::OUString
const & _aName
) const;
144 rtl::OUString
getName() const;
145 node::Attributes
getAttributes() const;
146 bool isDefault() const;
149 bool isGroup() const { return typeIs (data::Type::nodetype_group
); }
150 bool isSet() const { return typeIs (data::Type::nodetype_set
); }
151 bool isValue() const { return typeIs (data::Type::nodetype_value
); }
154 inline GroupNode
* groupData();
155 inline GroupNode
const * groupData() const;
156 inline SetNode
* setData();
157 inline SetNode
const * setData() const;
158 inline ValueNode
* valueData();
159 inline ValueNode
const * valueData() const;
162 bool isFragmentRoot() const;
163 #if OSL_DEBUG_LEVEL > 0
164 Node
* getParentNode();
165 Node
const * getParentNode() const;
167 TreeFragment
* getTreeFragment();
168 TreeFragment
const * getTreeFragment() const;
170 Node
* getSubnode(rtl::OUString
const & name
);
173 bool typeIs(data::Type::Type eType
) const
174 { return (info
.type
& data::Type::mask_nodetype
) == eType
; }
177 //-----------------------------------------------------------------------------
178 inline GroupNode
* GroupNode::from(Node
* node
)
179 { return node
== 0 ? 0 : node
->groupData(); }
181 inline SetNode
* SetNode::from(Node
* node
)
182 { return node
== 0 ? 0 : node
->setData(); }
184 inline ValueNode
* ValueNode::from(Node
* node
)
185 { return node
== 0 ? 0 : node
->valueData(); }
187 inline GroupNode
* Node::groupData()
188 { return isGroup() ? &this->group
: NULL
; }
189 inline GroupNode
const * Node::groupData() const
190 { return isGroup() ? &this->group
: NULL
; }
191 inline SetNode
* Node::setData()
192 { return isSet() ? &this->set
: NULL
; }
193 inline SetNode
const * Node::setData() const
194 { return isSet() ? &this->set
: NULL
; }
195 inline ValueNode
* Node::valueData()
196 { return isValue() ? &this->value
: NULL
; }
197 inline ValueNode
const * Node::valueData() const
198 { return isValue() ? &this->value
: NULL
; }
200 inline Node
* node(ValueNode
* pNode
)
201 { return reinterpret_cast<Node
*>(pNode
); }
202 inline Node
* node(GroupNode
* pNode
)
203 { return reinterpret_cast<Node
*>(pNode
); }
204 inline Node
* node(SetNode
* pNode
)
205 { return reinterpret_cast<Node
*>(pNode
); }
207 inline Node
const * node(ValueNode
const* pNode
)
208 { return reinterpret_cast<Node
const*>(pNode
); }
209 inline Node
const * node(GroupNode
const* pNode
)
210 { return reinterpret_cast<Node
const*>(pNode
); }
211 inline Node
const * node(SetNode
const* pNode
)
212 { return reinterpret_cast<Node
const*>(pNode
); }
213 //-----------------------------------------------------------------------------
214 inline Node
& node(ValueNode
& pNode
)
215 { return reinterpret_cast<Node
&>(pNode
); }
216 inline Node
& node(GroupNode
& pNode
)
217 { return reinterpret_cast<Node
&>(pNode
); }
218 inline Node
& node(SetNode
& pNode
)
219 { return reinterpret_cast<Node
&>(pNode
); }
221 inline Node
const & node(ValueNode
const& pNode
)
222 { return reinterpret_cast<Node
const&>(pNode
); }
223 inline Node
const & node(GroupNode
const& pNode
)
224 { return reinterpret_cast<Node
const&>(pNode
); }
225 inline Node
const & node(SetNode
const& pNode
)
226 { return reinterpret_cast<Node
const&>(pNode
); }
227 //-----------------------------------------------------------------------------
229 //-----------------------------------------------------------------------------
232 #endif // INCLUDED_SHARABLE_NODE_HXX