1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: requesttypes.hxx,v $
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>
46 #ifndef INCLUDED_MEMORY
48 #define INCLUDED_MEMORY
53 // ---------------------------------------------------------------------------
56 // ---------------------------------------------------------------------------
57 struct ComponentDataStruct
59 const std::auto_ptr
<ISubtree
>& data
;
61 ComponentDataStruct (const std::auto_ptr
<ISubtree
>& _data
, rtl::OUString _name
)
62 : data(_data
), name(_name
) {}
64 // ---------------------------------------------------------------------------
67 typedef std::auto_ptr
<ISubtree
> Data
;
70 NodeInstance(Data _node
, configuration::AbsolutePath
const & _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
; }
83 configuration::AbsolutePath m_root
;
85 // ---------------------------------------------------------------------------
86 struct TemplateInstance
88 typedef std::auto_ptr
<INode
> Data
;
91 TemplateInstance(Data _node
, rtl::OUString
const & _name
, rtl::OUString
const & _component
)
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
; }
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
;
114 ComponentInstance(Data _node
, Data _template
, rtl::OUString
const & _component
)
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
; }
133 rtl::OUString m_component
;
135 // ---------------------------------------------------------------------------
136 struct UpdateInstance
138 typedef SubtreeChange
* Data
;
141 UpdateInstance(Data _update
, configuration::AbsolutePath
const & _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
; }
158 configuration::AbsolutePath m_root
;
160 // ---------------------------------------------------------------------------
161 struct ConstUpdateInstance
163 typedef SubtreeChange
const * Data
;
166 ConstUpdateInstance(Data _update
, configuration::AbsolutePath
const & _rootpath
)
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
; }
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_
>
193 struct RCInstance
: public salhelper::SimpleReferenceObject
195 RCInstance(Instance_
& _instance
)
196 : instance(_instance
) {}
200 rtl::Reference
< RCInstance
> m_xInstance
;
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();
224 void releaseAndClear()
226 typename
Instance_::Data aData
= this->extractDataAndClear();
230 void clear() { m_xInstance
.clear(); }
232 // ---------------------------------------------------------------------------
234 // ---------------------------------------------------------------------------