IWORKFormula.h
Go to the documentation of this file.
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
23namespace libetonyek
24{
25
27{
28 struct Impl;
29
30public:
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
41public:
42 struct Coord
43 {
45 : m_coord(0)
46 , m_absolute(false)
47 {
48 }
51 };
52
53 struct Address
54 {
56 : m_column()
57 , m_row()
58 , m_table()
59 {
60 }
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
68 struct Token
69 {
74 explicit Token(Type type)
75 : m_type(type)
76 , m_string()
77 , m_value(0)
78 , m_address()
79 {
80 }
81 explicit Token(double const &val)
82 : m_type(Double)
83 , m_string()
84 , m_value(val)
85 , m_address()
86 {
87 }
88 Token(std::string const &name, Type type)
89 : m_type(type)
90 , m_string(name)
91 , m_value(0)
92 , m_address()
93 {
94 }
95 explicit Token(IWORKFormula::Address const &address)
96 : m_type(Cell)
97 , m_string()
98 , m_value()
99 , m_address(address)
100 {
101 }
102 friend std::ostream &operator<<(std::ostream &s, Token const &dt);
104 std::string m_string;
105 double m_value;
107 };
108
109private:
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: */
void write(const boost::optional< unsigned > &hc, librevenge::RVNGPropertyListVector &formula, const IWORKTableNameMapPtr_t &tableNameMap) const
bool parse(const std::vector< Token > &formula)
bool computeOffset(const boost::optional< unsigned > &hc, int &offsetColumn, int &offsetRow) const
boost::optional< unsigned > m_hc
Definition IWORKFormula.h:112
IWORKFormula(const boost::optional< unsigned > &hc)
std::shared_ptr< Impl > m_impl
Definition IWORKFormula.h:111
bool parse(const std::string &formula)
const std::string str(const boost::optional< unsigned > &hc) const
@ val
Definition IWORKToken.h:630
@ s
Definition IWORKToken.h:394
@ type
Definition IWORKToken.h:493
@ hc
Definition IWORKToken.h:559
@ formula
Definition IWORKToken.h:228
@ name
Definition IWORKToken.h:585
Definition IWORKBezierElement.cpp:21
std::shared_ptr< IWORKTableNameMap_t > IWORKTableNameMapPtr_t
Definition IWORKTypes_fwd.h:36
Definition IWORKFormula.h:54
boost::optional< Coord > m_column
Definition IWORKFormula.h:61
boost::optional< std::string > m_table
Definition IWORKFormula.h:63
friend std::ostream & operator<<(std::ostream &s, Address const &ad)
Definition IWORKFormula.cpp:35
boost::optional< Coord > m_row
Definition IWORKFormula.h:62
Address()
Definition IWORKFormula.h:55
Coord()
Definition IWORKFormula.h:44
bool m_absolute
Definition IWORKFormula.h:50
int m_coord
Definition IWORKFormula.h:49
small structure used by IWAParser to create formula
Definition IWORKFormula.h:69
IWORKFormula::Address m_address
Definition IWORKFormula.h:106
Token(IWORKFormula::Address const &address)
Definition IWORKFormula.h:95
Token(Type type)
Definition IWORKFormula.h:74
std::string m_string
Definition IWORKFormula.h:104
Type m_type
Definition IWORKFormula.h:103
friend std::ostream & operator<<(std::ostream &s, Token const &dt)
Definition IWORKFormula.cpp:51
Token(double const &val)
Definition IWORKFormula.h:81
Token(std::string const &name, Type type)
Definition IWORKFormula.h:88
double m_value
Definition IWORKFormula.h:105
Type
Definition IWORKFormula.h:71
@ Function
Definition IWORKFormula.h:72
@ Operator
Definition IWORKFormula.h:72
@ String
Definition IWORKFormula.h:72
@ Cell
Definition IWORKFormula.h:72
@ Double
Definition IWORKFormula.h:72

Generated for libetonyek by doxygen 1.13.2