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 filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:

Generated on Sun May 26 2013 20:03:13 for libwps by doxygen 1.8.3.1