Coverage Report

Created: 2026-03-12 06:42

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libwps/src/lib/QuattroFormula.h
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2
/* libwps
3
 * Version: MPL 2.0 / LGPLv2.1+
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
 * Major Contributor(s):
10
 * Copyright (C) 2006, 2007 Andrew Ziem
11
 * Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
12
 * Copyright (C) 2003 Marc Maurer (uwog@uwog.net)
13
 *
14
 * For minor contributions see the git repository.
15
 *
16
 * Alternatively, the contents of this file may be used under the terms
17
 * of the GNU Lesser General Public License Version 2.1 or later
18
 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
19
 * applicable instead of those above.
20
 */
21
22
#ifndef QUATTRO_FORMULA_H
23
#define QUATTRO_FORMULA_H
24
25
#include <functional>
26
#include <ostream>
27
#include <string>
28
#include <vector>
29
30
#include <librevenge-stream/librevenge-stream.h>
31
32
#include "libwps_internal.h"
33
34
#include "WPSDebug.h"
35
#include "WKSContentListener.h"
36
37
namespace QuattroFormulaInternal
38
{
39
struct State;
40
41
/** small class use to store Quattro Pro cell reference (.wb1-3 and qpw) */
42
class CellReference
43
{
44
public:
45
  /// constructor
46
  CellReference()
47
249k
    : m_cells()
48
249k
  {
49
249k
  }
50
  /// add an instruction
51
  void addInstruction(WKSContentListener::FormulaInstruction const &instr)
52
51.3k
  {
53
51.3k
    if (!m_cells.empty() && instr.m_type!=instr.F_Operator && m_cells.back().m_type!=instr.F_Operator)
54
1.87k
    {
55
1.87k
      WKSContentListener::FormulaInstruction sep;
56
1.87k
      sep.m_type=sep.F_Operator;
57
1.87k
      sep.m_content=";";
58
1.87k
      m_cells.push_back(sep);
59
1.87k
    }
60
51.3k
    m_cells.push_back(instr);
61
51.3k
  }
62
  /// return true if we have not read any reference
63
  bool empty() const
64
147k
  {
65
147k
    return m_cells.empty();
66
147k
  }
67
  /// friend operator<<
68
  friend std::ostream &operator<<(std::ostream &o, CellReference const &ref);
69
  //! the list of instruction coding each cell's block
70
  std::vector<WKSContentListener::FormulaInstruction> m_cells;
71
};
72
73
}
74
75
/** a class to read formula in a wb1-wb3, qpw file */
76
class QuattroFormulaManager
77
{
78
public:
79
  typedef std::function<bool(std::shared_ptr<WPSStream> const &stream, long endPos,
80
                             QuattroFormulaInternal::CellReference &ref,
81
                             Vec2i const &cPos, int cSheet)> CellReferenceFunction;
82
83
  //! constructor, version=1: means .wb1-3, version=2 means .qpw
84
  QuattroFormulaManager(QuattroFormulaManager::CellReferenceFunction const &readCellReference,
85
                        int version);
86
87
  //! add a dll's correspondance between an id and a name
88
  void addDLLIdName(int id, librevenge::RVNGString const &name, bool func1);
89
  /** reads a formula */
90
  bool readFormula(std::shared_ptr<WPSStream> const &stream, long endPos, Vec2i const &pos, int sheetId,
91
                   std::vector<WKSContentListener::FormulaInstruction> &formula, std::string &error) const;
92
private:
93
  /** the formula state */
94
  std::shared_ptr<QuattroFormulaInternal::State> m_state;
95
};
96
#endif /* QUATTRO_FORMULA_H */
97
/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */