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: OutputWithDepth.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 INCLUDED_OUTPUT_WITH_DEPTH
32 #define INCLUDED_OUTPUT_WITH_DEPTH
37 namespace writerfilter
40 using namespace ::std
;
45 typedef ::std::vector
<T
> Group_t
;
48 unsigned int mnCurrentDepth
;
49 unsigned int mnGroupDepth
;
55 virtual void output(const T
& aItem
) const = 0;
60 OutputWithDepth(const T
& aOpenTag
, const T
& aCloseTag
);
61 virtual ~OutputWithDepth();
65 void addItem(const T
& aItem
);
66 void setDepth(unsigned int nDepth
);
70 OutputWithDepth
<T
>::OutputWithDepth(const T
& aOpenTag
, const T
& aEndTag
)
71 : mOpenTag(aOpenTag
), mCloseTag(aEndTag
)
76 OutputWithDepth
<T
>::~OutputWithDepth()
81 void OutputWithDepth
<T
>::finalize()
87 void OutputWithDepth
<T
>::openGroup()
94 void OutputWithDepth
<T
>::closeGroup()
96 if (mnGroupDepth
> mnCurrentDepth
)
97 for (unsigned int i
= 0; i
< mnGroupDepth
- mnCurrentDepth
; ++i
)
99 else if (mnGroupDepth
< mnCurrentDepth
)
100 for (unsigned int i
= 0; i
< mnCurrentDepth
- mnGroupDepth
; ++i
)
105 mnCurrentDepth
= mnGroupDepth
;
108 template <typename T
>
109 void OutputWithDepth
<T
>::addItem(const T
& aItem
)
111 mGroup
.push_back(aItem
);
114 template <typename T
>
115 void OutputWithDepth
<T
>::setDepth(unsigned int nDepth
)
117 mnGroupDepth
= nDepth
;
120 template <typename T
>
121 void OutputWithDepth
<T
>::outputGroup()
123 typename
Group_t::iterator aItEnd
= mGroup
.end();
125 for (typename
Group_t::iterator aIt
= mGroup
.begin(); aIt
!= aItEnd
; aIt
++)
133 #endif // INCLUDED_OUTPUT_WITH_DEPTH