WPSEntry.h
Go to the documentation of this file.
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
39{
40public:
43 : m_begin(-1)
44 , m_length(-1)
45 , m_type("")
46 , m_name("")
47 , m_id(-1)
48 , m_parsed(false)
49 , m_extra("") {}
50 WPSEntry(WPSEntry const &)=default;
51 WPSEntry(WPSEntry &&)=default;
52 WPSEntry &operator=(WPSEntry const &)=default;
55 virtual ~WPSEntry();
57 void setBegin(long off)
58 {
59 m_begin = off;
60 }
61
62 void setLength(long l)
63 {
64 m_length = l;
65 }
66
67 void setEnd(long e)
68 {
69 m_length = e-m_begin;
70 }
71
73 long begin() const
74 {
75 return m_begin;
76 }
77
78 long end() const
79 {
80 return m_begin+m_length;
81 }
82
83 long length() const
84 {
85 return m_length;
86 }
87
89 bool valid(bool checkId = false) const
90 {
91 if (m_begin < 0 || m_length <= 0)
92 return false;
93 if (checkId && m_id < 0)
94 return false;
95 return true;
96 }
97
99 bool operator==(const WPSEntry &a) const
100 {
101 if (m_begin != a.m_begin) return false;
102 if (m_length != a.m_length) return false;
103 if (m_id != a. m_id) return false;
104 if (m_type != a.m_type) return false;
105 if (m_name != a.m_name) return false;
106 return true;
107 }
108
109 bool operator!=(const WPSEntry &a) const
110 {
111 return !operator==(a);
112 }
113
115 bool isParsed() const
116 {
117 return m_parsed;
118 }
119
120 void setParsed(bool ok=true) const
121 {
122 m_parsed = ok;
123 }
124
126 void setType(std::string const &tp)
127 {
128 m_type=tp;
129 }
130
131 std::string const &type() const
132 {
133 return m_type;
134 }
135
136 bool hasType(std::string const &tp) const
137 {
138 return m_type == tp;
139 }
140
142 void setName(std::string const &nam)
143 {
144 m_name=nam;
145 }
146
147 std::string const &name() const
148 {
149 return m_name;
150 }
151
152 bool hasName(std::string const &nam) const
153 {
154 return m_name == nam;
155 }
156
158 int id() const
159 {
160 return m_id;
161 }
162
163 void setId(int i)
164 {
165 m_id = i;
166 }
167
169 std::string const &extra() const
170 {
171 return m_extra;
172 }
173
174 void setExtra(std::string const &s)
175 {
176 m_extra = s;
177 }
178 friend std::ostream &operator<< (std::ostream &o, WPSEntry const &ent)
179 {
180 o << ent.m_type;
181 if (ent.m_name.length()) o << "|" << ent.m_name;
182 if (ent.m_id >= 0) o << "[" << ent.m_id << "]";
183 if (ent.m_extra.length()) o << "[" << ent.m_extra << "]";
184 return o;
185 }
186protected:
188
190 std::string m_type;
192 std::string m_name;
194 int m_id;
196 mutable bool m_parsed;
198 std::string m_extra;
199};
200
201#endif
202/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
void setLength(long l)
sets the zone size
Definition WPSEntry.h:62
std::string const & type() const
returns the type of the entry
Definition WPSEntry.h:131
void setEnd(long e)
sets the end offset
Definition WPSEntry.h:67
void setType(std::string const &tp)
sets the type of the entry: BTEP,FDPP, BTEC, FDPC, PLC , TEXT, ...
Definition WPSEntry.h:126
void setExtra(std::string const &s)
sets the extra string
Definition WPSEntry.h:174
WPSEntry & operator=(WPSEntry const &)=default
bool operator!=(const WPSEntry &a) const
basic operator!=
Definition WPSEntry.h:109
friend std::ostream & operator<<(std::ostream &o, WPSEntry const &ent)
Definition WPSEntry.h:178
int m_id
the identificator
Definition WPSEntry.h:194
long begin() const
returns the begin offset
Definition WPSEntry.h:73
long length() const
returns the length of the zone
Definition WPSEntry.h:83
void setParsed(bool ok=true) const
sets the flag m_parsed to true or false
Definition WPSEntry.h:120
void setId(int i)
sets the id
Definition WPSEntry.h:163
void setBegin(long off)
sets the begin offset
Definition WPSEntry.h:57
WPSEntry(WPSEntry &&)=default
std::string m_type
the entry type
Definition WPSEntry.h:190
long m_length
the size of the entry
Definition WPSEntry.h:187
bool valid(bool checkId=false) const
returns true if the zone length is positive
Definition WPSEntry.h:89
void setName(std::string const &nam)
sets the name of the entry
Definition WPSEntry.h:142
bool hasName(std::string const &nam) const
checks if the entry name is equal to name
Definition WPSEntry.h:152
bool m_parsed
a bool to store if the entry is or not parsed
Definition WPSEntry.h:196
WPSEntry & operator=(WPSEntry &&)=default
WPSEntry(WPSEntry const &)=default
int id() const
returns the entry id
Definition WPSEntry.h:158
std::string const & extra() const
retrieves the extra string
Definition WPSEntry.h:169
virtual ~WPSEntry()
destructor
Definition WPSEntry.cpp:28
long m_begin
the begin of the entry.
Definition WPSEntry.h:187
bool hasType(std::string const &tp) const
returns true if the type entry == type
Definition WPSEntry.h:136
std::string m_name
the name
Definition WPSEntry.h:192
WPSEntry()
constructor
Definition WPSEntry.h:42
bool isParsed() const
a flag to know if the entry was parsed or not
Definition WPSEntry.h:115
std::string m_extra
an extra string
Definition WPSEntry.h:198
long end() const
returns the end offset
Definition WPSEntry.h:78
bool operator==(const WPSEntry &a) const
basic operator==
Definition WPSEntry.h:99
std::string const & name() const
name of the entry
Definition WPSEntry.h:147

Generated on Sat Jul 19 2025 05:24:40 for libwps by doxygen 1.14.0