- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

WPSEntry.h
Go to the documentation of this file.
1 /* libwps
2 * Version: MPL 2.0 / LGPLv2.1+
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 *
8 * Major Contributor(s):
9 * Copyright (C) 2009, 2011 Alonso Laurent (alonso@loria.fr)
10 * Copyright (C) 2006, 2007 Andrew Ziem
11 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
12 * Copyright (C) 2004 Marc Maurer (uwog@uwog.net)
13 * Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
14 *
15 * For minor contributions see the git repository.
16 *
17 * Alternatively, the contents of this file may be used under the terms
18 * of the GNU Lesser General Public License Version 2.1 or later
19 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
20 * applicable instead of those above.
21 *
22 * For further information visit http://libwps.sourceforge.net
23 */
24
25 #ifndef WPS_ENTRY_H
26 #define WPS_ENTRY_H
27
28 #include <ostream>
29 #include <string>
30
37 class WPSEntry
38 {
39 public:
41 WPSEntry() : m_begin(-1), m_length(-1), m_type(""), m_name(""), m_id(-1), m_parsed(false), m_extra("") {}
42
43 virtual ~WPSEntry() {}
44
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 }
175 protected:
176 long m_begin , m_length ;
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: */
WPSEntry::hasType
bool hasType(std::string const &tp) const
returns true if the type entry == type
Definition: WPSEntry.h:125
WPSEntry::id
int id() const
returns the entry id
Definition: WPSEntry.h:147
WPSEntry::operator<<
friend std::ostream & operator<<(std::ostream &o, WPSEntry const &ent)
Definition: WPSEntry.h:167
WPSEntry::m_parsed
bool m_parsed
a bool to store if the entry is or not parsed
Definition: WPSEntry.h:185
WPSEntry::setBegin
void setBegin(long off)
sets the begin offset
Definition: WPSEntry.h:46
WPSEntry::extra
std::string const & extra() const
retrieves the extra string
Definition: WPSEntry.h:158
WPSEntry::length
long length() const
returns the length of the zone
Definition: WPSEntry.h:72
WPSEntry::type
std::string const & type() const
returns the type of the entry
Definition: WPSEntry.h:120
WPSEntry::begin
long begin() const
returns the begin offset
Definition: WPSEntry.h:62
WPSEntry::m_type
std::string m_type
the entry type
Definition: WPSEntry.h:179
WPSEntry::setType
void setType(std::string const &tp)
sets the type of the entry: BTEP,FDPP, BTEC, FDPC, PLC , TEXT, ...
Definition: WPSEntry.h:115
WPSEntry::setParsed
void setParsed(bool ok=true) const
sets the flag m_parsed to true or false
Definition: WPSEntry.h:109
WPSEntry::setId
void setId(int i)
sets the id
Definition: WPSEntry.h:152
WPSEntry::operator!=
bool operator!=(const WPSEntry &a) const
basic operator!=
Definition: WPSEntry.h:98
WPSEntry::m_length
long m_length
the size of the entry
Definition: WPSEntry.h:176
WPSEntry::m_name
std::string m_name
the name
Definition: WPSEntry.h:181
WPSEntry::valid
bool valid(bool checkId=false) const
returns true if the zone length is positive
Definition: WPSEntry.h:78
WPSEntry::m_extra
std::string m_extra
an extra string
Definition: WPSEntry.h:187
WPSEntry::name
std::string const & name() const
name of the entry
Definition: WPSEntry.h:136
WPSEntry::WPSEntry
WPSEntry()
constructor
Definition: WPSEntry.h:41
WPSEntry::operator==
bool operator==(const WPSEntry &a) const
basic operator==
Definition: WPSEntry.h:88
WPSEntry::setExtra
void setExtra(std::string const &s)
sets the extra string
Definition: WPSEntry.h:163
WPSEntry::hasName
bool hasName(std::string const &nam) const
checks if the entry name is equal to name
Definition: WPSEntry.h:141
WPSEntry::m_begin
long m_begin
the begin of the entry.
Definition: WPSEntry.h:176
WPSEntry
basic class to store an entry in a file This contained :
Definition: WPSEntry.h:37
WPSEntry::m_id
int m_id
the identificator
Definition: WPSEntry.h:183
WPSEntry::setName
void setName(std::string const &nam)
sets the name of the entry
Definition: WPSEntry.h:131
WPSEntry::isParsed
bool isParsed() const
a flag to know if the entry was parsed or not
Definition: WPSEntry.h:104
WPSEntry::setEnd
void setEnd(long e)
sets the end offset
Definition: WPSEntry.h:56
WPSEntry::end
long end() const
returns the end offset
Definition: WPSEntry.h:67
WPSEntry::setLength
void setLength(long l)
sets the zone size
Definition: WPSEntry.h:51
WPSEntry::~WPSEntry
virtual ~WPSEntry()
Definition: WPSEntry.h:43