Coverage Report

Created: 2026-07-20 07:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libmwaw/src/lib/NisusWrtStruct.hxx
Line
Count
Source
1
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2
3
/* libmwaw
4
* Version: MPL 2.0 / LGPLv2+
5
*
6
* The contents of this file are subject to the Mozilla Public License Version
7
* 2.0 (the "License"); you may not use this file except in compliance with
8
* the License or as specified alternatively below. You may obtain a copy of
9
* the License at http://www.mozilla.org/MPL/
10
*
11
* Software distributed under the License is distributed on an "AS IS" basis,
12
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13
* for the specific language governing rights and limitations under the
14
* License.
15
*
16
* Major Contributor(s):
17
* Copyright (C) 2002 William Lachance (wrlach@gmail.com)
18
* Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
19
* Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
20
* Copyright (C) 2006, 2007 Andrew Ziem
21
* Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
22
*
23
*
24
* All Rights Reserved.
25
*
26
* For minor contributions see the git repository.
27
*
28
* Alternatively, the contents of this file may be used under the terms of
29
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
30
* in which case the provisions of the LGPLv2+ are applicable
31
* instead of those above.
32
*/
33
34
#ifndef NISUS_WRT_STRUCT
35
#  define NISUS_WRT_STRUCT
36
37
#include <iostream>
38
#include <vector>
39
40
#include "libmwaw_internal.hxx"
41
42
#include "MWAWEntry.hxx"
43
44
class NisusWrtParser;
45
46
/** a namespace used to regroup the different structure used to parse a Nisus File */
47
namespace NisusWrtStruct
48
{
49
/** the different zone */
50
enum ZoneType : unsigned { Z_Main=0, Z_Footnote, Z_HeaderFooter };
51
52
/** the different variable type */
53
enum VariableType { V_None=0, V_Numbering, V_Variable, V_Version };
54
55
/** a position */
56
struct Position {
57
  //! the constructor
58
  Position()
59
124k
    : m_paragraph(0)
60
124k
    , m_word(0)
61
124k
    , m_char(0)
62
124k
  {
63
124k
  }
64
  //! operator<<: prints data in form "XxYxZ"
65
  friend std::ostream &operator<< (std::ostream &o, Position const &pos);
66
67
  //! operator==
68
  bool operator==(Position const &p2) const
69
0
  {
70
0
    return cmp(p2)==0;
71
0
  }
72
  //! operator!=
73
  bool operator!=(Position const &p2) const
74
0
  {
75
0
    return cmp(p2)!=0;
76
0
  }
77
  //! a small compare operator
78
  int cmp(Position const &p2) const
79
4.09M
  {
80
4.09M
    if (m_paragraph < p2.m_paragraph) return -1;
81
3.83M
    if (m_paragraph > p2.m_paragraph) return 1;
82
1.87M
    if (m_word < p2.m_word) return -1;
83
1.85M
    if (m_word > p2.m_word) return 1;
84
1.40M
    if (m_char < p2.m_char) return -1;
85
1.39M
    if (m_char > p2.m_char) return 1;
86
1.01M
    return 0;
87
1.39M
  }
88
  /** the paragraph */
89
  int m_paragraph;
90
  /** the word */
91
  int m_word;
92
  /** the character position */
93
  int m_char;
94
95
  //! a comparaison structure used to sort the position
96
  struct Compare {
97
    //! comparaison function
98
    bool operator()(Position const &p1, Position const &p2) const
99
1.88M
    {
100
1.88M
      return p1.cmp(p2) < 0;
101
1.88M
    }
102
  };
103
};
104
105
////////////////////////////////////////
106
// Internal: low level
107
108
/** Internal: low level a structure helping to store the footnote information */
109
struct FootnoteInfo {
110
  //! constructor
111
  FootnoteInfo()
112
24.6k
    : m_flags(0)
113
24.6k
    , m_distToDocument(5)
114
24.6k
    , m_distSeparator(36)
115
24.6k
    , m_separatorLength(108)
116
24.6k
    , m_unknown(0)
117
24.6k
  {
118
24.6k
  }
119
  //! operator<<: prints data
120
  friend std::ostream &operator<< (std::ostream &o, FootnoteInfo const &fnote);
121
122
  //! returns true if we have endnote
123
  bool endNotes() const
124
0
  {
125
0
    return (m_flags&0x8)!=0;
126
0
  }
127
  //! returns true if we have to reset index at the beginning of a page
128
  bool resetNumberOnNewPage() const
129
684
  {
130
684
    return (m_flags&0x8)==0 && (m_flags&0x10);
131
684
  }
132
  //! the footnote flags
133
  int m_flags;
134
  //! the distance between the footnote and the document
135
  int m_distToDocument;
136
  //! the distance between two footnotes ( or between a footnote and the line sep)
137
  int m_distSeparator;
138
  //! the separator length
139
  int m_separatorLength;
140
  //! a unknown value
141
  int m_unknown;
142
};
143
144
/** Internal: low level a structure helping to read recursifList */
145
struct RecursifData {
146
  struct Node;
147
  struct Info;
148
  //! constructor
149
  explicit RecursifData(NisusWrtStruct::ZoneType zone, NisusWrtStruct::VariableType vType=NisusWrtStruct::V_None, int level=0)
150
19.8k
    : m_info(new Info(zone, vType))
151
19.8k
    , m_level(level)
152
19.8k
    , m_childList()
153
19.8k
  {
154
19.8k
  }
155
  //! copy constructor
156
  RecursifData(RecursifData const &orig)
157
42.2k
    : m_info(orig.m_info)
158
42.2k
    , m_level(-1)
159
42.2k
    , m_childList()
160
42.2k
  {
161
42.2k
  }
162
  //! copy operator
163
  RecursifData &operator=(RecursifData const &orig)
164
0
  {
165
0
    if (this != &orig) {
166
0
      m_info = orig.m_info;
167
0
      m_level = orig.m_level;
168
0
      m_childList = orig.m_childList;
169
0
    }
170
0
    return *this;
171
0
  }
172
  //! read the data
173
  bool read(NisusWrtParser &parser, MWAWEntry const &entry);
174
175
  //! zone information
176
  std::shared_ptr<Info> m_info;
177
  //! the node level
178
  int m_level;
179
  //! the list of data entry
180
  std::vector<Node> m_childList;
181
182
  //! the zone information
183
  struct Info {
184
    //! the constructor
185
    explicit Info(NisusWrtStruct::ZoneType zType, NisusWrtStruct::VariableType vType=NisusWrtStruct::V_None)
186
19.8k
      : m_zoneType(zType)
187
19.8k
      , m_variableType(vType)
188
19.8k
    {
189
19.8k
    }
190
    //! the zone id
191
    NisusWrtStruct::ZoneType m_zoneType;
192
    //! the variable type
193
    NisusWrtStruct::VariableType m_variableType;
194
  };
195
  //! the data data
196
  struct Node {
197
    //! constructor
198
    Node()
199
269k
      : m_type(0)
200
269k
      , m_entry()
201
269k
      , m_data()
202
269k
    {
203
269k
    }
204
    //! returns true if the node is a final node
205
    bool isLeaf() const
206
210k
    {
207
210k
      return !m_data;
208
210k
    }
209
210
    //! the variable type
211
    int m_type;
212
    //! the entry
213
    MWAWEntry m_entry;
214
    //! the recursif data
215
    std::shared_ptr<RecursifData> m_data;
216
  };
217
};
218
}
219
220
#endif
221
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: