Coverage Report

Created: 2026-09-14 06:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libmwaw/src/lib/MWAWEntry.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 MWAW_ENTRY_H
35
#define MWAW_ENTRY_H
36
37
#include <ostream>
38
#include <string>
39
40
/** \brief  basic class to store an entry in a file
41
 * This contained :
42
 * - its begin and end positions
43
 * - its type, its name and an identificator
44
 * - a flag used to know if the file is or not parsed
45
 */
46
class MWAWEntry
47
{
48
public:
49
  //!constructor
50
  MWAWEntry()
51
5.53G
    : m_begin(-1)
52
5.53G
    , m_length(-1)
53
5.53G
    , m_type("")
54
5.53G
    , m_name("")
55
5.53G
    , m_extra("")
56
5.53G
    , m_id(-1)
57
5.53G
    , m_parsed(false)
58
5.53G
  {
59
5.53G
  }
60
8.64G
  MWAWEntry(MWAWEntry const &)=default;
61
439M
  MWAWEntry &operator=(MWAWEntry const &)=default;
62
127M
  MWAWEntry &operator=(MWAWEntry &&)=default;
63
  //! destructor
64
  virtual ~MWAWEntry();
65
66
  //! sets the begin offset
67
  void setBegin(long off)
68
791M
  {
69
791M
    m_begin = off;
70
791M
  }
71
  //! sets the zone size
72
  void setLength(long l)
73
689M
  {
74
689M
    m_length = l;
75
689M
  }
76
  //! sets the end offset
77
  void setEnd(long off)
78
52.8M
  {
79
52.8M
    m_length = off-m_begin;
80
52.8M
  }
81
82
  //! returns the begin offset
83
  long begin() const
84
660M
  {
85
660M
    return m_begin;
86
660M
  }
87
  //! returns the end offset
88
  long end() const
89
4.36G
  {
90
4.36G
    return m_begin+m_length;
91
4.36G
  }
92
  //! returns the length of the zone
93
  long length() const
94
972M
  {
95
972M
    return m_length;
96
972M
  }
97
98
  //! returns true if the zone length is positive
99
  bool valid() const
100
3.81G
  {
101
3.81G
    return m_begin >= 0 && m_length > 0;
102
3.81G
  }
103
104
  //! basic operator==
105
  bool operator==(const MWAWEntry &a) const
106
1.37M
  {
107
1.37M
    if (m_begin != a.m_begin) return false;
108
1.25M
    if (m_length != a.m_length) return false;
109
1.25M
    if (m_id != a. m_id) return false;
110
1.25M
    if (m_type != a.m_type) return false;
111
1.25M
    if (m_name != a.m_name) return false;
112
1.25M
    return true;
113
1.25M
  }
114
  //! basic operator!=
115
  bool operator!=(const MWAWEntry &a) const
116
1.37M
  {
117
1.37M
    return !operator==(a);
118
1.37M
  }
119
120
  //! a flag to know if the entry was parsed or not
121
  bool isParsed() const
122
29.1M
  {
123
29.1M
    return m_parsed;
124
29.1M
  }
125
  //! sets the flag m_parsed to true or false
126
  void setParsed(bool ok=true) const
127
5.49M
  {
128
5.49M
    m_parsed = ok;
129
5.49M
  }
130
131
  //! sets the type of the entry: BTEP,FDPP, BTEC, FDPC, PLC , TEXT, ...
132
  void setType(std::string const &newType)
133
81.8M
  {
134
81.8M
    m_type=newType;
135
81.8M
  }
136
  //! returns the type of the entry
137
  std::string const &type() const
138
43.6M
  {
139
43.6M
    return m_type;
140
43.6M
  }
141
  //! returns true if the type entry == \a type
142
  bool hasType(std::string const &typ) const
143
7.57M
  {
144
7.57M
    return m_type == typ;
145
7.57M
  }
146
147
  //! sets the name of the entry
148
  void setName(std::string const &nam)
149
2.89M
  {
150
2.89M
    m_name=nam;
151
2.89M
  }
152
  //! name of the entry
153
  std::string const &name() const
154
3.97M
  {
155
3.97M
    return m_name;
156
3.97M
  }
157
  //! checks if the entry name is equal to \a name
158
  bool hasName(std::string const &nam) const
159
269k
  {
160
269k
    return m_name == nam;
161
269k
  }
162
163
  /** \brief returns the id */
164
  int id() const
165
3.68G
  {
166
3.68G
    return m_id;
167
3.68G
  }
168
  //! sets the id
169
  void setId(int newId)
170
176M
  {
171
176M
    m_id = newId;
172
176M
  }
173
174
  //! retrieves the extra string
175
  std::string const &extra() const
176
0
  {
177
0
    return m_extra;
178
0
  }
179
  //! sets the extra string
180
  void setExtra(std::string const &s)
181
10.3M
  {
182
10.3M
    m_extra = s;
183
10.3M
  }
184
185
  friend std::ostream &operator<< (std::ostream &o, MWAWEntry const &ent)
186
0
  {
187
0
    o << ent.m_type;
188
0
    if (ent.m_name.length()) o << "|" << ent.m_name;
189
0
    if (ent.m_id >= 0) o << "[" << ent.m_id << "]";
190
0
    if (ent.m_extra.length()) o << "[" << ent.m_extra << "]";
191
0
    return o;
192
0
  }
193
194
protected:
195
  long m_begin /** the begin of the entry.*/, m_length /** the size of the entry*/;
196
197
  //! the entry type
198
  std::string m_type;
199
  //! the name
200
  std::string m_name;
201
  //! an extra string
202
  std::string m_extra;
203
  //! an identificator
204
  int m_id;
205
  //! a bool to store if the entry is or not parsed
206
  mutable bool m_parsed;
207
};
208
209
#endif
210
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: