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