WPSEntry.h
Go to the documentation of this file.
/* libwps
* Version: MPL 2.0 / LGPLv2.1+
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Major Contributor(s):
* Copyright (C) 2009, 2011 Alonso Laurent (alonso@loria.fr)
* Copyright (C) 2006, 2007 Andrew Ziem
* Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
* Copyright (C) 2004 Marc Maurer (uwog@uwog.net)
* Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
*
* For minor contributions see the git repository.
*
* Alternatively, the contents of this file may be used under the terms
* of the GNU Lesser General Public License Version 2.1 or later
* (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
* applicable instead of those above.
*
* For further information visit http://libwps.sourceforge.net
*/
#ifndef WPS_ENTRY_H
#define WPS_ENTRY_H
#include <ostream>
#include <string>
class WPSEntry
{
public:
WPSEntry() : m_begin(-1), m_length(-1), m_type(""), m_name(""), m_id(-1), m_parsed(false), m_extra("") {}
virtual ~WPSEntry() {}
void setBegin(long off)
{
m_begin = off;
}
void setLength(long l)
{
m_length = l;
}
void setEnd(long e)
{
m_length = e-m_begin;
}
long begin() const
{
return m_begin;
}
long end() const
{
return m_begin+m_length;
}
long length() const
{
return m_length;
}
bool valid(bool checkId = false) const
{
if (m_begin < 0 || m_length <= 0)
return false;
if (checkId && m_id < 0)
return false;
return true;
}
bool operator==(const WPSEntry &a) const
{
if (m_begin != a.m_begin) return false;
if (m_length != a.m_length) return false;
if (m_id != a. m_id) return false;
if (m_type != a.m_type) return false;
if (m_name != a.m_name) return false;
return true;
}
bool operator!=(const WPSEntry &a) const
{
return !operator==(a);
}
bool isParsed() const
{
return m_parsed;
}
void setParsed(bool ok=true) const
{
m_parsed = ok;
}
void setType(std::string const tp)
{
m_type=tp;
}
std::string const &type() const
{
return m_type;
}
bool hasType(std::string const tp) const
{
return m_type == tp;
}
void setName(std::string const &nam)
{
m_name=nam;
}
std::string const &name() const
{
return m_name;
}
bool hasName(std::string const &nam) const
{
return m_name == nam;
}
int id() const
{
return m_id;
}
void setId(int i)
{
m_id = i;
}
std::string const &extra() const
{
return m_extra;
}
void setExtra(std::string const &s)
{
m_extra = s;
}
friend std::ostream &operator<< (std::ostream &o, WPSEntry const &ent)
{
o << ent.m_type;
if (ent.m_name.length()) o << "|" << ent.m_name;
if (ent.m_id >= 0) o << "[" << ent.m_id << "]";
if (ent.m_extra.length()) o << "[" << ent.m_extra << "]";
return o;
}
protected:
long m_begin , m_length ;
std::string m_type;
std::string m_name;
int m_id;
mutable bool m_parsed;
std::string m_extra;
};
#endif
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: