1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _DOCXFOOTNOTES_HXX_
25 #define _DOCXFOOTNOTES_HXX_
26 
27 #include <fmtftn.hxx>
28 
29 #include <rtl/string.hxx>
30 #include <rtl/ustring.hxx>
31 #include <sax/fshelper.hxx>
32 
33 #include <vector>
34 
35 namespace docx {
36 
37 typedef ::std::vector< const SwFmtFtn* > FootnotesVector;
38 
39 /** Remember footnotes/endnotes so that we can dump them in one go.
40 
41     Also rememeber the last added footnote Id to be able to write it in the
42     DocxAttributeOutput::EndRunProperties() method.
43 */
44 class FootnotesList {
45     /// The current footnote, that was not written yet.
46     sal_Int32 m_nCurrent;
47 
48     /// List of the footnotes.
49     FootnotesVector m_aFootnotes;
50 
51 public:
FootnotesList()52     FootnotesList() : m_nCurrent( -1 ) {}
53 
add(const SwFmtFtn & rFootnote)54     void add( const SwFmtFtn& rFootnote )
55     {
56         m_aFootnotes.push_back( &rFootnote );
57         m_nCurrent = m_aFootnotes.size() - 1;
58     }
59 
60     /// Return the current footnote/endnote and clear the 'current' state.
getCurrent(sal_Int32 & rId)61     const SwFmtFtn* getCurrent( sal_Int32& rId )
62     {
63         // skip ids 0 and 1 - they are reserved for separator and
64         // continuationSeparator
65         rId = m_nCurrent + 2;
66 
67         // anything to write at all?
68         if ( m_nCurrent < 0 )
69         {
70             rId = -1;
71             return NULL;
72         }
73 
74         const SwFmtFtn *pFootnote = m_aFootnotes[m_nCurrent];
75         m_nCurrent = -1;
76 
77         return pFootnote;
78     }
79 
80     /// Return all the footnotes/endnotes.
getVector() const81     const FootnotesVector& getVector() const
82     {
83         return m_aFootnotes;
84     }
85 
86     /// Do we have any footnotes/endnotes at all?
isEmpty() const87     bool isEmpty() const
88     {
89         return m_aFootnotes.empty();
90     }
91 };
92 
93 } // namespace docx
94 
95 #endif // _DOCXFOOTNOTES_HXX_
96