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
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 : m_coord(0)
46 , m_absolute(false)
47 {
48 }
49 int m_coord;
50 bool m_absolute;
51 };
52
53 struct Address
54 {
55 Address()
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 {
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 {
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);
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: */
IWORKTypes_fwd.h
libetonyek::IWORKFormula::write
void write(const boost::optional< unsigned > &hc, librevenge::RVNGPropertyListVector &formula, const IWORKTableNameMapPtr_t &tableNameMap) const
libetonyek::IWORKFormula::parse
bool parse(const std::vector< Token > &formula)
libetonyek::IWORKFormula::computeOffset
bool computeOffset(const boost::optional< unsigned > &hc, int &offsetColumn, int &offsetRow) const
libetonyek::IWORKFormula::m_hc
boost::optional< unsigned > m_hc
Definition IWORKFormula.h:112
libetonyek::IWORKFormula::IWORKFormula
IWORKFormula(const boost::optional< unsigned > &hc)
libetonyek::IWORKFormula::m_impl
std::shared_ptr< Impl > m_impl
Definition IWORKFormula.h:111
libetonyek::IWORKFormula::parse
bool parse(const std::string &formula)
libetonyek::IWORKFormula::str
const std::string str(const boost::optional< unsigned > &hc) const
libetonyek_utils.h
libetonyek::IWORKToken::val
@ val
Definition IWORKToken.h:630
libetonyek::IWORKToken::s
@ s
Definition IWORKToken.h:394
libetonyek::IWORKToken::type
@ type
Definition IWORKToken.h:493
libetonyek::IWORKToken::hc
@ hc
Definition IWORKToken.h:559
libetonyek::IWORKToken::formula
@ formula
Definition IWORKToken.h:228
libetonyek::IWORKToken::name
@ name
Definition IWORKToken.h:585
libetonyek
Definition IWORKBezierElement.cpp:21
libetonyek::IWORKTableNameMapPtr_t
std::shared_ptr< IWORKTableNameMap_t > IWORKTableNameMapPtr_t
Definition IWORKTypes_fwd.h:36
libetonyek::IWORKFormula::Address
Definition IWORKFormula.h:54
libetonyek::IWORKFormula::Address::m_column
boost::optional< Coord > m_column
Definition IWORKFormula.h:61
libetonyek::IWORKFormula::Address::m_table
boost::optional< std::string > m_table
Definition IWORKFormula.h:63
libetonyek::IWORKFormula::Address::operator<<
friend std::ostream & operator<<(std::ostream &s, Address const &ad)
Definition IWORKFormula.cpp:35
libetonyek::IWORKFormula::Address::m_row
boost::optional< Coord > m_row
Definition IWORKFormula.h:62
libetonyek::IWORKFormula::Address::Address
Address()
Definition IWORKFormula.h:55
libetonyek::IWORKFormula::Coord::Coord
Coord()
Definition IWORKFormula.h:44
libetonyek::IWORKFormula::Coord::m_absolute
bool m_absolute
Definition IWORKFormula.h:50
libetonyek::IWORKFormula::Coord::m_coord
int m_coord
Definition IWORKFormula.h:49
libetonyek::IWORKFormula::Token
small structure used by IWAParser to create formula
Definition IWORKFormula.h:69
libetonyek::IWORKFormula::Token::m_address
IWORKFormula::Address m_address
Definition IWORKFormula.h:106
libetonyek::IWORKFormula::Token::Token
Token(IWORKFormula::Address const &address)
Definition IWORKFormula.h:95
libetonyek::IWORKFormula::Token::Token
Token(Type type)
Definition IWORKFormula.h:74
libetonyek::IWORKFormula::Token::m_string
std::string m_string
Definition IWORKFormula.h:104
libetonyek::IWORKFormula::Token::m_type
Type m_type
Definition IWORKFormula.h:103
libetonyek::IWORKFormula::Token::operator<<
friend std::ostream & operator<<(std::ostream &s, Token const &dt)
Definition IWORKFormula.cpp:51
libetonyek::IWORKFormula::Token::Token
Token(double const &val)
Definition IWORKFormula.h:81
libetonyek::IWORKFormula::Token::Token
Token(std::string const &name, Type type)
Definition IWORKFormula.h:88
libetonyek::IWORKFormula::Token::m_value
double m_value
Definition IWORKFormula.h:105
libetonyek::IWORKFormula::Token::Type
Type
Definition IWORKFormula.h:71
libetonyek::IWORKFormula::Token::Function
@ Function
Definition IWORKFormula.h:72
libetonyek::IWORKFormula::Token::Operator
@ Operator
Definition IWORKFormula.h:72
libetonyek::IWORKFormula::Token::String
@ String
Definition IWORKFormula.h:72
libetonyek::IWORKFormula::Token::Cell
@ Cell
Definition IWORKFormula.h:72
libetonyek::IWORKFormula::Token::Double
@ Double
Definition IWORKFormula.h:72