merge the formfield patch from ooo-build
[ooovba.git] / configmgr / source / inc / nodechangeinfo.hxx
blob840f13ef8365a88b0e8454808d74be918a91c026
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: nodechangeinfo.hxx,v $
10 * $Revision: 1.12 $
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_CONFIGCHANGEINFO_HXX_
32 #define CONFIGMGR_CONFIGCHANGEINFO_HXX_
34 #include "configpath.hxx"
35 #include "noderef.hxx"
36 #include "valueref.hxx"
37 #include <rtl/ref.hxx>
39 #ifndef INCLUDED_VECTOR
40 #include <vector>
41 #define INCLUDED_VECTOR
42 #endif
44 namespace configmgr
46 namespace configuration
48 //-----------------------------------------------------------------------------
49 class NodeRef;
50 class ValueRef;
51 class NodeID;
52 class SubNodeID;
54 class ElementTree;
56 //-----------------------------------------------------------------------------
57 /// captures the values of something changing
58 template <class DataT>
59 struct DataChange
61 DataT newValue;
62 DataT oldValue;
64 DataChange()
65 : newValue(), oldValue()
68 DataChange(DataT const& newValue_, DataT const& oldValue_)
69 : newValue(newValue_), oldValue(oldValue_)
72 // note: maybe we should support a comparison object
73 bool isDataChange() const
74 { return !(oldValue == newValue); } // not using != to avoid conversion warning
77 //-----------------------------------------------------------------------------
78 /// information about what changed (but close to no context)
79 class NodeChangeData
81 public:
82 //-------------------------------------------------
83 enum Type
85 eNoChange,
87 // Changes to value nodes
88 eSetValue,
89 eSetDefault,
91 // Changes to set nodes
92 eInsertElement,
93 eReplaceElement,
94 eRemoveElement,
96 eRenameElementTree, // not fully supported yet
98 eResetSetDefault
100 //-------------------------------------------------
102 bool isEmptyChange() const { return eNoChange == type; }
103 bool isValueChange() const { return eSetValue <= type && type <= eSetDefault; }
104 bool isSetChange() const { return eInsertElement <= type && type <= eRemoveElement; }
105 bool isRemoveSetChange() const { return eRemoveElement == type;}
106 bool isReplaceSetChange() const { return eReplaceElement == type;}
107 //-------------------------------------------------
108 bool isDataChange() const;
110 //-------------------------------------------------
111 // wrapper object creation
112 rtl::Reference< Tree > getNewElementTree() const;
113 rtl::Reference< Tree > getOldElementTree() const;
115 NodeID getNewElementNodeID() const;
116 NodeID getOldElementNodeID() const;
117 //-------------------------------------------------
119 //-- Compiler barrier for element tree ------------
120 NodeChangeData();
121 NodeChangeData(NodeChangeData const& aOther);
122 NodeChangeData& operator=(NodeChangeData const& aOther);
123 ~NodeChangeData();
124 //-------------------------------------------------
125 Type type;
127 // Value change: old/new value; Set change: new/old api element (if known); Rename: old/new name
128 DataChange< com::sun::star::uno::Any > unoData;
129 // Value change: NULL,NULL; Set change: new/old tree element; Rename: the affected element-tree (twice)
130 DataChange< rtl::Reference<ElementTree> > element;
131 //-------------------------------------------------
134 //-------------------------------------------------
135 // Identify the location of a change. Interpretation of members may depend upon
136 class NodeChangeLocation
138 public:
139 //-------------------------------------------------
140 // checks whether the base has been properly set up.
141 // Does not check for existence of the affected node
142 #if OSL_DEBUG_LEVEL > 0
143 /// check whether the location has been initialized properly
144 bool isValidData() const;
145 #endif
146 /// check whether the location is for a valid object
147 bool isValidLocation() const;
149 //-------------------------------------------------
150 /// retrieve the path from the base node to the changed node (which might be a child of the affected node)
151 RelativePath getAccessor() const { return m_path; }
153 /// retrieve the tree where the change is actually initiated/reported
154 rtl::Reference< Tree > getBaseTree() const;
155 /// retrieve the node where the change is actually initiated/reported
156 NodeRef getBaseNode() const;
158 /// retrieve the tree where the change is actually taking place (may be Empty, if the tree has never been accessed)
159 rtl::Reference< Tree > getAffectedTreeRef() const;
160 /// identify the node where the change is actually taking place
161 NodeID getAffectedNodeID() const;
163 /// identify the node (within the affected tree), that actually is changed (this one may be a value node)
164 SubNodeID getChangingValueID() const;
166 //-------------------------------------------------
167 void setAccessor( RelativePath const& aAccessor );
169 void setBase( NodeID const& aBaseID );
170 void setBase( rtl::Reference< Tree > const& aBaseTree, NodeRef const& aBaseNode )
171 { setBase( NodeID(aBaseTree,aBaseNode) ); }
173 void setAffected( NodeID const& aTargetID );
174 void setAffected( rtl::Reference< Tree > const& aTargetTree, NodeRef const& aTargetNode )
175 { setAffected( NodeID(aTargetTree,aTargetNode) ); }
177 void setChangingSubnode( bool bSubnode = true );
178 //-------------------------------------------------
179 NodeChangeLocation();
180 // NodeChangeLocation(NodeChangeLocation const& aOther);
181 // NodeChangeLocation& operator=(NodeChangeLocation const& aOther);
182 // ~NodeChangeLocation();
183 //-------------------------------------------------
184 private:
185 RelativePath m_path; // path from baseNode to changing node
186 NodeID m_base; // a (non-empty) node
187 NodeID m_affected; // identifies the affected node (if available)
188 bool m_bSubNodeChanging; // do we change a value ?
189 //-------------------------------------------------
191 //-----------------------------------------------------------------------------
192 class NodeChangeInformation
194 public:
195 //-------------------------------------------------
196 explicit
197 NodeChangeInformation()
198 : change()
199 , location()
202 //-------------------------------------------------
203 NodeChangeData change;
204 NodeChangeLocation location;
206 //-------------------------------------------------
207 bool hasValidLocation() const { return location.isValidLocation(); }
208 bool isDataChange() const { return change.isDataChange(); }
210 bool isEmptyChange() const { return change.isEmptyChange(); }
211 bool isValueChange() const { return change.isValueChange(); }
212 bool isSetChange() const { return change.isSetChange(); }
213 //-------------------------------------------------
215 //-----------------------------------------------------------------------------
217 class NodeChangesInformation
219 public:
220 std::vector< NodeChangeInformation >::size_type size() const { return m_data.size(); }
221 bool empty() const { return m_data.empty(); }
223 void reserve(std::vector< NodeChangeInformation >::size_type sz_) { m_data.reserve(sz_); }
224 void clear() { m_data.clear(); }
225 void swap(NodeChangesInformation& aOther) throw() { m_data.swap(aOther.m_data); }
227 void push_back(NodeChangeInformation const& aChange_)
228 { m_data.push_back(aChange_); }
230 std::vector< NodeChangeInformation >::const_iterator begin() const { return m_data.begin(); }
231 std::vector< NodeChangeInformation >::const_iterator end() const { return m_data.end(); }
232 private:
233 std::vector< NodeChangeInformation > m_data;
235 //-----------------------------------------------------------------------------
239 #if !defined(WNT) || (defined(WNT) && _MSC_VER < 1400)
240 namespace std
242 template <>
243 inline
244 void swap(configmgr::configuration::NodeChangesInformation& lhs, configmgr::configuration::NodeChangesInformation& rhs)
245 { lhs.swap(rhs); }
247 #endif
249 #endif // CONFIGMGR_CONFIGCHANGEINFO_HXX_