update dev300-m58
[ooovba.git] / configmgr / source / api2 / apinodeupdate.hxx
blobbade3975f3cd203f4ccc8482c06c5ce5dbb30f54
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: apinodeupdate.hxx,v $
10 * $Revision: 1.11 $
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_API_NODEUPDATE_HXX_
32 #define CONFIGMGR_API_NODEUPDATE_HXX_
34 #include "sal/config.h"
36 #include "boost/utility.hpp"
38 #include "apinodeaccess.hxx"
39 #include "utility.hxx"
41 namespace configmgr
43 namespace configuration
45 class GroupUpdater;
46 class GroupDefaulter;
47 class TreeSetUpdater;
48 class ValueSetUpdater;
49 class SetDefaulter;
50 class SetElementFactory;
52 class NodeUpdate;
54 namespace configapi
56 class SetElement;
58 // API object implementation wrappers
59 // these objects just provide the pieces needed to navigate and manipulate trees and nodes
61 // Updating access for Group Nodes
62 class NodeGroupAccess : public NodeGroupInfoAccess
64 public:
65 typedef configuration::GroupUpdater NodeUpdater;
66 typedef configuration::GroupDefaulter NodeDefaulter;
67 NodeUpdater getNodeUpdater();
68 NodeDefaulter getNodeDefaulter();
70 /** ensures that the default data for a group is loaded (if possible)
71 <p>Must be called outside of any locks !</p>
73 friend NodeGroupAccess& withDefaultData(NodeGroupAccess& aGroup);
76 // Updating access for Set Nodes
77 class NodeSetAccess : public NodeSetInfoAccess
79 public:
80 typedef struct SetUpdater_PlaceHolder NodeUpdater;
81 typedef configuration::SetDefaulter NodeDefaulter;
82 NodeDefaulter getNodeDefaulter();
85 // Updating access for Set Nodes containing whole trees
86 class NodeTreeSetAccess : public NodeSetAccess
88 public:
89 typedef configuration::TreeSetUpdater NodeUpdater;
90 NodeUpdater getNodeUpdater();
92 configuration::SetElementFactory getElementFactory();
95 // Updating access for Set Nodes containing simple values
96 class NodeValueSetAccess : public NodeSetAccess
98 public:
99 typedef configuration::ValueSetUpdater NodeUpdater;
100 NodeUpdater getNodeUpdater();
103 /// informs a <type>SetElement</type> that it should now link to the given SetElement
104 void attachSetElement(NodeTreeSetAccess& aSet, SetElement& aElement);
106 /// informs a <type>SetElement</type> that it should now link to the given SetElement
107 bool attachSetElement(NodeTreeSetAccess& aSet, rtl::Reference< configuration::ElementTree > const& aElementTree);
109 /// informs a <type>SetElement</type> that it should now unlink from its owning SetElement
110 void detachSetElement(SetElement& aElement);
112 /// informs a <type>SetElement</type> that it should now unlink from its owning SetElement
113 bool detachSetElement(Factory& rFactory, rtl::Reference< configuration::ElementTree > const& aElementTree);
115 /// Guarding and locking implementations
116 /// guards a NodeGroupAccess, or NodeSetAccess; provides an object (write)/provider(read) lock; ensures object was not disposed
117 class UpdateGuardImpl : private boost::noncopyable
119 NodeAccess& m_rNode;
120 public:
121 UpdateGuardImpl(NodeGroupAccess& rNode);
122 UpdateGuardImpl(NodeSetAccess& rNode);
123 ~UpdateGuardImpl() throw ();
124 public:
125 NodeAccess& get() const { return m_rNode; }
127 void downgrade() { }
130 // Thin Wrappers around NodeAccesses: Provide guarding and convenient access
131 /// wraps a NodeAccess; provides an object (write)/provider(read) lock, ensures object was not disposed
132 template <class Access>
133 class GuardedNodeUpdate
135 UnoApiLock m_aLock;
136 UpdateGuardImpl m_aImpl;
137 public:
138 GuardedNodeUpdate(Access& rNode) : m_aImpl(rNode) {}
139 public:
140 Access& get() const { return static_cast<Access&>(m_aImpl.get()); }
142 rtl::Reference< configuration::Tree > getTree() const;
143 configuration::NodeRef getNode() const;
145 typename Access::NodeUpdater getNodeUpdater() const;
146 typename Access::NodeDefaulter getNodeDefaulter() const;
148 void clearForBroadcast() { m_aImpl.downgrade(); }
151 template <class Access>
152 rtl::Reference< configuration::Tree > GuardedNodeUpdate<Access>::getTree() const
154 return get().getTree();
157 template <class Access>
158 configuration::NodeRef GuardedNodeUpdate<Access>::getNode() const
160 return get().getNodeRef();
163 template <class Access>
164 typename Access::NodeUpdater GuardedNodeUpdate<Access>::getNodeUpdater() const
166 return get().getNodeUpdater();
169 template <class Access>
170 typename Access::NodeDefaulter GuardedNodeUpdate<Access>::getNodeDefaulter() const
172 return get().getNodeDefaulter();
177 #endif // CONFIGMGR_API_NODEUPDATE_HXX_