WPSEntry.h
Go to the documentation of this file.
1 /* libwps
2  * Copyright (C) 2009, 2011 Alonso Laurent (alonso@loria.fr)
3  * Copyright (C) 2006, 2007 Andrew Ziem
4  * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
5  * Copyright (C) 2004 Marc Maurer (uwog@uwog.net)
6  * Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21  *
22  * For further information visit http://libwps.sourceforge.net
23  */
24 
25 /* "This product is not manufactured, approved, or supported by
26  * Corel Corporation or Corel Corporation Limited."
27  */
28 
29 #ifndef WPS_ENTRY_H
30 #define WPS_ENTRY_H
31 
32 #include <ostream>
33 #include <string>
34 
41 class WPSEntry
42 {
43 public:
45  WPSEntry() : m_begin(-1), m_length(-1), m_type(""), m_name(""), m_id(-1), m_parsed(false), m_extra("") {}
46 
47  virtual ~WPSEntry() {}
48 
50  void setBegin(long off)
51  {
52  m_begin = off;
53  }
55  void setLength(long l)
56  {
57  m_length = l;
58  }
60  void setEnd(long e)
61  {
62  m_length = e-m_begin;
63  }
64 
66  long begin() const
67  {
68  return m_begin;
69  }
71  long end() const
72  {
73  return m_begin+m_length;
74  }
76  long length() const
77  {
78  return m_length;
79  }
80 
82  bool valid(bool checkId = false) const
83  {
84  if (m_begin < 0 || m_length <= 0)
85  return false;
86  if (checkId && m_id < 0)
87  return false;
88  return true;
89  }
90 
92  bool operator==(const WPSEntry &a) const
93  {
94  if (m_begin != a.m_begin) return false;
95  if (m_length != a.m_length) return false;
96  if (m_id != a. m_id) return false;
97  if (m_type != a.m_type) return false;
98  if (m_name != a.m_name) return false;
99  return true;
100  }
102  bool operator!=(const WPSEntry &a) const
103  {
104  return !operator==(a);
105  }
106 
108  bool isParsed() const
109  {
110  return m_parsed;
111  }
113  void setParsed(bool ok=true) const
114  {
115  m_parsed = ok;
116  }
117 
119  void setType(std::string const tp)
120  {
121  m_type=tp;
122  }
124  std::string const &type() const
125  {
126  return m_type;
127  }
129  bool hasType(std::string const tp) const
130  {
131  return m_type == tp;
132  }
133 
135  void setName(std::string const &nam)
136  {
137  m_name=nam;
138  }
140  std::string const &name() const
141  {
142  return m_name;
143  }
145  bool hasName(std::string const &nam) const
146  {
147  return m_name == nam;
148  }
149 
151  int id() const
152  {
153  return m_id;
154  }
156  void setId(int i)
157  {
158  m_id = i;
159  }
160 
162  std::string const &extra() const
163  {
164  return m_extra;
165  }
167  void setExtra(std::string const &s)
168  {
169  m_extra = s;
170  }
171  friend std::ostream &operator<< (std::ostream &o, WPSEntry const &ent)
172  {
173  o << ent.m_type;
174  if (ent.m_name.length()) o << "|" << ent.m_name;
175  if (ent.m_id >= 0) o << "[" << ent.m_id << "]";
176  if (ent.m_extra.length()) o << "[" << ent.m_extra << "]";
177  return o;
178  }
179 protected:
180  long m_begin , m_length ;
181 
183  std::string m_type;
185  std::string m_name;
187  int m_id;
189  mutable bool m_parsed;
191  std::string m_extra;
192 };
193 
194 #endif
195 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:

Generated on Wed Aug 8 2012 16:07:57 for libwps by doxygen 1.8.1.2