Commit b13eba5f authored by ElenaSubbotina's avatar ElenaSubbotina

x2t optimization rels

parent a48058c7
...@@ -103,11 +103,9 @@ namespace PPTX ...@@ -103,11 +103,9 @@ namespace PPTX
pSrcFile->type() == OOX::Presentation::FileTypes::NotesSlide) ? true : false; pSrcFile->type() == OOX::Presentation::FileTypes::NotesSlide) ? true : false;
} }
size_t nCount = rels.m_arrRelations.size(); for (std::map<std::wstring, OOX::Rels::CRelationShip*>::const_iterator it = rels.m_mapRelations.begin(); it != rels.m_mapRelations.end(); it++)
{
for (size_t i = 0; i < nCount; ++i) OOX::Rels::CRelationShip* pRelation = it->second;
{
OOX::Rels::CRelationShip* pRelation = rels.m_arrRelations[i];
OOX::CPath normPath = CorrectPathRels(path, pRelation); OOX::CPath normPath = CorrectPathRels(path, pRelation);
......
...@@ -74,19 +74,19 @@ namespace OOX ...@@ -74,19 +74,19 @@ namespace OOX
void IFileContainer::Read (const OOX::CRels& oRels, const OOX::CPath& oRootPath, const OOX::CPath& oPath) void IFileContainer::Read (const OOX::CRels& oRels, const OOX::CPath& oRootPath, const OOX::CPath& oPath)
{ {
unsigned int nCount = oRels.m_arrRelations.size(); for (std::map<std::wstring, Rels::CRelationShip*>::const_iterator it = oRels.m_mapRelations.begin(); it != oRels.m_mapRelations.end(); it++)
for ( unsigned int nIndex = 0; nIndex < nCount; ++nIndex )
{ {
if (!it->second) continue;
smart_ptr<OOX::File> pFile; smart_ptr<OOX::File> pFile;
if (m_bSpreadsheets) if (m_bSpreadsheets)
pFile = OOX::Spreadsheet::CreateFile( oRootPath, oPath, oRels.m_arrRelations[nIndex] ); pFile = OOX::Spreadsheet::CreateFile( oRootPath, oPath, it->second );
if (pFile.IsInit() == false || pFile->type() == FileTypes::Unknow) if (pFile.IsInit() == false || pFile->type() == FileTypes::Unknow)
pFile = OOX::CreateFile( oRootPath, oPath, oRels.m_arrRelations[nIndex] ); pFile = OOX::CreateFile( oRootPath, oPath, it->second );
Add( oRels.m_arrRelations[nIndex]->rId(), pFile ); Add( it->second->rId(), pFile );
} }
} }
......
...@@ -172,12 +172,12 @@ namespace OOX ...@@ -172,12 +172,12 @@ namespace OOX
} }
~CRels() ~CRels()
{ {
for ( unsigned int nIndex = 0; nIndex < m_arrRelations.size(); nIndex++ ) for (std::map<std::wstring, Rels::CRelationShip*>::iterator it = m_mapRelations.begin(); it != m_mapRelations.end(); it++)
{ {
if ( m_arrRelations[nIndex] ) delete m_arrRelations[nIndex]; if ( it->second ) delete it->second;
m_arrRelations[nIndex] = NULL; it->second = NULL;
} }
m_arrRelations.clear(); m_mapRelations.clear();
} }
...@@ -206,8 +206,12 @@ namespace OOX ...@@ -206,8 +206,12 @@ namespace OOX
sName = oReader.GetName(); sName = oReader.GetName();
if ( _T("Relationship") == sName ) if ( _T("Relationship") == sName )
{ {
OOX::Rels::CRelationShip *oRel = new OOX::Rels::CRelationShip(oReader); OOX::Rels::CRelationShip *pRel = new OOX::Rels::CRelationShip(oReader);
if (oRel) m_arrRelations.push_back( oRel ); if (pRel)
{
std::wstring rid = pRel->rId().get();
m_mapRelations.insert(std::make_pair( rid, pRel) );
}
} }
} }
} }
...@@ -226,9 +230,12 @@ namespace OOX ...@@ -226,9 +230,12 @@ namespace OOX
{ {
if ( oNodes.GetAt( nIndex, oRelNode ) ) if ( oNodes.GetAt( nIndex, oRelNode ) )
{ {
//Rels::CRelationShip oRel = oRelNode; Rels::CRelationShip *pRel = new Rels::CRelationShip (oRelNode);
Rels::CRelationShip *oRel = new Rels::CRelationShip (oRelNode); if (pRel)
m_arrRelations.push_back( oRel ); {
std::wstring rid = pRel->rId().get();
m_mapRelations.insert(std::make_pair( rid, pRel) );
}
} }
} }
} }
...@@ -237,7 +244,7 @@ namespace OOX ...@@ -237,7 +244,7 @@ namespace OOX
} }
void Write(const CPath& oFilePath) const void Write(const CPath& oFilePath) const
{ {
if ( 0 < m_arrRelations.size() ) if ( !m_mapRelations.empty() )
{ {
CPath oFile = CreateFileName( oFilePath ); CPath oFile = CreateFileName( oFilePath );
CSystemUtility::CreateDirectories( oFile.GetDirectory() ); CSystemUtility::CreateDirectories( oFile.GetDirectory() );
...@@ -250,10 +257,10 @@ namespace OOX ...@@ -250,10 +257,10 @@ namespace OOX
oWriter.WriteAttribute( _T("xmlns"), _T("http://schemas.openxmlformats.org/package/2006/relationships") ); oWriter.WriteAttribute( _T("xmlns"), _T("http://schemas.openxmlformats.org/package/2006/relationships") );
oWriter.WriteNodeEnd( _T("Relationships"), true, false ); oWriter.WriteNodeEnd( _T("Relationships"), true, false );
for ( unsigned int nIndex = 0; nIndex < m_arrRelations.size(); nIndex++ ) for (std::map<std::wstring, Rels::CRelationShip*>::const_iterator it = m_mapRelations.begin(); it != m_mapRelations.end(); it++)
{ {
if ( m_arrRelations[nIndex]) if ( it->second )
oWriter.WriteString( m_arrRelations[nIndex]->toXML() ); oWriter.WriteString( it->second->toXML() );
} }
oWriter.WriteNodeEnd(_T("Relationships") ); oWriter.WriteNodeEnd(_T("Relationships") );
...@@ -270,39 +277,37 @@ namespace OOX ...@@ -270,39 +277,37 @@ namespace OOX
std::wstring strFileName = oPath.m_strFilename; std::wstring strFileName = oPath.m_strFilename;
std::wstring strDir = oPath.GetDirectory() + _T(""); std::wstring strDir = oPath.GetDirectory() + _T("");
if ( _T("") == oPath.GetExtention() ) if ( L"" == oPath.GetExtention() )
{ {
if ( oType.RelationType() == _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject") ) if ( oType.RelationType() == L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject" )
{ {
strFileName += L".bin"; strFileName += L".bin";
m_arrRelations.push_back(new Rels::CRelationShip( rId, oType.RelationType(), strDir + strFileName ) ); m_mapRelations.insert( std::make_pair( rId.get(), new Rels::CRelationShip( rId, oType.RelationType(), strDir + strFileName )) );
} }
else if ( oType.RelationType() == _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/image") ) else if ( oType.RelationType() == L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" )
{ {
strFileName += L".wmf" ; strFileName += L".wmf" ;
m_arrRelations.push_back(new Rels::CRelationShip( rId, oType.RelationType(), strDir + strFileName ) ); m_mapRelations.insert( std::make_pair( rId.get(), new Rels::CRelationShip( rId, oType.RelationType(), strDir + strFileName )) );
} }
} }
else else
{ {
m_arrRelations.push_back(new Rels::CRelationShip( rId, oType.RelationType(), oPath.GetPath()) ); m_mapRelations.insert( std::make_pair( rId.get(), new Rels::CRelationShip( rId, oType.RelationType(), oPath.GetPath())));
//m_arrRelations.push_back( Rels::CRelationShip( rId, oType.RelationType(), replace_extension( oPath, L"svm", L"png") );
} }
} }
} }
void Registration(const RId& rId, const smart_ptr<External> pExternal) void Registration(const RId& rId, const smart_ptr<External> pExternal)
{ {
m_arrRelations.push_back( new Rels::CRelationShip( rId, pExternal ) ); m_mapRelations.insert( std::make_pair( rId.get(), new Rels::CRelationShip( rId, pExternal )) );
} }
void GetRel(const RId& rId, Rels::CRelationShip** ppRelationShip) void GetRel(const RId& rId, Rels::CRelationShip** ppRelationShip)
{ {
(*ppRelationShip) = NULL; (*ppRelationShip) = NULL;
for( size_t i = 0, length = m_arrRelations.size(); i < length; ++i)
std::map<std::wstring, Rels::CRelationShip*>::iterator pFind = m_mapRelations.find(rId.get());
if (pFind != m_mapRelations.end())
{ {
if ((m_arrRelations[i]) && (m_arrRelations[i]->rId() == rId)) (*ppRelationShip) = pFind->second;
{
(*ppRelationShip) = new Rels::CRelationShip(*m_arrRelations[i]);
}
} }
} }
...@@ -319,11 +324,9 @@ namespace OOX ...@@ -319,11 +324,9 @@ namespace OOX
return pathTemp.GetPath(); return pathTemp.GetPath();
} }
public: public:
std::vector<Rels::CRelationShip*> m_arrRelations; std::map<std::wstring, Rels::CRelationShip*> m_mapRelations;
}; };
} // namespace OOX } // namespace OOX
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment