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

Generated on Fri Sep 30 2022 11:47:43 for libwps by doxygen 1.9.5