LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/writerfilter/inc/resourcemodel - SubSequence.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 93 0.0 %
Date: 2013-07-09 Functions: 0 15 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_SUB_SEQUENCE_HXX
      21             : #define INCLUDED_SUB_SEQUENCE_HXX
      22             : 
      23             : #include <com/sun/star/uno/Sequence.hxx>
      24             : 
      25             : #include <boost/shared_ptr.hpp>
      26             : #include <iostream>
      27             : #include <stdio.h>
      28             : #include <ctype.h>
      29             : #include "exceptions.hxx"
      30             : #include <WriterFilterDllApi.hxx>
      31             : #include <resourcemodel/OutputWithDepth.hxx>
      32             : 
      33             : namespace writerfilter {
      34             : using namespace ::std;
      35             : 
      36             : template <class T>
      37             : class SubSequence;
      38             : 
      39             : template <typename T>
      40             : void dumpLine(OutputWithDepth<string> & o, SubSequence<T> & rSeq,
      41             :               sal_uInt32 nOffset, sal_uInt32 nStep);
      42             : 
      43             : template <class T>
      44           0 : class SubSequence
      45             : {
      46             :     typedef boost::shared_ptr<com::sun::star::uno::Sequence<T> >
      47             :     SequencePointer;
      48             : 
      49             :     SequencePointer mpSequence;
      50             :     sal_uInt32 mnOffset;
      51             :     sal_uInt32 mnCount;
      52             : 
      53             : public:
      54             :     typedef boost::shared_ptr<SubSequence> Pointer_t;
      55             : 
      56           0 :     SubSequence() : mpSequence(new ::com::sun::star::uno::Sequence<T>()),
      57           0 :                     mnOffset(0), mnCount(0)
      58             :     {
      59           0 :     }
      60             : 
      61             :     SubSequence(SequencePointer pSequence, sal_uInt32 nOffset_,
      62             :                 sal_uInt32 nCount_)
      63             :         : mpSequence(pSequence), mnOffset(nOffset_), mnCount(nCount_)
      64             :     {
      65             :     }
      66             : 
      67             :     SubSequence(SequencePointer pSequence)
      68             :         : mpSequence(pSequence), mnOffset(0), mnCount(pSequence->getLength())
      69             :     {
      70             :     }
      71             : 
      72           0 :     SubSequence(const SubSequence & rSubSequence, sal_uInt32 nOffset_,
      73             :                 sal_uInt32 nCount_)
      74             :         : mpSequence(rSubSequence.mpSequence),
      75             :           mnOffset(rSubSequence.mnOffset + nOffset_),
      76           0 :           mnCount(nCount_)
      77             :     {
      78           0 :     }
      79             : 
      80           0 :     SubSequence(const T * pStart, sal_uInt32 nCount_)
      81             :         : mpSequence(new com::sun::star::uno::Sequence<T>(pStart, nCount_)),
      82           0 :           mnOffset(0), mnCount(nCount_)
      83             :     {
      84           0 :     }
      85             : 
      86             :     SubSequence(sal_Int32 nCount_)
      87             :         : mpSequence(new com::sun::star::uno::Sequence<T>(nCount_)), mnOffset(0),
      88             :           mnCount(nCount_)
      89             :     {
      90             :     }
      91             : 
      92           0 :     ::com::sun::star::uno::Sequence<T> & getSequence()
      93             :     {
      94           0 :         return *mpSequence;
      95             :     }
      96             : 
      97             :     const ::com::sun::star::uno::Sequence<T> & getSequence() const
      98             :     {
      99             :         return *mpSequence;
     100             :     }
     101             : 
     102             :     void reset() {
     103             :         mnOffset = 0;
     104             :         mnCount = mpSequence->getLength();
     105             :     }
     106             : 
     107           0 :     sal_uInt32 getOffset() const { return mnOffset; }
     108           0 :     sal_uInt32 getCount() const { return mnCount; }
     109             : 
     110           0 :     const T & operator[] (sal_uInt32 nIndex) const
     111             :     {
     112           0 :         if (mnOffset + nIndex >=
     113           0 :             sal::static_int_cast<sal_uInt32>(mpSequence->getLength()))
     114           0 :             throw ExceptionOutOfBounds("SubSequence::operator[]");
     115             : 
     116           0 :         return (*mpSequence)[mnOffset + nIndex];
     117             :     }
     118             : 
     119             :     void dump(ostream & o) const
     120             :     {
     121             :         {
     122             :             char sBuffer[256];
     123             : 
     124             :             snprintf(sBuffer, sizeof(sBuffer),
     125             :                      "<sequence id='%p' offset='%lx' count='%lx'>",
     126             :                      mpSequence.get(), mnOffset, mnCount);
     127             :             o << sBuffer << endl;
     128             :         }
     129             : 
     130             :         sal_uInt32 n = 0;
     131             :         sal_uInt32 nStep = 16;
     132             : 
     133             :         while (n < getCount())
     134             :         {
     135             :             char sBuffer[256];
     136             : 
     137             :             o << "<line>";
     138             : 
     139             :             snprintf(sBuffer, 255, "%08lx: ", static_cast<unsigned long>(n));
     140             : 
     141             :             o << sBuffer;
     142             : 
     143             :             for (sal_uInt32 i = 0; i < nStep; i++)
     144             :             {
     145             :                 if (n + i < getCount())
     146             :                 {
     147             :                     snprintf(sBuffer, 255, "%02x ", operator[](n + i));
     148             :                     o << sBuffer;
     149             :                 }
     150             :                 else
     151             :                     o << "   ";
     152             : 
     153             :                 if (i % 8 == 7)
     154             :                     o << " ";
     155             :             }
     156             : 
     157             :             {
     158             :                 for (sal_uInt32 i = 0; i < nStep; i++)
     159             :                 {
     160             :                     if (n + i < getCount())
     161             :                     {
     162             :                         unsigned char c =
     163             :                             static_cast<unsigned char>(operator[](n + i));
     164             : 
     165             :                         if (c=='&')
     166             :                             o << "&amp;";
     167             :                         else if (c=='<')
     168             :                             o << "&lt;";
     169             :                         else if (c=='>')
     170             :                             o << "&gt;";
     171             :                         else if (c < 128 && isprint(c))
     172             :                             o << c;
     173             :                         else
     174             :                             o << ".";
     175             :                     }
     176             : 
     177             :                 }
     178             :             }
     179             : 
     180             :             o << "</line>" << endl;
     181             : 
     182             :             n += nStep;
     183             :         }
     184             : 
     185             :         o << "</sequence>" << endl;
     186             :     }
     187             : 
     188           0 :     void dump(OutputWithDepth<string> & o)
     189             :     {
     190             :         {
     191             :             char sBuffer[256];
     192             : 
     193           0 :             snprintf(sBuffer, sizeof(sBuffer),
     194             :                      "<sequence id='%p' offset='%" SAL_PRIxUINT32 "' count='%" SAL_PRIxUINT32 "'>",
     195           0 :                      mpSequence.get(), mnOffset, mnCount);
     196           0 :             o.addItem(sBuffer);
     197             :         }
     198             : 
     199           0 :         sal_uInt32 n = 0;
     200           0 :         sal_uInt32 nStep = 16;
     201             : 
     202             :         try
     203             :         {
     204           0 :             sal_uInt32 nCount = getCount();
     205           0 :             while (n < nCount)
     206             :             {
     207           0 :                 sal_uInt32 nBytes = nCount - n;
     208             : 
     209           0 :                 if (nBytes > nStep)
     210           0 :                     nBytes = nStep;
     211             : 
     212           0 :                 SubSequence<T> aSeq(*this, n, nBytes);
     213           0 :                 dumpLine(o, aSeq, n, nStep);
     214             : 
     215           0 :                 n += nBytes;
     216             :             }
     217             :         }
     218           0 :         catch (...)
     219             :         {
     220           0 :             o.addItem("<exception/>");
     221             :         }
     222             : 
     223           0 :         o.addItem("</sequence>");
     224           0 :     }
     225             : 
     226           0 :     string toString() const
     227             :     {
     228           0 :         sal_uInt32 n = 0;
     229           0 :         sal_uInt32 nStep = 16;
     230             : 
     231           0 :         string sResult;
     232             : 
     233           0 :         while (n < getCount())
     234             :         {
     235             :             char sBuffer[256];
     236             : 
     237           0 :             snprintf(sBuffer, 255, "<line>%08" SAL_PRIxUINT32 ": ", n);
     238             : 
     239           0 :             sResult += sBuffer;
     240             : 
     241           0 :             for (sal_uInt32 i = 0; i < nStep; i++)
     242             :             {
     243           0 :                 if (n + i < getCount())
     244             :                 {
     245           0 :                     snprintf(sBuffer, 255, "%02x ", operator[](n + i));
     246           0 :                     sResult += sBuffer;
     247             :                 }
     248             :                 else
     249           0 :                     sResult += "   ";
     250             : 
     251           0 :                 if (i % 8 == 7)
     252           0 :                     sResult += " ";
     253             :             }
     254             : 
     255             :             {
     256           0 :                 for (sal_uInt32 i = 0; i < nStep; i++)
     257             :                 {
     258           0 :                     if (n + i < getCount())
     259             :                     {
     260             :                         unsigned char c =
     261           0 :                             static_cast<unsigned char>(operator[](n + i));
     262             : 
     263           0 :                         if (c=='&')
     264           0 :                             sResult += "&amp;";
     265           0 :                         else if (c=='<')
     266           0 :                             sResult += "&lt;";
     267           0 :                         else if (c=='>')
     268           0 :                             sResult += "&gt;";
     269           0 :                         else if (c < 128 && isprint(c))
     270           0 :                             sResult += c;
     271             :                         else
     272           0 :                             sResult += ".";
     273             :                     }
     274             :                 }
     275             :             }
     276             : 
     277           0 :             sResult += "</line>\n";
     278             : 
     279           0 :             n += nStep;
     280             :         }
     281             : 
     282           0 :         return sResult;
     283             :     }
     284             : };
     285             : 
     286             : template <typename T>
     287           0 : void dumpLine(OutputWithDepth<string> & o, SubSequence<T> & rSeq,
     288             :               sal_uInt32 nOffset, sal_uInt32 nStep)
     289             : {
     290           0 :     sal_uInt32 nCount = rSeq.getCount();
     291             :     char sBuffer[256];
     292             : 
     293           0 :     string tmpStr = "<line>";
     294             : 
     295           0 :     snprintf(sBuffer, 255, "%08" SAL_PRIxUINT32 ": ", nOffset);
     296             : 
     297           0 :     tmpStr += sBuffer;
     298             : 
     299           0 :     for (sal_uInt32 i = 0; i < nStep; i++)
     300             :     {
     301           0 :         if (i < nCount)
     302             :         {
     303           0 :             snprintf(sBuffer, 255, "%02x ", rSeq[i]);
     304           0 :             tmpStr += sBuffer;
     305             :         }
     306             :         else
     307           0 :             tmpStr += "   ";
     308             : 
     309           0 :         if (i % 8 == 7)
     310           0 :             tmpStr += " ";
     311             :     }
     312             : 
     313             :     {
     314           0 :         for (sal_uInt32 i = 0; i < nStep; i++)
     315             :         {
     316           0 :             if (i < nCount)
     317             :             {
     318             :                 unsigned char c =
     319           0 :                     static_cast<unsigned char>(rSeq[i]);
     320             : 
     321           0 :                 if (c=='&')
     322           0 :                     tmpStr += "&amp;";
     323           0 :                 else if (c=='<')
     324           0 :                     tmpStr += "&lt;";
     325           0 :                 else if (c=='>')
     326           0 :                     tmpStr += "&gt;";
     327           0 :                 else if (c < 128 && isprint(c))
     328           0 :                     tmpStr += c;
     329             :                 else
     330           0 :                     tmpStr += ".";
     331             :             }
     332             : 
     333             :         }
     334             :     }
     335             : 
     336           0 :     tmpStr += "</line>";
     337             : 
     338           0 :     o.addItem(tmpStr);
     339           0 : }
     340             : 
     341             : }
     342             : 
     343             : #endif // INCLUDED_SUB_SEQUENCE_HXX
     344             : 
     345             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10