You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
liborcus/0001-Remove-use-of-boost-in...

396 lines
13 KiB

From 1f12d182ca0fa4f3f0fd017cce551d8fdc30a1a2 Mon Sep 17 00:00:00 2001
From: Kohei Yoshida <kohei.yoshida@gmail.com>
Date: Sat, 20 Jun 2015 14:46:56 -0400
Subject: [PATCH] Remove use of boost in orcus-spreadsheet-model.
---
src/spreadsheet/document.cpp | 100 +++++++++++++++++++++++--------------------
src/spreadsheet/sheet.cpp | 18 ++++----
src/spreadsheet/table.cpp | 6 ++-
3 files changed, 68 insertions(+), 56 deletions(-)
diff --git a/src/spreadsheet/document.cpp b/src/spreadsheet/document.cpp
index c33a30e..02850ce 100644
--- a/src/spreadsheet/document.cpp
+++ b/src/spreadsheet/document.cpp
@@ -16,6 +16,7 @@
#include "orcus/pstring.hpp"
#include "orcus/types.hpp"
#include "orcus/string_pool.hpp"
+#include "orcus/global.hpp"
#include <ixion/formula.hpp>
#include <ixion/formula_result.hpp>
@@ -26,9 +27,7 @@
#include <iostream>
#include <fstream>
-#include <boost/ptr_container/ptr_vector.hpp>
-#include <boost/ptr_container/ptr_map.hpp>
-#include <boost/scoped_ptr.hpp>
+#include <map>
using namespace std;
@@ -41,47 +40,50 @@ namespace {
* Use the printer function object to print sheet content with for_each
* function.
*/
-struct sheet_item : private boost::noncopyable
+struct sheet_item
{
+ sheet_item(const sheet_item&) = delete;
+ sheet_item& operator=(const sheet_item&) = delete;
+
pstring name;
sheet data;
sheet_item(document& doc, const pstring& _name, sheet_t sheet_index, row_t row_size, col_t col_size);
- class flat_printer : public ::std::unary_function<sheet_item, void>
+ class flat_printer : public ::std::unary_function<std::unique_ptr<sheet_item>, void>
{
const std::string& m_outdir;
public:
flat_printer(const std::string& outdir);
- void operator() (const sheet_item& item) const;
+ void operator() (const std::unique_ptr<sheet_item>& item) const;
};
- class check_printer : public std::unary_function<sheet_item, void>
+ class check_printer : public std::unary_function<std::unique_ptr<sheet_item>, void>
{
std::ostream& m_os;
public:
check_printer(std::ostream& os);
- void operator() (const sheet_item& item) const;
+ void operator() (const std::unique_ptr<sheet_item>& item) const;
};
- struct html_printer : public ::std::unary_function<sheet_item, void>
+ struct html_printer : public ::std::unary_function<std::unique_ptr<sheet_item>, void>
{
html_printer(const ::std::string& filepath);
- void operator() (const sheet_item& item) const;
+ void operator() (const std::unique_ptr<sheet_item>& item) const;
private:
const ::std::string& m_filepath;
};
};
-typedef boost::ptr_map<pstring, table_t> table_store_type;
+typedef std::map<pstring, std::unique_ptr<table_t>> table_store_type;
sheet_item::sheet_item(document& doc, const pstring& _name, sheet_t sheet_index, row_t row_size, col_t col_size) :
name(_name), data(doc, sheet_index, row_size, col_size) {}
sheet_item::flat_printer::flat_printer(const string& outdir) : m_outdir(outdir) {}
-void sheet_item::flat_printer::operator() (const sheet_item& item) const
+void sheet_item::flat_printer::operator() (const std::unique_ptr<sheet_item>& item) const
{
- string this_file = m_outdir + '/' + item.name.str() + ".txt";
+ string this_file = m_outdir + '/' + item->name.str() + ".txt";
ofstream file(this_file.c_str());
if (!file)
@@ -91,35 +93,35 @@ void sheet_item::flat_printer::operator() (const sheet_item& item) const
}
file << "---" << endl;
- file << "Sheet name: " << item.name << endl;
- item.data.dump_flat(file);
+ file << "Sheet name: " << item->name << endl;
+ item->data.dump_flat(file);
}
sheet_item::check_printer::check_printer(std::ostream& os) : m_os(os) {}
-void sheet_item::check_printer::operator() (const sheet_item& item) const
+void sheet_item::check_printer::operator() (const std::unique_ptr<sheet_item>& item) const
{
- item.data.dump_check(m_os, item.name);
+ item->data.dump_check(m_os, item->name);
}
sheet_item::html_printer::html_printer(const string& filepath) :
m_filepath(filepath) {}
-void sheet_item::html_printer::operator() (const sheet_item& item) const
+void sheet_item::html_printer::operator() (const std::unique_ptr<sheet_item>& item) const
{
// file path is expected to be a directory.
- string this_file = m_filepath + '/' + item.name.str() + ".html";
- item.data.dump_html(this_file);
+ string this_file = m_filepath + '/' + item->name.str() + ".html";
+ item->data.dump_html(this_file);
}
-class find_sheet_by_name : std::unary_function<sheet_item , bool>
+class find_sheet_by_name : std::unary_function<std::unique_ptr<sheet_item> , bool>
{
const pstring& m_name;
public:
find_sheet_by_name(const pstring& name) : m_name(name) {}
- bool operator() (const sheet_item & v) const
+ bool operator() (const std::unique_ptr<sheet_item>& v) const
{
- return v.name == m_name;
+ return v->name == m_name;
}
};
@@ -208,10 +210,10 @@ class table_handler : public ixion::iface::table_handler
const table_t* find_table(const ixion::abs_address_t& pos) const
{
- table_store_type::const_iterator it = m_tables.begin(), it_end = m_tables.end();
+ auto it = m_tables.begin(), it_end = m_tables.end();
for (; it != it_end; ++it)
{
- const table_t* p = it->second;
+ const table_t* p = it->second.get();
if (p->range.contains(pos))
return p;
}
@@ -310,31 +312,36 @@ public:
// no table name given.
return ixion::abs_range_t(ixion::abs_range_t::invalid);
- table_store_type::const_iterator it = m_tables.find(tab_name);
+ auto it = m_tables.find(tab_name);
if (it == m_tables.end())
// no table by this name found.
return ixion::abs_range_t(ixion::abs_range_t::invalid);
- const table_t* tab = it->second;
+ const table_t* tab = it->second.get();
return get_range_from_table(*tab, column_first, column_last, areas);
}
};
+typedef std::vector<std::unique_ptr<sheet_item>> sheet_items_type;
+
}
struct document_impl
{
+ document_impl(const document_impl&) = delete;
+ document_impl& operator=(const document_impl&) = delete;
+
document& m_doc;
string_pool m_string_pool;
ixion::model_context m_context;
date_time_t m_origin_date;
- boost::ptr_vector<sheet_item> m_sheets;
+ sheet_items_type m_sheets;
import_styles* mp_styles;
import_shared_strings* mp_strings;
ixion::dirty_formula_cells_t m_dirty_cells;
- boost::scoped_ptr<ixion::formula_name_resolver> mp_name_resolver;
+ std::unique_ptr<ixion::formula_name_resolver> mp_name_resolver;
formula_grammar_t m_grammar;
table_store_type m_tables;
@@ -407,22 +414,23 @@ void document::insert_table(table_t* p)
return;
pstring name = p->name;
- mp_impl->m_tables.insert(name, p);
+ mp_impl->m_tables.insert(
+ table_store_type::value_type(name, std::unique_ptr<table_t>(p)));
}
const table_t* document::get_table(const pstring& name) const
{
- table_store_type::const_iterator it = mp_impl->m_tables.find(name);
- return it == mp_impl->m_tables.end() ? NULL : it->second;
+ auto it = mp_impl->m_tables.find(name);
+ return it == mp_impl->m_tables.end() ? NULL : it->second.get();
}
namespace {
-struct sheet_finalizer : unary_function<sheet_item, void>
+struct sheet_finalizer : std::unary_function<std::unique_ptr<sheet_item>, void>
{
- void operator() (sheet_item& sh)
+ void operator() (std::unique_ptr<sheet_item>& sh)
{
- sh.data.finalize();
+ sh->data.finalize();
}
};
@@ -440,24 +448,24 @@ sheet* document::append_sheet(const pstring& sheet_name, row_t row_size, col_t c
sheet_t sheet_index = static_cast<sheet_t>(mp_impl->m_sheets.size());
mp_impl->m_sheets.push_back(
- new sheet_item(
+ make_unique<sheet_item>(
*this, sheet_name_safe, sheet_index, row_size, col_size));
mp_impl->m_context.append_sheet(
sheet_name_safe.get(), sheet_name_safe.size(), row_size, col_size);
- return &mp_impl->m_sheets.back().data;
+ return &mp_impl->m_sheets.back()->data;
}
sheet* document::get_sheet(const pstring& sheet_name)
{
- boost::ptr_vector<sheet_item>::iterator it =
- std::find_if(mp_impl->m_sheets.begin(), mp_impl->m_sheets.end(), find_sheet_by_name(sheet_name));
+ auto it = std::find_if(
+ mp_impl->m_sheets.begin(), mp_impl->m_sheets.end(), find_sheet_by_name(sheet_name));
if (it == mp_impl->m_sheets.end())
return NULL;
- return &it->data;
+ return &(*it)->data;
}
sheet* document::get_sheet(sheet_t sheet_pos)
@@ -465,7 +473,7 @@ sheet* document::get_sheet(sheet_t sheet_pos)
if (static_cast<size_t>(sheet_pos) >= mp_impl->m_sheets.size())
return NULL;
- return &mp_impl->m_sheets[sheet_pos].data;
+ return &mp_impl->m_sheets[sheet_pos]->data;
}
const sheet* document::get_sheet(sheet_t sheet_pos) const
@@ -473,7 +481,7 @@ const sheet* document::get_sheet(sheet_t sheet_pos) const
if (static_cast<size_t>(sheet_pos) >= mp_impl->m_sheets.size())
return NULL;
- return &mp_impl->m_sheets[sheet_pos].data;
+ return &mp_impl->m_sheets[sheet_pos]->data;
}
void document::calc_formulas()
@@ -516,13 +524,13 @@ void document::dump_html(const string& outdir) const
sheet_t document::get_sheet_index(const pstring& name) const
{
- boost::ptr_vector<sheet_item>::const_iterator it =
- std::find_if(mp_impl->m_sheets.begin(), mp_impl->m_sheets.end(), find_sheet_by_name(name));
+ auto it = std::find_if(
+ mp_impl->m_sheets.begin(), mp_impl->m_sheets.end(), find_sheet_by_name(name));
if (it == mp_impl->m_sheets.end())
return ixion::invalid_sheet;
- boost::ptr_vector<sheet_item>::const_iterator it_beg = mp_impl->m_sheets.begin();
+ auto it_beg = mp_impl->m_sheets.begin();
size_t pos = std::distance(it_beg, it);
return static_cast<sheet_t>(pos);
}
@@ -536,7 +544,7 @@ pstring document::get_sheet_name(sheet_t sheet_pos) const
if (pos >= mp_impl->m_sheets.size())
return pstring();
- return mp_impl->m_sheets[pos].name;
+ return mp_impl->m_sheets[pos]->name;
}
size_t document::sheet_size() const
diff --git a/src/spreadsheet/sheet.cpp b/src/spreadsheet/sheet.cpp
index 8e9db3b..a9d423f 100644
--- a/src/spreadsheet/sheet.cpp
+++ b/src/spreadsheet/sheet.cpp
@@ -30,6 +30,7 @@
#include <cassert>
#include <memory>
#include <cstdlib>
+#include <unordered_map>
#include <mdds/flat_segment_tree.hpp>
#include <mdds/multi_type_matrix.hpp>
@@ -43,9 +44,6 @@
#include <ixion/model_context.hpp>
#include <ixion/address.hpp>
-#include <boost/unordered_map.hpp>
-#include <boost/noncopyable.hpp>
-
#define ORCUS_DEBUG_SHEET 0
using namespace std;
@@ -64,15 +62,15 @@ struct merge_size
};
// Merged cell data stored in sheet.
-typedef boost::unordered_map<row_t, merge_size> merge_size_type;
-typedef boost::unordered_map<col_t, merge_size_type*> col_merge_size_type;
+typedef std::unordered_map<row_t, merge_size> merge_size_type;
+typedef std::unordered_map<col_t, merge_size_type*> col_merge_size_type;
// Overlapped cells per row, used when rendering sheet content.
typedef mdds::flat_segment_tree<col_t, bool> overlapped_col_index_type;
-typedef boost::unordered_map<row_t, overlapped_col_index_type*> overlapped_cells_type;
+typedef std::unordered_map<row_t, overlapped_col_index_type*> overlapped_cells_type;
typedef mdds::flat_segment_tree<row_t, size_t> segment_row_index_type;
-typedef boost::unordered_map<col_t, segment_row_index_type*> cell_format_type;
+typedef std::unordered_map<col_t, segment_row_index_type*> cell_format_type;
// Widths and heights are stored in twips.
typedef mdds::flat_segment_tree<col_t, col_width_t> col_widths_store_type;
@@ -156,7 +154,7 @@ public:
}
-struct sheet_impl : boost::noncopyable
+struct sheet_impl
{
document& m_doc;
sheet_properties m_sheet_props; /// sheet properties import interface.
@@ -184,6 +182,10 @@ struct sheet_impl : boost::noncopyable
col_t m_col_size;
const sheet_t m_sheet; /// sheet ID
+ sheet_impl() = delete;
+ sheet_impl(const sheet_impl&) = delete;
+ sheet_impl& operator=(const sheet_impl&) = delete;
+
sheet_impl(document& doc, sheet& sh, sheet_t sheet_index, row_t row_size, col_t col_size) :
m_doc(doc),
m_sheet_props(doc, sh), m_data_table(sh),
diff --git a/src/spreadsheet/table.cpp b/src/spreadsheet/table.cpp
index 9abc978..9dc7564 100644
--- a/src/spreadsheet/table.cpp
+++ b/src/spreadsheet/table.cpp
@@ -15,7 +15,6 @@
#include "orcus/spreadsheet/auto_filter.hpp"
#include <ixion/formula_name_resolver.hpp>
-#include <boost/noncopyable.hpp>
namespace orcus { namespace spreadsheet {
@@ -84,7 +83,7 @@ public:
}
-struct table_impl : boost::noncopyable
+struct table_impl
{
document& m_doc;
sheet& m_sheet;
@@ -94,6 +93,9 @@ struct table_impl : boost::noncopyable
std::unique_ptr<table_t> mp_data;
table_column_t m_column;
+ table_impl(const table_impl&) = delete;
+ table_impl& operator=(const table_impl&) = delete;
+
table_impl(document& doc, sheet& sh) :
m_doc(doc), m_sheet(sh), m_auto_filter(doc) {}
};
--
2.5.0