bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / filter / ww8 / WW8Sttbf.hxx
blobb7187546d0fa2432b00771e7d71c56a0242870fb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #include <vector>
21 #include <boost/shared_ptr.hpp>
22 #include <boost/shared_array.hpp>
23 #include <tools/solar.h>
24 #include <rtl/ustring.hxx>
25 #include <tools/stream.hxx>
26 #include <IDocumentExternalData.hxx>
28 namespace ww8
30 typedef boost::shared_array<sal_uInt8> DataArray_t;
32 class WW8Struct : public ::sw::ExternalData
34 DataArray_t mp_data;
35 sal_uInt32 mn_offset;
36 sal_uInt32 mn_size;
38 public:
39 WW8Struct(SvStream& rSt, sal_uInt32 nPos, sal_uInt32 nSize);
40 WW8Struct(WW8Struct * pStruct, sal_uInt32 nPos, sal_uInt32 nSize);
41 virtual ~WW8Struct();
43 sal_uInt8 getU8(sal_uInt32 nOffset);
45 sal_uInt16 getU16(sal_uInt32 nOffset)
46 { return getU8(nOffset) + (getU8(nOffset + 1) << 8); }
48 sal_uInt32 getU32(sal_uInt32 nOffset)
49 { return getU16(nOffset) + (getU16(nOffset + 1) << 16); }
51 OUString getUString(sal_uInt32 nOffset, sal_uInt32 nCount);
53 OUString getString(sal_uInt32 nOffset, sal_uInt32 nCount);
56 typedef ::std::vector<OUString> StringVector_t;
57 template <class T>
58 class WW8Sttb : public WW8Struct
60 typedef ::boost::shared_ptr< void > ExtraPointer_t;
61 typedef ::std::vector< ExtraPointer_t > ExtrasVector_t;
62 bool bDoubleByteCharacters;
63 StringVector_t m_Strings;
64 ExtrasVector_t m_Extras;
66 public:
67 WW8Sttb(SvStream& rSt, sal_Int32 nPos, sal_uInt32 nSize);
68 virtual ~WW8Sttb();
70 sal_uInt32 getCount() const;
71 OUString getEntry(sal_uInt32 nEntry) const
73 return m_Strings[nEntry];
76 StringVector_t & getStrings()
78 return m_Strings;
81 const T * getExtra(sal_uInt32 nEntry) const
83 return dynamic_cast<const T *> (m_Extras[nEntry].get());
87 template <class T>
88 WW8Sttb<T>::WW8Sttb(SvStream& rSt, sal_Int32 nPos, sal_uInt32 nSize)
89 : WW8Struct(rSt, nPos, nSize), bDoubleByteCharacters(false)
91 sal_uInt32 nOffset = 0;
93 if (getU16(nOffset) == 0xffff)
95 bDoubleByteCharacters = true;
96 nOffset += 2;
99 sal_uInt16 nCount = getU16(nOffset);
100 sal_uInt16 ncbExtra = getU16(nOffset + 2);
102 nOffset += 4;
103 for (sal_uInt16 i = 0; i < nCount; i++)
105 if (bDoubleByteCharacters)
107 sal_uInt16 nStrLen = getU16(nOffset);
109 m_Strings.push_back(getUString(nOffset +2, nStrLen));
111 nOffset += 2 + 2 * nStrLen;
113 else
115 sal_uInt8 nStrLen = getU8(nOffset);
117 m_Strings.push_back(getUString(nOffset, nStrLen));
119 nOffset += 1 + nStrLen;
122 if (ncbExtra > 0)
124 ExtraPointer_t pExtra(new T(this, nOffset, ncbExtra));
125 m_Extras.push_back(pExtra);
127 nOffset += ncbExtra;
132 template <class T>
133 WW8Sttb<T>::~WW8Sttb()
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */