workbook parameterised constructors

Issue #298
- all 4 are simply duplicating existing behaviour, but perhaps we can get a more optimal version in future
- istream ctor is intended as an extension point that can then be used to create free/static functions to work with any future data source (vector), while the path ctor is a convenience function for the common case (from file)
This commit is contained in:
Crzyrndm 2018-07-02 21:33:27 +12:00
parent e0d62b0835
commit bb04205dac
2 changed files with 50 additions and 3 deletions

View File

@ -130,6 +130,31 @@ public:
/// </summary>
workbook();
/// <summary>
/// load the xlsx file at path
/// </summary>
workbook(const xlnt::path &file);
/// <summary>
/// load the encrpyted xlsx file at path
/// </summary>
workbook(const xlnt::path &file, const std::string& password);
/// <summary>
/// construct the workbook from any data stream where the data is the binary form of a workbook
/// </summary>
workbook(std::istream & data);
/// <summary>
/// construct the workbook from any data stream where the data is the binary form of an encrypted workbook
/// </summary>
workbook(std::istream &data, const std::string& password);
/// <summary>
/// Move constructor. Constructs a workbook from existing workbook, other.
/// </summary>
workbook(workbook &&other);
/// <summary>
/// Move constructor. Constructs a workbook from existing workbook, other.
/// </summary>

View File

@ -500,6 +500,30 @@ workbook::workbook()
swap(wb_template);
}
workbook::workbook(const xlnt::path &file)
{
*this = empty();
load(file);
}
workbook::workbook(const xlnt::path &file, const std::string &password)
{
*this = empty();
load(file, password);
}
workbook::workbook(std::istream &data)
{
*this = empty();
load(data);
}
workbook::workbook(std::istream &data, const std::string &password)
{
*this = empty();
load(data, password);
}
workbook::workbook(detail::workbook_impl *impl)
: d_(impl)
{
@ -1178,9 +1202,7 @@ workbook::workbook(const workbook &other)
d_->stylesheet_.get().parent = this;
}
workbook::~workbook()
{
}
workbook::~workbook() = default;
bool workbook::has_theme() const
{