WPSEntry.h
Go to the documentation of this file.
00001 /* libwps
00002  * Version: MPL 2.0 / LGPLv2.1+
00003  *
00004  * This Source Code Form is subject to the terms of the Mozilla Public
00005  * License, v. 2.0. If a copy of the MPL was not distributed with this
00006  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
00007  *
00008  * Major Contributor(s):
00009  * Copyright (C) 2009, 2011 Alonso Laurent (alonso@loria.fr)
00010  * Copyright (C) 2006, 2007 Andrew Ziem
00011  * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
00012  * Copyright (C) 2004 Marc Maurer (uwog@uwog.net)
00013  * Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
00014  *
00015  * For minor contributions see the git repository.
00016  *
00017  * Alternatively, the contents of this file may be used under the terms
00018  * of the GNU Lesser General Public License Version 2.1 or later
00019  * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
00020  * applicable instead of those above.
00021  *
00022  * For further information visit http://libwps.sourceforge.net
00023  */
00024 
00025 #ifndef WPS_ENTRY_H
00026 #define WPS_ENTRY_H
00027 
00028 #include <ostream>
00029 #include <string>
00030 
00037 class WPSEntry
00038 {
00039 public:
00041         WPSEntry() : m_begin(-1), m_length(-1), m_type(""), m_name(""), m_id(-1), m_parsed(false), m_extra("") {}
00042 
00043         virtual ~WPSEntry() {}
00044 
00046         void setBegin(long off)
00047         {
00048                 m_begin = off;
00049         }
00051         void setLength(long l)
00052         {
00053                 m_length = l;
00054         }
00056         void setEnd(long e)
00057         {
00058                 m_length = e-m_begin;
00059         }
00060 
00062         long begin() const
00063         {
00064                 return m_begin;
00065         }
00067         long end() const
00068         {
00069                 return m_begin+m_length;
00070         }
00072         long length() const
00073         {
00074                 return m_length;
00075         }
00076 
00078         bool valid(bool checkId = false) const
00079         {
00080                 if (m_begin < 0 || m_length <= 0)
00081                         return false;
00082                 if (checkId && m_id < 0)
00083                         return false;
00084                 return true;
00085         }
00086 
00088         bool operator==(const WPSEntry &a) const
00089         {
00090                 if (m_begin != a.m_begin) return false;
00091                 if (m_length != a.m_length) return false;
00092                 if (m_id != a. m_id) return false;
00093                 if (m_type != a.m_type) return false;
00094                 if (m_name != a.m_name) return false;
00095                 return true;
00096         }
00098         bool operator!=(const WPSEntry &a) const
00099         {
00100                 return !operator==(a);
00101         }
00102 
00104         bool isParsed() const
00105         {
00106                 return m_parsed;
00107         }
00109         void setParsed(bool ok=true) const
00110         {
00111                 m_parsed = ok;
00112         }
00113 
00115         void setType(std::string const &tp)
00116         {
00117                 m_type=tp;
00118         }
00120         std::string const &type() const
00121         {
00122                 return m_type;
00123         }
00125         bool hasType(std::string const &tp) const
00126         {
00127                 return m_type == tp;
00128         }
00129 
00131         void setName(std::string const &nam)
00132         {
00133                 m_name=nam;
00134         }
00136         std::string const &name() const
00137         {
00138                 return m_name;
00139         }
00141         bool hasName(std::string const &nam) const
00142         {
00143                 return m_name == nam;
00144         }
00145 
00147         int id() const
00148         {
00149                 return m_id;
00150         }
00152         void setId(int i)
00153         {
00154                 m_id = i;
00155         }
00156 
00158         std::string const &extra() const
00159         {
00160                 return m_extra;
00161         }
00163         void setExtra(std::string const &s)
00164         {
00165                 m_extra = s;
00166         }
00167         friend std::ostream &operator<< (std::ostream &o, WPSEntry const &ent)
00168         {
00169                 o << ent.m_type;
00170                 if (ent.m_name.length()) o << "|" << ent.m_name;
00171                 if (ent.m_id >= 0) o << "[" << ent.m_id << "]";
00172                 if (ent.m_extra.length()) o << "[" << ent.m_extra << "]";
00173                 return o;
00174         }
00175 protected:
00176         long m_begin , m_length ;
00177 
00179         std::string m_type;
00181         std::string m_name;
00183         int m_id;
00185         mutable bool m_parsed;
00187         std::string m_extra;
00188 };
00189 
00190 #endif
00191 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */