merge the formfield patch from ooo-build
[ooovba.git] / configmgr / source / inc / node.hxx
blob92d7494c5c57154b7718d4fa8aafedabab10ab28
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: node.hxx,v $
10 * $Revision: 1.9 $
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"
36 #include "flags.hxx"
37 #include "anydata.hxx"
39 namespace configmgr
41 //-----------------------------------------------------------------------------
42 namespace node { struct Attributes; }
43 //-----------------------------------------------------------------------------
44 namespace sharable
46 struct TreeFragment;
47 union Node;
48 //-----------------------------------------------------------------------------
49 struct NodeInfo
51 rtl_uString * name;
52 sal_uInt16 parent; // always counts backwards
53 sal_uInt8 flags;
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 //-----------------------------------------------------------------------------
64 struct GroupNode
66 NodeInfo info;
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 //-----------------------------------------------------------------------------
78 struct SetNode
81 NodeInfo info;
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
98 static
99 sal_uInt8 * allocTemplateData(const rtl::OUString &rName,
100 const rtl::OUString &rModule);
101 static
102 sal_uInt8 * copyTemplateData(sal_uInt8 * _aTemplateData);
103 static
104 void releaseTemplateData(sal_uInt8 * _aTemplateData);
106 //-----------------------------------------------------------------------------
107 struct ValueNode
109 NodeInfo info;
110 AnyData value;
111 AnyData defaultValue;
113 bool isNull() const;
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);
122 void setToDefault();
123 void changeDefault(com::sun::star::uno::Any const & newDefault);
125 static inline ValueNode * from(Node * node);
127 private:
128 void releaseValue();
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 //-----------------------------------------------------------------------------
135 union Node
137 NodeInfo info;
138 GroupNode group;
139 SetNode set;
140 ValueNode value;
142 // info access
143 bool isNamed(rtl::OUString const & _aName) const;
144 rtl::OUString getName() const;
145 node::Attributes getAttributes() const;
146 bool isDefault() const;
148 // type checks
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); }
153 // checked access
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;
161 // navigation
162 bool isFragmentRoot() const;
163 #if OSL_DEBUG_LEVEL > 0
164 Node * getParentNode();
165 Node const * getParentNode() const;
166 #endif
167 TreeFragment * getTreeFragment();
168 TreeFragment const * getTreeFragment() const;
170 Node * getSubnode(rtl::OUString const & name);
172 private:
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