Coverage Report

Created: 2026-06-13 06:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libwps/src/lib/WPSEntry.h
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2
/* libwps
3
 * Version: MPL 2.0 / LGPLv2.1+
4
 *
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/.
8
 *
9
 * Major Contributor(s):
10
 * Copyright (C) 2009, 2011 Alonso Laurent (alonso@loria.fr)
11
 * Copyright (C) 2006, 2007 Andrew Ziem
12
 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
13
 * Copyright (C) 2004 Marc Maurer (uwog@uwog.net)
14
 * Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
15
 *
16
 * For minor contributions see the git repository.
17
 *
18
 * Alternatively, the contents of this file may be used under the terms
19
 * of the GNU Lesser General Public License Version 2.1 or later
20
 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
21
 * applicable instead of those above.
22
 *
23
 * For further information visit http://libwps.sourceforge.net
24
 */
25
26
#ifndef WPS_ENTRY_H
27
#define WPS_ENTRY_H
28
29
#include <ostream>
30
#include <string>
31
32
/** \brief  basic class to store an entry in a file
33
 * This contained :
34
 * - its begin and end positions
35
 * - its type, its name and an identificator
36
 * - a flag used to know if the file is or not parsed
37
 */
38
class WPSEntry
39
{
40
public:
41
  //!constructor
42
  WPSEntry()
43
66.7M
    : m_begin(-1)
44
66.7M
    , m_length(-1)
45
66.7M
    , m_type("")
46
66.7M
    , m_name("")
47
66.7M
    , m_id(-1)
48
66.7M
    , m_parsed(false)
49
66.7M
    , m_extra("") {}
50
43.1M
  WPSEntry(WPSEntry const &)=default;
51
36.3M
  WPSEntry(WPSEntry &&)=default;
52
1.63M
  WPSEntry &operator=(WPSEntry const &)=default;
53
3.30M
  WPSEntry &operator=(WPSEntry &&)=default;
54
  //! destructor
55
  virtual ~WPSEntry();
56
  //! sets the begin offset
57
  void setBegin(long off)
58
51.0M
  {
59
51.0M
    m_begin = off;
60
51.0M
  }
61
  //! sets the zone size
62
  void setLength(long l)
63
45.1M
  {
64
45.1M
    m_length = l;
65
45.1M
  }
66
  //! sets the end offset
67
  void setEnd(long e)
68
10.6M
  {
69
10.6M
    m_length = e-m_begin;
70
10.6M
  }
71
72
  //! returns the begin offset
73
  long begin() const
74
738M
  {
75
738M
    return m_begin;
76
738M
  }
77
  //! returns the end offset
78
  long end() const
79
858M
  {
80
858M
    return m_begin+m_length;
81
858M
  }
82
  //! returns the length of the zone
83
  long length() const
84
70.1M
  {
85
70.1M
    return m_length;
86
70.1M
  }
87
88
  //! returns true if the zone length is positive
89
  bool valid(bool checkId = false) const
90
7.02M
  {
91
7.02M
    if (m_begin < 0 || m_length <= 0)
92
4.83M
      return false;
93
2.19M
    if (checkId && m_id < 0)
94
0
      return false;
95
2.19M
    return true;
96
2.19M
  }
97
98
  //! basic operator==
99
  bool operator==(const WPSEntry &a) const
100
4.31M
  {
101
4.31M
    if (m_begin != a.m_begin) return false;
102
14.9k
    if (m_length != a.m_length) return false;
103
13.5k
    if (m_id != a. m_id) return false;
104
13.1k
    if (m_type != a.m_type) return false;
105
13.1k
    if (m_name != a.m_name) return false;
106
13.1k
    return true;
107
13.1k
  }
108
  //! basic operator!=
109
  bool operator!=(const WPSEntry &a) const
110
27.4k
  {
111
27.4k
    return !operator==(a);
112
27.4k
  }
113
114
  //! a flag to know if the entry was parsed or not
115
  bool isParsed() const
116
90.5k
  {
117
90.5k
    return m_parsed;
118
90.5k
  }
119
  //! sets the flag m_parsed to true or false
120
  void setParsed(bool ok=true) const
121
6.31M
  {
122
6.31M
    m_parsed = ok;
123
6.31M
  }
124
125
  //! sets the type of the entry: BTEP,FDPP, BTEC, FDPC, PLC , TEXT, ...
126
  void setType(std::string const &tp)
127
42.7M
  {
128
42.7M
    m_type=tp;
129
42.7M
  }
130
  //! returns the type of the entry
131
  std::string const &type() const
132
4.35M
  {
133
4.35M
    return m_type;
134
4.35M
  }
135
  //! returns true if the type entry == \a type
136
  bool hasType(std::string const &tp) const
137
18.8M
  {
138
18.8M
    return m_type == tp;
139
18.8M
  }
140
141
  //! sets the name of the entry
142
  void setName(std::string const &nam)
143
42.6M
  {
144
42.6M
    m_name=nam;
145
42.6M
  }
146
  //! name of the entry
147
  std::string const &name() const
148
6.37M
  {
149
6.37M
    return m_name;
150
6.37M
  }
151
  //! checks if the entry name is equal to \a name
152
  bool hasName(std::string const &nam) const
153
11.1M
  {
154
11.1M
    return m_name == nam;
155
11.1M
  }
156
157
  /** \brief returns the entry id */
158
  int id() const
159
50.4M
  {
160
50.4M
    return m_id;
161
50.4M
  }
162
  //! sets the id
163
  void setId(int i)
164
44.8M
  {
165
44.8M
    m_id = i;
166
44.8M
  }
167
168
  //! retrieves the extra string
169
  std::string const &extra() const
170
167
  {
171
167
    return m_extra;
172
167
  }
173
  //! sets the extra string
174
  void setExtra(std::string const &s)
175
98.5k
  {
176
98.5k
    m_extra = s;
177
98.5k
  }
178
  friend std::ostream &operator<< (std::ostream &o, WPSEntry const &ent)
179
0
  {
180
0
    o << ent.m_type;
181
0
    if (ent.m_name.length()) o << "|" << ent.m_name;
182
0
    if (ent.m_id >= 0) o << "[" << ent.m_id << "]";
183
0
    if (ent.m_extra.length()) o << "[" << ent.m_extra << "]";
184
0
    return o;
185
0
  }
186
protected:
187
  long m_begin /** the begin of the entry.*/, m_length /** the size of the entry*/;
188
189
  //! the entry type
190
  std::string m_type;
191
  //! the name
192
  std::string m_name;
193
  //! the identificator
194
  int m_id;
195
  //! a bool to store if the entry is or not parsed
196
  mutable bool m_parsed;
197
  //! an extra string
198
  std::string m_extra;
199
};
200
201
#endif
202
/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */