summaryrefslogtreecommitdiff
path: root/configmgr/source/inc/nodechange.hxx
blob: dfb630d88ddafc2dcc7ff758b0740909d9ab84dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: nodechange.hxx,v $
 * $Revision: 1.9 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef CONFIGMGR_CONFIGCHANGE_HXX_
#define CONFIGMGR_CONFIGCHANGE_HXX_

#include "rtl/ref.hxx"

#include "configexcept.hxx"

#include <vector>

namespace configmgr
{
    namespace configuration
    {
//-----------------------------------------------------------------------------
        class AbsolutePath;
        class RelativePath;
        class NodeRef;
        class NodeID;
        class SubNodeID;
        class Tree;
//-----------------------------------------------------------------------------

        class NodeChange;
        class NodeChangeImpl;
        class NodeChangeLocation;
        class NodeChangeInformation;
        class NodeChangesInformation;
//-----------------------------------------------------------------------------

        /// represents a node position in some tree
        class NodeChange
        {
        public:
            /// constructs an empty (unchanging) node change
            NodeChange();
            /// constructs a  node change with a given implementation
            NodeChange(NodeChangeImpl* pImpl);
            /// copies a node change with reference semantics
            NodeChange(NodeChange const& rOther);
            /// copies a node change with reference semantics
            NodeChange& operator=(NodeChange const& rOther);
            /// swaps the contents of this with another NodeChange
            void swap(NodeChange& rOther);
            /// destroys a node change
            ~NodeChange();

            /// checks, if this may represent an actual change (might not be tested)
            bool maybeChange() const;
            /// checks, if this represents an actual change (PRE: must be tested)
            bool isChange() const;
            /// retrieve information about the changed data, appending to a sequence, returning the count
            sal_uInt32 getChangeInfos(NodeChangesInformation& rInfo) const;
            /// retrieve information about what node is changed
            bool getChangeLocation(NodeChangeLocation& rLoc) const;

            /// test whether this would really be a change (as close as possible)
            NodeChange& test();
            NodeChange const& test() const;

            /// apply this change and check whether the target node changed
            NodeChange& apply();
            NodeChange const& apply() const;

            // retrieve the tree where the change is actually taking place
            rtl::Reference< Tree > getAffectedTree() const;
            // retrieve the node where the change is actually taking place
            NodeRef getAffectedNode() const;

            // Comparison
            friend bool operator==(NodeChange const& lhs, NodeChange const& rhs)
            {
                return lhs.m_pImpl == rhs.m_pImpl;
            }
            friend bool operator!=(NodeChange const& lhs, NodeChange const& rhs)
            {
                return lhs.m_pImpl != rhs.m_pImpl;
            }

            /// provides access to the internal Implementation for related classes
            NodeChangeImpl* impl() const { return m_pImpl; }
        private:
            NodeChangeImpl* m_pImpl;
            void init(), deinit();
        };

        /** represents a collection of updates to nodes (identified by <type>NodeChange</type>s) within a hierarchy of config entries
        */
        class NodeChanges
        {
        public:
            /// Constructs an empty collection of changes
            NodeChanges();

            /// checks whether there are any (non-empty) changes in this
            bool isEmpty() const;

            /// retrieves the total count of changes in this collection
            std::vector<NodeChange>::size_type getCount() const { return m_aChanges.size(); }

            /// retrieve information about the changed data, appending to a sequence, returning the count
            sal_uInt32 getChangesInfos(NodeChangesInformation& rInfos) const;

            /// test all changes
            NodeChanges& test()             { implTest(); return *this; }
            NodeChanges const& test() const { implTest(); return *this; }

            /// remove all changes known to be doing nothing from this collection.
            NodeChanges& compact();

            /** insert a change into this collection
            */
            void add(NodeChange const& aChange);

            /// returns an STL-style iterator to the first element of the collection
            std::vector<NodeChange>::const_iterator begin() const       { return m_aChanges.begin(); }
            std::vector<NodeChange>::iterator begin()   { return m_aChanges.begin(); }

            /// returns an STL-style iterator to past the last element of the collection
            std::vector<NodeChange>::const_iterator end() const { return m_aChanges.end(); }
            std::vector<NodeChange>::iterator end() { return m_aChanges.end(); }

        private:
            void implTest() const;
            std::vector<NodeChange> m_aChanges;
        };

    }
}

#endif // CONFIGMGR_CONFIGCHANGE_HXX_