LibreOffice Module basic (master) 1
image.hxx
Go to the documentation of this file.
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#pragma once
21
22#include <basic/sbx.hxx>
23#include <rtl/ustring.hxx>
24#include "filefmt.hxx"
26#include <cstddef>
27#include <vector>
28
29// This class reads in the image that's been produced by the compiler
30// and manages the access to the single elements.
31
32enum class SbiImageFlags
33{
34 NONE = 0,
35 EXPLICIT = 0x0001, // OPTION EXPLICIT is active
36 COMPARETEXT = 0x0002, // OPTION COMPARE TEXT is active
37 INITCODE = 0x0004, // Init-Code does exist
38 CLASSMODULE = 0x0008, // OPTION ClassModule is active
39};
40namespace o3tl
41{
42 template<> struct typed_flags<SbiImageFlags> : is_typed_flags<SbiImageFlags, 0xf> {};
43}
44
45class SbiImage {
46 friend class SbiCodeGen; // compiler classes, that the private-
47
48 SbxArrayRef rTypes; // User defined types
49 SbxArrayRef rEnums; // Enum types
50 std::vector<sal_uInt32> mvStringOffsets; // StringId-Offsets
51 std::unique_ptr<sal_Unicode[]> pStrings; // StringPool
52 std::vector<sal_uInt8> aCode; // Code-Image
53 std::vector<sal_uInt8> aLegacyPCode; // Code-Image
54 bool bError;
56 sal_uInt32 nStringSize;
57 sal_uInt16 nDimBase; // OPTION BASE value
58 rtl_TextEncoding eCharSet;
59 // temporary management-variable:
60 std::size_t nStringIdx;
61 sal_uInt32 nStringOff; // current Pos in the stringbuffer
62 // routines for the compiler:
63 void MakeStrings( short ); // establish StringPool
64 void AddString( const OUString& );
65 void AddCode(std::vector<sal_uInt8>&&);
66 void AddType(SbxObject const *);
67 void AddEnum(SbxObject *);
68
69public:
70 OUString aName; // macro name
71 OUString aOUSource; // source code
72 OUString aComment;
73 bool bInit;
75
76 SbiImage();
77 ~SbiImage();
78 void Clear();
79 bool Load( SvStream&, sal_uInt32& nVer );
80 // nVer is set to version
81 // of image
82 bool Save( SvStream&, sal_uInt32 );
83 bool IsError() const { return bError; }
84
85 const sal_uInt8* GetCode() const { return aCode.data(); }
86 sal_uInt32 GetCodeSize() const { return aCode.size(); }
87 sal_uInt16 GetBase() const { return nDimBase; }
88 OUString GetString( sal_uInt32 nId, SbxDataType *eType = nullptr ) const;
89 const SbxObject* FindType (const OUString& aTypeName) const;
90
91 const SbxArrayRef& GetEnums() const { return rEnums; }
92
93 void SetFlag( SbiImageFlags n ) { nFlags |= n; }
94 bool IsFlag( SbiImageFlags n ) const { return bool(nFlags & n); }
95 sal_uInt16 CalcLegacyOffset( sal_Int32 nOffset );
96 sal_uInt32 CalcNewOffset( sal_Int16 nOffset );
100};
101
102/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool Save(SvStream &, sal_uInt32)
Definition: image.cxx:374
const SbxArrayRef & GetEnums() const
Definition: image.hxx:91
bool bFirstInit
Definition: image.hxx:74
OUString GetString(sal_uInt32 nId, SbxDataType *eType=nullptr) const
Definition: image.cxx:618
const SbxObject * FindType(const OUString &aTypeName) const
Definition: image.cxx:665
const sal_uInt8 * GetCode() const
Definition: image.hxx:85
sal_uInt32 nStringOff
Definition: image.hxx:61
SbiImageFlags nFlags
Definition: image.hxx:55
~SbiImage()
Definition: image.cxx:47
sal_uInt16 GetBase() const
Definition: image.hxx:87
void SetFlag(SbiImageFlags n)
Definition: image.hxx:93
OUString aOUSource
Definition: image.hxx:71
sal_uInt16 CalcLegacyOffset(sal_Int32 nOffset)
Definition: image.cxx:670
void Clear()
Definition: image.cxx:51
std::vector< sal_uInt32 > mvStringOffsets
Definition: image.hxx:50
sal_uInt32 GetCodeSize() const
Definition: image.hxx:86
void AddEnum(SbxObject *)
Definition: image.cxx:608
void MakeStrings(short)
Definition: image.cxx:536
bool ExceedsImgVersion12Limits()
Definition: image.cxx:690
bool ExceedsLegacyLimits()
Definition: image.cxx:685
OUString aComment
Definition: image.hxx:72
sal_uInt32 nStringSize
Definition: image.hxx:56
void ReleaseLegacyBuffer()
Definition: image.cxx:680
sal_uInt32 CalcNewOffset(sal_Int16 nOffset)
Definition: image.cxx:675
OUString aName
Definition: image.hxx:70
SbxArrayRef rTypes
Definition: image.hxx:48
bool bInit
Definition: image.hxx:73
std::size_t nStringIdx
Definition: image.hxx:60
SbiImage()
Definition: image.cxx:34
bool Load(SvStream &, sal_uInt32 &nVer)
Definition: image.cxx:103
rtl_TextEncoding eCharSet
Definition: image.hxx:58
std::unique_ptr< sal_Unicode[]> pStrings
Definition: image.hxx:51
std::vector< sal_uInt8 > aLegacyPCode
Definition: image.hxx:53
void AddCode(std::vector< sal_uInt8 > &&)
Definition: image.cxx:592
bool bError
Definition: image.hxx:54
bool IsFlag(SbiImageFlags n) const
Definition: image.hxx:94
void AddString(const OUString &)
Definition: image.cxx:551
SbxArrayRef rEnums
Definition: image.hxx:49
std::vector< sal_uInt8 > aCode
Definition: image.hxx:52
void AddType(SbxObject const *)
Definition: image.cxx:598
sal_uInt16 nDimBase
Definition: image.hxx:57
bool IsError() const
Definition: image.hxx:83
SbiImageFlags
Definition: image.hxx:33
sal_Int64 n
NONE
SbxDataType
Definition: sbxdef.hxx:37
@ CLASSMODULE
Definition: token.hxx:81
unsigned char sal_uInt8