Files
core/ASCOfficeXlsFile2/source/XlsFormat/Binary/CompoundFile.cpp
Elen.Subbotina 4357aba883 XlsFile2 bug 24441
git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@63909 954022d7-b5bf-4e40-9824-e11837661b57
2016-05-21 00:20:54 +03:00

159 lines
3.5 KiB
C++

#include "CompoundFile.h"
#include "CFStream.h"
#include <sstream>
namespace XLS
{;
CompoundFile::~CompoundFile()
{
streams.clear();
if (storage_)delete storage_;
storage_ = NULL;
}
CompoundFile::CompoundFile(const std::wstring & file_path, const ReadWriteMode mode)
: rwMode(mode)
{
unsigned int grfMode = 0;
storage_ = new POLE::Storage(file_path.c_str());
if (storage_ == NULL) return;
switch(rwMode)
{
case cf_ReadMode:
{
if (storage_->open(false, false) == false)
throw;
}break;
case cf_WriteMode:
{
if (storage_->open(true, true) == false)
throw;
}break;
}
}
// Opens "Workbook" stream and returns the only reference
CFStreamPtr CompoundFile::getWorkbookStream()
{
return getNamedStream("Workbook");
}
// Creates "Workbook" stream and returns the only reference
CFStreamPtr CompoundFile::createWorkbookStream()
{
return createNamedStream("Workbook");
}
// Opens "SummaryInformation" stream and returns the only reference
CFStreamPtr CompoundFile::getSummaryInformationStream()
{
return getNamedStream("SummaryInformation");
}
// Creates "SummaryInformation" stream and returns the only reference
CFStreamPtr CompoundFile::createSummaryInformationStream()
{
return createNamedStream("SummaryInformation");
}
// Closes "SummaryInformation" stream
void CompoundFile::closeSummaryInformationStream()
{
return closeNamedStream("SummaryInformation");
}
// Opens "SummaryInformation" stream and returns the only reference
CFStreamPtr CompoundFile::getDocumentSummaryInformationStream()
{
return getNamedStream("DocumentSummaryInformation");
}
// Creates "SummaryInformation" stream and returns the only reference
CFStreamPtr CompoundFile::createDocumentSummaryInformationStream()
{
return createNamedStream("DocumentSummaryInformation");
}
// Closes "SummaryInformation" stream
void CompoundFile::closeDocumentSummaryInformationStream()
{
closeNamedStream("DocumentSummaryInformation");
}
CFStreamPtr CompoundFile::getNamedStream(const std::string& name)
{
if(!streams[name])
{
POLE::Stream * pStream = openStream(name.c_str());
if (pStream)
streams[name].reset(new CFStream(pStream));
}
return streams[name];
}
CFStreamPtr CompoundFile::createNamedStream(const std::string& name)
{
if(!streams[name])
{
POLE::Stream * pStream = createStream(name.c_str());
if (pStream)
streams[name].reset(new CFStream(pStream));
}
return streams[name];
}
void CompoundFile::closeNamedStream(const std::string& name)
{
streams[name].reset();
}
// Opens a stream in the storage (shall be called not more than once per stream)
POLE::Stream* CompoundFile::openStream(const std::string & stream_name)
{
POLE::Stream* pStream = new POLE::Stream(storage_, stream_name);
if(pStream == NULL)
{
throw;// EXCEPT::RT::CompoundFileFormatError(std::string("Error opening \"") + static_cast<char*>(stream_name) + "\" stream", hres);
}
if ((pStream) && (pStream->size() > 0))
return pStream;
else return NULL;
}
// Creates a new stream in the storage
POLE::Stream* CompoundFile::createStream(const std::string & stream_name)
{
POLE::Stream* pStream = new POLE::Stream(storage_, stream_name, true);
if(pStream == NULL)
{
throw;// EXCEPT::RT::CompoundFileFormatError(std::string("Error creating \"") + static_cast<char*>(stream_name) + "\" stream", hres);
}
return pStream;
}
} // namespace XLS