nss: upgrade to release 3.73
[LibreOffice.git] / sc / source / filter / oox / tablecolumnsbuffer.cxx
blob57552204c62bbf8f5fbf4f318cc9e590447018b4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <tablecolumnsbuffer.hxx>
22 #include <sal/log.hxx>
23 #include <oox/helper/attributelist.hxx>
24 #include <oox/token/tokens.hxx>
25 #include <dbdata.hxx>
27 namespace oox::xls {
29 TableColumn::TableColumn( const WorkbookHelper& rHelper ) :
30 WorkbookHelper( rHelper ),
31 mnId( -1 ),
32 mnDataDxfId( -1 )
36 void TableColumn::importTableColumn( const AttributeList& rAttribs )
38 mnId = rAttribs.getInteger( XML_id, -1 );
39 maName = rAttribs.getString( XML_name, OUString() );
40 mnDataDxfId = rAttribs.getInteger( XML_dataDxfId, -1 );
43 void TableColumn::importTableColumn( SequenceInputStream& /*rStrm*/ )
45 /* XXX not implemented */
46 (void) mnId;
49 const OUString& TableColumn::getName() const
51 return maName;
54 TableColumns::TableColumns( const WorkbookHelper& rHelper ) :
55 WorkbookHelper( rHelper ),
56 mnCount(0)
60 void TableColumns::importTableColumns( const AttributeList& rAttribs )
62 mnCount = rAttribs.getInteger( XML_count, 0 );
65 void TableColumns::importTableColumns( SequenceInputStream& /*rStrm*/ )
67 /* XXX not implemented */
68 (void) mnCount;
71 TableColumn& TableColumns::createTableColumn()
73 TableColumnVector::value_type xTableColumn = std::make_shared<TableColumn>( *this );
74 maTableColumnVector.push_back( xTableColumn );
75 return *xTableColumn;
78 bool TableColumns::finalizeImport( ScDBData* pDBData )
80 SAL_WARN_IF( static_cast<size_t>(mnCount) != maTableColumnVector.size(), "sc.filter",
81 "TableColumns::finalizeImport - count attribute doesn't match number of tableColumn elements");
82 if ( pDBData )
84 /* TODO: use svl::SharedString for names */
85 ::std::vector< OUString > aNames( maTableColumnVector.size());
86 size_t i = 0;
87 for (const auto& rxTableColumn : maTableColumnVector)
89 aNames[i] = rxTableColumn->getName();
90 ++i;
92 pDBData->SetTableColumnNames( aNames);
93 return true;
95 return false;
98 TableColumnsBuffer::TableColumnsBuffer( const WorkbookHelper& rHelper ) :
99 WorkbookHelper( rHelper )
103 TableColumns& TableColumnsBuffer::createTableColumns()
105 TableColumnsVector::value_type xTableColumns = std::make_shared<TableColumns>( *this );
106 maTableColumnsVector.push_back( xTableColumns );
107 return *xTableColumns;
110 void TableColumnsBuffer::finalizeImport( ScDBData* pDBData )
112 TableColumns* pTableColumns = getActiveTableColumns();
113 if ( pTableColumns )
114 pTableColumns->finalizeImport( pDBData );
117 TableColumns* TableColumnsBuffer::getActiveTableColumns()
119 // not more than one table columns descriptor per table
120 SAL_WARN_IF( maTableColumnsVector.size() > 1, "sc.filter",
121 "TableColumnsBuffer::getActiveTableColumns - too many table columns" );
122 // stick to the last imported table columns
123 return maTableColumnsVector.empty() ? nullptr : maTableColumnsVector.back().get();
126 } // namespace oox::xls
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */