Coverage Report

Created: 2026-10-28 06:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libetonyek/src/lib/IWORKFormula.h
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/*
3
 * This file is part of the libetonyek 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
10
#ifndef IWORKFORMULA_H_INCLUDED
11
#define IWORKFORMULA_H_INCLUDED
12
13
#include <memory>
14
#include <ostream>
15
#include <string>
16
#include <vector>
17
18
#include <boost/optional.hpp>
19
20
#include "IWORKTypes_fwd.h"
21
#include "libetonyek_utils.h"
22
23
namespace libetonyek
24
{
25
26
class IWORKFormula
27
{
28
  struct Impl;
29
30
public:
31
  struct Token;
32
33
  explicit IWORKFormula(const boost::optional<unsigned> &hc);
34
35
  bool parse(const std::string &formula);
36
  bool parse(const std::vector<Token> &formula);
37
38
  void write(const boost::optional<unsigned> &hc, librevenge::RVNGPropertyListVector &formula, const IWORKTableNameMapPtr_t &tableNameMap) const;
39
  const std::string str(const boost::optional<unsigned> &hc) const;
40
41
public:
42
  struct Coord
43
  {
44
    Coord()
45
0
      : m_coord(0)
46
0
      , m_absolute(false)
47
0
    {
48
0
    }
49
    int m_coord;
50
    bool m_absolute;
51
  };
52
53
  struct Address
54
  {
55
    Address()
56
0
      : m_column()
57
0
      , m_row()
58
0
      , m_table()
59
0
    {
60
0
    }
61
    boost::optional<Coord> m_column;
62
    boost::optional<Coord> m_row;
63
    boost::optional<std::string> m_table;
64
    friend std::ostream &operator<<(std::ostream &s, Address const &ad);
65
  };
66
67
  //! small structure used by IWAParser to create formula
68
  struct Token
69
  {
70
    enum Type
71
    {
72
      Cell, Double, Function, Operator, String
73
    };
74
    explicit Token(Type type)
75
      : m_type(type)
76
      , m_string()
77
      , m_value(0)
78
      , m_address()
79
0
    {
80
0
    }
81
    explicit Token(double const &val)
82
0
      : m_type(Double)
83
0
      , m_string()
84
0
      , m_value(val)
85
0
      , m_address()
86
0
    {
87
0
    }
88
    Token(std::string const &name, Type type)
89
0
      : m_type(type)
90
0
      , m_string(name)
91
0
      , m_value(0)
92
0
      , m_address()
93
0
    {
94
0
    }
95
    explicit Token(IWORKFormula::Address const &address)
96
0
      : m_type(Cell)
97
0
      , m_string()
98
      , m_value()
99
0
      , m_address(address)
100
0
    {
101
0
    }
102
    friend std::ostream &operator<<(std::ostream &s, Token const &dt);
103
    Type m_type;
104
    std::string m_string;
105
    double m_value;
106
    IWORKFormula::Address m_address;
107
  };
108
109
private:
110
  bool computeOffset(const boost::optional<unsigned> &hc, int &offsetColumn, int &offsetRow) const;
111
  std::shared_ptr<Impl> m_impl;
112
  boost::optional<unsigned> m_hc;
113
};
114
115
} // namespace libetonyek
116
117
#endif // IWORKFORMULA_H_INCLUDED
118
119
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */