00001 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */ 00002 00003 /* libmwaw 00004 * Version: MPL 2.0 / LGPLv2+ 00005 * 00006 * The contents of this file are subject to the Mozilla Public License Version 00007 * 2.0 (the "License"); you may not use this file except in compliance with 00008 * the License or as specified alternatively below. You may obtain a copy of 00009 * the License at http://www.mozilla.org/MPL/ 00010 * 00011 * Software distributed under the License is distributed on an "AS IS" basis, 00012 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 00013 * for the specific language governing rights and limitations under the 00014 * License. 00015 * 00016 * Major Contributor(s): 00017 * Copyright (C) 2002 William Lachance (wrlach@gmail.com) 00018 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net) 00019 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch) 00020 * Copyright (C) 2006, 2007 Andrew Ziem 00021 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr) 00022 * 00023 * 00024 * All Rights Reserved. 00025 * 00026 * For minor contributions see the git repository. 00027 * 00028 * Alternatively, the contents of this file may be used under the terms of 00029 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), 00030 * in which case the provisions of the LGPLv2+ are applicable 00031 * instead of those above. 00032 */ 00033 00034 #ifndef MWAW_ENTRY_H 00035 #define MWAW_ENTRY_H 00036 00037 #include <ostream> 00038 #include <string> 00039 00046 class MWAWEntry 00047 { 00048 public: 00050 MWAWEntry() : m_begin(-1), m_length(-1), m_type(""), m_name(""), m_id(-1), m_parsed(false), m_extra("") {} 00051 00052 virtual ~MWAWEntry() {} 00053 00055 void setBegin(long off) { 00056 m_begin = off; 00057 } 00059 void setLength(long l) { 00060 m_length = l; 00061 } 00063 void setEnd(long off) { 00064 m_length = off-m_begin; 00065 } 00066 00068 long begin() const { 00069 return m_begin; 00070 } 00072 long end() const { 00073 return m_begin+m_length; 00074 } 00076 long length() const { 00077 return m_length; 00078 } 00079 00081 bool valid() const { 00082 return m_begin >= 0 && m_length > 0; 00083 } 00084 00086 bool operator==(const MWAWEntry &a) const { 00087 if (m_begin != a.m_begin) return false; 00088 if (m_length != a.m_length) return false; 00089 if (m_id != a. m_id) return false; 00090 if (m_type != a.m_type) return false; 00091 if (m_name != a.m_name) return false; 00092 return true; 00093 } 00095 bool operator!=(const MWAWEntry &a) const { 00096 return !operator==(a); 00097 } 00098 00100 bool isParsed() const { 00101 return m_parsed; 00102 } 00104 void setParsed(bool ok=true) const { 00105 m_parsed = ok; 00106 } 00107 00109 void setType(std::string const &newType) { 00110 m_type=newType; 00111 } 00113 std::string const &type() const { 00114 return m_type; 00115 } 00117 bool hasType(std::string const &typ) const { 00118 return m_type == typ; 00119 } 00120 00122 void setName(std::string const &nam) { 00123 m_name=nam; 00124 } 00126 std::string const &name() const { 00127 return m_name; 00128 } 00130 bool hasName(std::string const &nam) const { 00131 return m_name == nam; 00132 } 00133 00135 int id() const { 00136 return m_id; 00137 } 00139 void setId(int newId) { 00140 m_id = newId; 00141 } 00142 00144 std::string const &extra() const { 00145 return m_extra; 00146 } 00148 void setExtra(std::string const &s) { 00149 m_extra = s; 00150 } 00151 00152 friend std::ostream &operator<< (std::ostream &o, MWAWEntry const &ent) { 00153 o << ent.m_type; 00154 if (ent.m_name.length()) o << "|" << ent.m_name; 00155 if (ent.m_id >= 0) o << "[" << ent.m_id << "]"; 00156 if (ent.m_extra.length()) o << "[" << ent.m_extra << "]"; 00157 return o; 00158 } 00159 00160 protected: 00161 long m_begin , m_length ; 00162 00164 std::string m_type; 00166 std::string m_name; 00168 int m_id; 00170 mutable bool m_parsed; 00172 std::string m_extra; 00173 }; 00174 00175 #endif 00176 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: