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: SubSequence.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_SUB_SEQUENCE_HXX
32 #define INCLUDED_SUB_SEQUENCE_HXX
34 #include <com/sun/star/uno/Sequence.hxx>
36 #include <boost/shared_ptr.hpp>
40 #include "exceptions.hxx"
41 #include <WriterFilterDllApi.hxx>
42 #include <resourcemodel/OutputWithDepth.hxx>
44 namespace writerfilter
{
45 using namespace ::std
;
51 void dumpLine(OutputWithDepth
<string
> & o
, SubSequence
<T
> & rSeq
,
52 sal_uInt32 nOffset
, sal_uInt32 nStep
);
55 class WRITERFILTER_DLLPUBLIC SubSequence
57 typedef boost::shared_ptr
<com::sun::star::uno::Sequence
<T
> >
60 SequencePointer mpSequence
;
65 typedef boost::shared_ptr
<SubSequence
> Pointer_t
;
67 SubSequence() : mpSequence(new ::com::sun::star::uno::Sequence
<T
>()),
68 mnOffset(0), mnCount(0)
72 SubSequence(SequencePointer pSequence
, sal_uInt32 nOffset_
,
74 : mpSequence(pSequence
), mnOffset(nOffset_
), mnCount(nCount_
)
78 SubSequence(SequencePointer pSequence
)
79 : mpSequence(pSequence
), mnOffset(0), mnCount(pSequence
->getLength())
83 SubSequence(const SubSequence
& rSubSequence
, sal_uInt32 nOffset_
,
85 : mpSequence(rSubSequence
.mpSequence
),
86 mnOffset(rSubSequence
.mnOffset
+ nOffset_
),
91 SubSequence(const T
* pStart
, sal_uInt32 nCount_
)
92 : mpSequence(new com::sun::star::uno::Sequence
<T
>(pStart
, nCount_
)),
93 mnOffset(0), mnCount(nCount_
)
97 SubSequence(sal_Int32 nCount_
)
98 : mpSequence(new com::sun::star::uno::Sequence
<T
>(nCount_
)), mnOffset(0),
103 ::com::sun::star::uno::Sequence
<T
> & getSequence()
108 const ::com::sun::star::uno::Sequence
<T
> & getSequence() const
115 mnCount
= mpSequence
->getLength();
118 sal_uInt32
getOffset() const { return mnOffset
; }
119 sal_uInt32
getCount() const { return mnCount
; }
121 const T
& operator[] (sal_uInt32 nIndex
) const
123 if (mnOffset
+ nIndex
>=
124 sal::static_int_cast
<sal_uInt32
>(mpSequence
->getLength()))
125 throw ExceptionOutOfBounds("SubSequence::operator[]");
127 return (*mpSequence
)[mnOffset
+ nIndex
];
130 void dump(ostream
& o
) const
135 snprintf(sBuffer
, sizeof(sBuffer
),
136 "<sequence id='%p' offset='%lx' count='%lx'>",
137 mpSequence
.get(), mnOffset
, mnCount
);
138 o
<< sBuffer
<< endl
;
142 sal_uInt32 nStep
= 16;
144 while (n
< getCount())
150 snprintf(sBuffer
, 255, "%08lx: ", n
);
154 for (sal_uInt32 i
= 0; i
< nStep
; i
++)
156 if (n
+ i
< getCount())
158 snprintf(sBuffer
, 255, "%02x ", operator[](n
+ i
));
169 for (sal_uInt32 i
= 0; i
< nStep
; i
++)
171 if (n
+ i
< getCount())
174 static_cast<unsigned char>(operator[](n
+ i
));
182 else if (c
< 128 && isprint(c
))
191 o
<< "</line>" << endl
;
196 o
<< "</sequence>" << endl
;
199 void dump(OutputWithDepth
<string
> & o
)
204 snprintf(sBuffer
, sizeof(sBuffer
),
205 "<sequence id='%p' offset='%" SAL_PRIxUINT32
"' count='%" SAL_PRIxUINT32
"'>",
206 mpSequence
.get(), mnOffset
, mnCount
);
211 sal_uInt32 nStep
= 16;
215 sal_uInt32 nCount
= getCount();
218 sal_uInt32 nBytes
= nCount
- n
;
223 SubSequence
<T
> aSeq(*this, n
, nBytes
);
224 dumpLine(o
, aSeq
, n
, nStep
);
231 o
.addItem("<exception/>");
234 o
.addItem("</sequence>");
237 string
toString() const
240 sal_uInt32 nStep
= 16;
244 while (n
< getCount())
248 snprintf(sBuffer
, 255, "<line>%08" SAL_PRIxUINT32
": ", n
);
252 for (sal_uInt32 i
= 0; i
< nStep
; i
++)
254 if (n
+ i
< getCount())
256 snprintf(sBuffer
, 255, "%02x ", operator[](n
+ i
));
267 for (sal_uInt32 i
= 0; i
< nStep
; i
++)
269 if (n
+ i
< getCount())
272 static_cast<unsigned char>(operator[](n
+ i
));
280 else if (c
< 128 && isprint(c
))
288 sResult
+= "</line>\n";
297 template <typename T
>
298 void dumpLine(OutputWithDepth
<string
> & o
, SubSequence
<T
> & rSeq
,
299 sal_uInt32 nOffset
, sal_uInt32 nStep
)
301 sal_uInt32 nCount
= rSeq
.getCount();
304 string tmpStr
= "<line>";
306 snprintf(sBuffer
, 255, "%08" SAL_PRIxUINT32
": ", nOffset
);
310 for (sal_uInt32 i
= 0; i
< nStep
; i
++)
314 snprintf(sBuffer
, 255, "%02x ", rSeq
[i
]);
325 for (sal_uInt32 i
= 0; i
< nStep
; i
++)
330 static_cast<unsigned char>(rSeq
[i
]);
338 else if (c
< 128 && isprint(c
))
354 #endif // INCLUDED_SUB_SEQUENCE_HXX