Update ooo320-m1
[ooovba.git] / configmgr / source / inc / requesttypes.hxx
blob9fb6d8ac7e8baa944d1f77616e2f733177474d6a
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: requesttypes.hxx,v $
10 * $Revision: 1.10 $
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_BACKEND_REQUESTTYPES_HXX_
32 #define CONFIGMGR_BACKEND_REQUESTTYPES_HXX_
34 #include "sal/config.h"
36 #include "salhelper/simplereferenceobject.hxx"
38 #include "valuenode.hxx"
39 #include "treechangelist.hxx"
40 #include "configpath.hxx"
42 #ifndef _CONFIGMGR_UTILITY_HXX_
43 #include <utility.hxx>
44 #endif
46 #ifndef INCLUDED_MEMORY
47 #include <memory>
48 #define INCLUDED_MEMORY
49 #endif
51 namespace configmgr
53 // ---------------------------------------------------------------------------
54 namespace backend
56 // ---------------------------------------------------------------------------
57 struct ComponentDataStruct
59 const std::auto_ptr<ISubtree>& data;
60 rtl::OUString name;
61 ComponentDataStruct (const std::auto_ptr<ISubtree>& _data, rtl::OUString _name)
62 : data(_data), name(_name) {}
64 // ---------------------------------------------------------------------------
65 struct NodeInstance
67 typedef std::auto_ptr<ISubtree> Data;
69 explicit
70 NodeInstance(Data _node, configuration::AbsolutePath const & _rootpath)
71 : m_node(_node)
72 , m_root(_rootpath)
76 Data const & data() const { return m_node; }
77 configuration::AbsolutePath const & root() const { return m_root; }
79 Data & mutableData() { return m_node; }
80 Data extractData() { return m_node; }
81 private:
82 Data m_node;
83 configuration::AbsolutePath m_root;
85 // ---------------------------------------------------------------------------
86 struct TemplateInstance
88 typedef std::auto_ptr<INode> Data;
90 explicit
91 TemplateInstance(Data _node, rtl::OUString const & _name, rtl::OUString const & _component)
92 : m_node(_node)
93 , m_name(_name)
94 , m_component(_component)
98 Data const & data() const { return m_node; }
99 rtl::OUString const & name() const { return m_name; }
100 rtl::OUString const & component() const { return m_component; }
102 Data extractData() { return m_node; }
103 private:
104 Data m_node;
105 rtl::OUString m_name; // if empty, this is a complete set of component templates
106 rtl::OUString m_component;
108 // ---------------------------------------------------------------------------
109 struct ComponentInstance
111 typedef std::auto_ptr<ISubtree> Data;
113 explicit
114 ComponentInstance(Data _node, Data _template, rtl::OUString const & _component)
115 : m_node(_node)
116 , m_template(_template)
117 , m_component(_component)
121 Data const & data() const { return m_node; }
122 Data const & templateData() const { return m_template; }
123 rtl::OUString const & component() const { return m_component; }
125 ComponentDataStruct componentTemplateData () const { return ComponentDataStruct(m_template,m_component);}
126 ComponentDataStruct componentNodeData () const { return ComponentDataStruct(m_node,m_component);}
127 Data & mutableData() { return m_node; }
128 Data extractData() { return m_node; }
129 Data extractTemplateData() { return m_template; }
130 private:
131 Data m_node;
132 Data m_template;
133 rtl::OUString m_component;
135 // ---------------------------------------------------------------------------
136 struct UpdateInstance
138 typedef SubtreeChange * Data;
140 explicit
141 UpdateInstance(Data _update, configuration::AbsolutePath const & _rootpath)
142 : m_update(_update)
143 , m_root(_rootpath)
147 UpdateInstance(UpdateInstance & _aModifiableOther)
148 : m_update(_aModifiableOther.m_update)
149 , m_root(_aModifiableOther.m_root)
153 Data data() { return m_update; }
154 SubtreeChange const * data() const { return m_update; }
155 configuration::AbsolutePath const & root() const { return m_root; }
156 private:
157 Data m_update;
158 configuration::AbsolutePath m_root;
160 // ---------------------------------------------------------------------------
161 struct ConstUpdateInstance
163 typedef SubtreeChange const * Data;
165 explicit
166 ConstUpdateInstance(Data _update, configuration::AbsolutePath const & _rootpath)
167 : m_update(_update)
168 , m_root(_rootpath)
172 // conversion
173 ConstUpdateInstance(UpdateInstance const & _aModifiable)
174 : m_update(_aModifiable.data())
175 , m_root(_aModifiable.root())
179 Data data() const { return m_update; }
180 configuration::AbsolutePath const & root() const { return m_root; }
181 private:
182 Data m_update;
183 configuration::AbsolutePath m_root;
185 // ---------------------------------------------------------------------------
186 // ---------------------------------------------------------------------------
187 // Due to the use of auto_ptr, the XxxInstance classes cannot easily be used as return values
188 // To return them, they should be wrapped into a ResultHolder
190 template <class Instance_>
191 class ResultHolder
193 struct RCInstance : public salhelper::SimpleReferenceObject
195 RCInstance(Instance_ & _instance)
196 : instance(_instance) {}
197 Instance_ instance;
200 rtl::Reference< RCInstance > m_xInstance;
201 public:
202 explicit
203 ResultHolder(Instance_ & _rInstance)
204 : m_xInstance( new RCInstance(_rInstance) )
207 bool isEmpty() const { return !m_xInstance.is(); }
209 bool is() const { return m_xInstance.is() && m_xInstance->instance.data().get(); }
211 Instance_ const & instance() const { return m_xInstance->instance; }
213 Instance_ const & operator *() const { return instance(); }
214 Instance_ const * operator->() const { return &instance(); }
215 Instance_ & mutableInstance() { return m_xInstance->instance; }
217 typename Instance_::Data extractDataAndClear()
219 typename Instance_::Data aData = m_xInstance->instance.extractData();
220 this->clear();
221 return aData;
224 void releaseAndClear()
226 typename Instance_::Data aData = this->extractDataAndClear();
227 aData.release();
230 void clear() { m_xInstance.clear(); }
232 // ---------------------------------------------------------------------------
234 // ---------------------------------------------------------------------------
235 } // namespace
237 #endif