1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SUB_SEQUENCE_HXX
21 #define INCLUDED_SUB_SEQUENCE_HXX
23 #include <com/sun/star/uno/Sequence.hxx>
25 #include <boost/shared_ptr.hpp>
29 #include "exceptions.hxx"
30 #include <WriterFilterDllApi.hxx>
31 #include <resourcemodel/OutputWithDepth.hxx>
33 namespace writerfilter
{
34 using namespace ::std
;
40 void dumpLine(OutputWithDepth
<string
> & o
, SubSequence
<T
> & rSeq
,
41 sal_uInt32 nOffset
, sal_uInt32 nStep
);
46 typedef boost::shared_ptr
<com::sun::star::uno::Sequence
<T
> >
49 SequencePointer mpSequence
;
54 typedef boost::shared_ptr
<SubSequence
> Pointer_t
;
56 SubSequence() : mpSequence(new ::com::sun::star::uno::Sequence
<T
>()),
57 mnOffset(0), mnCount(0)
61 SubSequence(SequencePointer pSequence
, sal_uInt32 nOffset_
,
63 : mpSequence(pSequence
), mnOffset(nOffset_
), mnCount(nCount_
)
67 SubSequence(SequencePointer pSequence
)
68 : mpSequence(pSequence
), mnOffset(0), mnCount(pSequence
->getLength())
72 SubSequence(const SubSequence
& rSubSequence
, sal_uInt32 nOffset_
,
74 : mpSequence(rSubSequence
.mpSequence
),
75 mnOffset(rSubSequence
.mnOffset
+ nOffset_
),
80 SubSequence(const T
* pStart
, sal_uInt32 nCount_
)
81 : mpSequence(new com::sun::star::uno::Sequence
<T
>(pStart
, nCount_
)),
82 mnOffset(0), mnCount(nCount_
)
86 SubSequence(sal_Int32 nCount_
)
87 : mpSequence(new com::sun::star::uno::Sequence
<T
>(nCount_
)), mnOffset(0),
92 ::com::sun::star::uno::Sequence
<T
> & getSequence()
97 const ::com::sun::star::uno::Sequence
<T
> & getSequence() const
104 mnCount
= mpSequence
->getLength();
107 sal_uInt32
getOffset() const { return mnOffset
; }
108 sal_uInt32
getCount() const { return mnCount
; }
110 const T
& operator[] (sal_uInt32 nIndex
) const
112 if (mnOffset
+ nIndex
>=
113 sal::static_int_cast
<sal_uInt32
>(mpSequence
->getLength()))
114 throw ExceptionOutOfBounds("SubSequence::operator[]");
116 return (*mpSequence
)[mnOffset
+ nIndex
];
119 void dump(ostream
& o
) const
124 snprintf(sBuffer
, sizeof(sBuffer
),
125 "<sequence id='%p' offset='%lx' count='%lx'>",
126 mpSequence
.get(), mnOffset
, mnCount
);
127 o
<< sBuffer
<< endl
;
131 sal_uInt32 nStep
= 16;
133 while (n
< getCount())
139 snprintf(sBuffer
, 255, "%08lx: ", static_cast<unsigned long>(n
));
143 for (sal_uInt32 i
= 0; i
< nStep
; i
++)
145 if (n
+ i
< getCount())
147 snprintf(sBuffer
, 255, "%02x ", operator[](n
+ i
));
158 for (sal_uInt32 i
= 0; i
< nStep
; i
++)
160 if (n
+ i
< getCount())
163 static_cast<unsigned char>(operator[](n
+ i
));
171 else if (c
< 128 && isprint(c
))
180 o
<< "</line>" << endl
;
185 o
<< "</sequence>" << endl
;
188 void dump(OutputWithDepth
<string
> & o
)
193 snprintf(sBuffer
, sizeof(sBuffer
),
194 "<sequence id='%p' offset='%" SAL_PRIxUINT32
"' count='%" SAL_PRIxUINT32
"'>",
195 mpSequence
.get(), mnOffset
, mnCount
);
200 sal_uInt32 nStep
= 16;
204 sal_uInt32 nCount
= getCount();
207 sal_uInt32 nBytes
= nCount
- n
;
212 SubSequence
<T
> aSeq(*this, n
, nBytes
);
213 dumpLine(o
, aSeq
, n
, nStep
);
220 o
.addItem("<exception/>");
223 o
.addItem("</sequence>");
226 string
toString() const
229 sal_uInt32 nStep
= 16;
233 while (n
< getCount())
237 snprintf(sBuffer
, 255, "<line>%08" SAL_PRIxUINT32
": ", n
);
241 for (sal_uInt32 i
= 0; i
< nStep
; i
++)
243 if (n
+ i
< getCount())
245 snprintf(sBuffer
, 255, "%02x ", operator[](n
+ i
));
256 for (sal_uInt32 i
= 0; i
< nStep
; i
++)
258 if (n
+ i
< getCount())
261 static_cast<unsigned char>(operator[](n
+ i
));
269 else if (c
< 128 && isprint(c
))
277 sResult
+= "</line>\n";
286 template <typename T
>
287 void dumpLine(OutputWithDepth
<string
> & o
, SubSequence
<T
> & rSeq
,
288 sal_uInt32 nOffset
, sal_uInt32 nStep
)
290 sal_uInt32 nCount
= rSeq
.getCount();
293 string tmpStr
= "<line>";
295 snprintf(sBuffer
, 255, "%08" SAL_PRIxUINT32
": ", nOffset
);
299 for (sal_uInt32 i
= 0; i
< nStep
; i
++)
303 snprintf(sBuffer
, 255, "%02x ", rSeq
[i
]);
314 for (sal_uInt32 i
= 0; i
< nStep
; i
++)
319 static_cast<unsigned char>(rSeq
[i
]);
327 else if (c
< 128 && isprint(c
))
343 #endif // INCLUDED_SUB_SEQUENCE_HXX
345 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */