WPSEntry.h
Go to the documentation of this file.
00001 /* libwps
00002  * Copyright (C) 2009, 2011 Alonso Laurent (alonso@loria.fr)
00003  * Copyright (C) 2006, 2007 Andrew Ziem
00004  * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
00005  * Copyright (C) 2004 Marc Maurer (uwog@uwog.net)
00006  * Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Library General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2 of the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Library General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Library General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
00021  *
00022  * For further information visit http://libwps.sourceforge.net
00023  */
00024 
00025 /* "This product is not manufactured, approved, or supported by
00026  * Corel Corporation or Corel Corporation Limited."
00027  */
00028 
00029 #ifndef WPS_ENTRY_H
00030 #define WPS_ENTRY_H
00031 
00032 #include <ostream>
00033 #include <string>
00034 
00041 class WPSEntry
00042 {
00043 public:
00045         WPSEntry() : m_begin(-1), m_length(-1), m_type(""), m_name(""), m_id(-1), m_parsed(false), m_extra("") {}
00046 
00047         virtual ~WPSEntry() {}
00048 
00050         void setBegin(long off)
00051         {
00052                 m_begin = off;
00053         }
00055         void setLength(long l)
00056         {
00057                 m_length = l;
00058         }
00060         void setEnd(long e)
00061         {
00062                 m_length = e-m_begin;
00063         }
00064 
00066         long begin() const
00067         {
00068                 return m_begin;
00069         }
00071         long end() const
00072         {
00073                 return m_begin+m_length;
00074         }
00076         long length() const
00077         {
00078                 return m_length;
00079         }
00080 
00082         bool valid(bool checkId = false) const
00083         {
00084                 if (m_begin < 0 || m_length <= 0)
00085                         return false;
00086                 if (checkId && m_id < 0)
00087                         return false;
00088                 return true;
00089         }
00090 
00092         bool operator==(const WPSEntry &a) const
00093         {
00094                 if (m_begin != a.m_begin) return false;
00095                 if (m_length != a.m_length) return false;
00096                 if (m_id != a. m_id) return false;
00097                 if (m_type != a.m_type) return false;
00098                 if (m_name != a.m_name) return false;
00099                 return true;
00100         }
00102         bool operator!=(const WPSEntry &a) const
00103         {
00104                 return !operator==(a);
00105         }
00106 
00108         bool isParsed() const
00109         {
00110                 return m_parsed;
00111         }
00113         void setParsed(bool ok=true) const
00114         {
00115                 m_parsed = ok;
00116         }
00117 
00119         void setType(std::string const tp)
00120         {
00121                 m_type=tp;
00122         }
00124         std::string const &type() const
00125         {
00126                 return m_type;
00127         }
00129         bool hasType(std::string const tp) const
00130         {
00131                 return m_type == tp;
00132         }
00133 
00135         void setName(std::string const &nam)
00136         {
00137                 m_name=nam;
00138         }
00140         std::string const &name() const
00141         {
00142                 return m_name;
00143         }
00145         bool hasName(std::string const &nam) const
00146         {
00147                 return m_name == nam;
00148         }
00149 
00151         int id() const
00152         {
00153                 return m_id;
00154         }
00156         void setId(int i)
00157         {
00158                 m_id = i;
00159         }
00160 
00162         std::string const &extra() const
00163         {
00164                 return m_extra;
00165         }
00167         void setExtra(std::string const &s)
00168         {
00169                 m_extra = s;
00170         }
00171         friend std::ostream &operator<< (std::ostream &o, WPSEntry const &ent)
00172         {
00173                 o << ent.m_type;
00174                 if (ent.m_name.length()) o << "|" << ent.m_name;
00175                 if (ent.m_id >= 0) o << "[" << ent.m_id << "]";
00176                 if (ent.m_extra.length()) o << "[" << ent.m_extra << "]";
00177                 return o;
00178         }
00179 protected:
00180         long m_begin , m_length ;
00181 
00183         std::string m_type;
00185         std::string m_name;
00187         int m_id;
00189         mutable bool m_parsed;
00191         std::string m_extra;
00192 };
00193 
00194 #endif
00195 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: