merge the formfield patch from ooo-build
[ooovba.git] / configmgr / source / treemgr / nodechange.cxx
blobcfffd7cc15bf2f24848e07939a89712873d33512
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: nodechange.cxx,v $
10 * $Revision: 1.13 $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_configmgr.hxx"
34 #include "nodechange.hxx"
35 #include "nodechangeimpl.hxx"
36 #include "nodechangeinfo.hxx"
38 #include "noderef.hxx"
39 #include "tree.hxx"
41 #include <algorithm>
42 #include <osl/diagnose.h>
44 namespace configmgr
46 namespace configuration
49 //-----------------------------------------------------------------------------
50 // NodeChange handle class
51 //-----------------------------------------------------------------------------
53 //-----------------------------------------------------------------------------
54 inline void NodeChange::init()
56 if (m_pImpl) m_pImpl->acquire();
58 inline void NodeChange::deinit()
60 if (m_pImpl) m_pImpl->release();
63 //-----------------------------------------------------------------------------
64 NodeChange::NodeChange()
65 : m_pImpl(0)
68 //-----------------------------------------------------------------------------
70 NodeChange::NodeChange(NodeChangeImpl* pImpl)
71 : m_pImpl(pImpl)
73 init();
75 //-----------------------------------------------------------------------------
77 NodeChange::NodeChange(NodeChange const& rOther)
78 : m_pImpl(rOther.m_pImpl)
80 init();
82 //-----------------------------------------------------------------------------
84 NodeChange& NodeChange::operator=(NodeChange const& rOther)
86 NodeChange(rOther).swap(*this);
87 return *this;
89 //-----------------------------------------------------------------------------
91 void NodeChange::swap(NodeChange& rOther)
93 std::swap(m_pImpl,rOther.m_pImpl);
95 //-----------------------------------------------------------------------------
97 NodeChange::~NodeChange()
99 deinit();
101 //-----------------------------------------------------------------------------
103 bool NodeChange::maybeChange() const
105 return m_pImpl && m_pImpl->isChange(true);
107 //-----------------------------------------------------------------------------
109 bool NodeChange::isChange() const
111 return m_pImpl && m_pImpl->isChange(false);
113 //-----------------------------------------------------------------------------
115 sal_uInt32 NodeChange::getChangeInfos(NodeChangesInformation& _rInfos) const
117 sal_uInt32 nCount = 0;
118 if (m_pImpl)
120 sal_uInt32 nChanges = m_pImpl->getChangeDataCount();
122 for (sal_uInt32 ix = 0; ix < nChanges; ++ix)
124 NodeChangeInformation aSingleInfo;
125 aSingleInfo.change.type = NodeChangeData::eNoChange;
127 m_pImpl->fillChangeInfo(aSingleInfo,ix);
129 if ( !aSingleInfo.isEmptyChange() )
131 _rInfos.push_back(aSingleInfo);
132 ++nCount;
137 return nCount;
139 //-----------------------------------------------------------------------------
141 bool NodeChange::getChangeLocation(NodeChangeLocation& rLoc) const
143 return m_pImpl && m_pImpl->fillChangeLocation(rLoc);
146 //-----------------------------------------------------------------------------
148 // retrieve the tree where the change is actually taking place
149 rtl::Reference< Tree > NodeChange::getAffectedTree() const
151 if (this->maybeChange())
152 return m_pImpl->getTargetTree().get();
153 else
154 return NULL;
156 //-----------------------------------------------------------------------------
158 // retrieve the tree where the change is actually taking place
159 NodeRef NodeChange::getAffectedNode() const
161 if (this->maybeChange())
163 rtl::Reference<Tree> aTree = m_pImpl->getTargetTree();
164 unsigned int nOffset = m_pImpl->getTargetNode();
166 OSL_ASSERT(aTree.is() && aTree->isValidNode(nOffset));
168 if (aTree.is() && nOffset)
169 return aTree->getNode(nOffset);
171 return NodeRef();
173 //-----------------------------------------------------------------------------
175 NodeChange& NodeChange::test()
177 if (m_pImpl) m_pImpl->test();
178 return *this;
181 //-----------------------------------------------------------------------------
182 NodeChange const& NodeChange::test() const
184 if (m_pImpl) m_pImpl->test();
185 return *this;
188 //-----------------------------------------------------------------------------
189 NodeChange& NodeChange::apply()
191 if (m_pImpl) m_pImpl->apply();
192 return *this;
195 //-----------------------------------------------------------------------------
196 NodeChange const& NodeChange::apply() const
198 if (m_pImpl) m_pImpl->apply();
199 return *this;
202 //-----------------------------------------------------------------------------
203 // NodeChanges collection
204 //-----------------------------------------------------------------------------
206 NodeChanges::NodeChanges()
207 : m_aChanges()
210 //-----------------------------------------------------------------------------
212 bool NodeChanges::isEmpty() const
214 return m_aChanges.empty();
216 //-----------------------------------------------------------------------------
218 /// predicate for compact
220 static bool isEmptyChange(NodeChange const& aChange)
222 return !aChange.maybeChange();
224 //-----------------------------------------------------------------------------
227 NodeChanges& NodeChanges::compact()
229 m_aChanges.erase( std::remove_if(begin(),end(),isEmptyChange), end() );
230 return *this;
232 //-----------------------------------------------------------------------------
234 void NodeChanges::implTest() const
236 for(std::vector<NodeChange>::const_iterator it = begin(), stop = end(); it != stop; ++it)
238 it ->test();
241 //-----------------------------------------------------------------------------
242 /** insert a change into this collection
244 void NodeChanges::add(NodeChange const& aChange)
246 m_aChanges.push_back(aChange);
249 //-----------------------------------------------------------------------------
251 /** removes a change to <var>aNode</var> from this collection (if there is one)
252 void NodeChanges::reset(Node const& aNode)
257 sal_uInt32 NodeChanges::getChangesInfos(NodeChangesInformation& _rInfos) const
259 if (isEmpty()) return 0;
261 _rInfos.reserve(_rInfos.size() + this->getCount());
263 sal_Int32 nResult = 0;
264 for (std::vector<NodeChange>::const_iterator it = begin(); it != end(); ++it)
266 nResult += it->getChangeInfos(_rInfos);
269 return nResult;
271 //-----------------------------------------------------------------------------
272 //-----------------------------------------------------------------------------