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

Generated for libetonyek by doxygen 1.8.6