00001 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */ 00002 00003 /* libstaroffice 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 STOFF_ENTRY_H 00035 #define STOFF_ENTRY_H 00036 00037 #include <ostream> 00038 #include <string> 00039 00046 class STOFFEntry 00047 { 00048 public: 00050 STOFFEntry() : m_begin(-1), m_length(-1), m_type(""), m_name(""), m_id(-1), m_parsed(false), m_extra("") {} 00051 00052 virtual ~STOFFEntry(); 00053 00055 void setBegin(long off) 00056 { 00057 m_begin = off; 00058 } 00060 void setLength(long l) 00061 { 00062 m_length = l; 00063 } 00065 void setEnd(long off) 00066 { 00067 m_length = off-m_begin; 00068 } 00069 00071 long begin() const 00072 { 00073 return m_begin; 00074 } 00076 long end() const 00077 { 00078 return m_begin+m_length; 00079 } 00081 long length() const 00082 { 00083 return m_length; 00084 } 00085 00087 bool valid() const 00088 { 00089 return m_begin >= 0 && m_length > 0; 00090 } 00091 00093 bool operator==(const STOFFEntry &a) const 00094 { 00095 if (m_begin != a.m_begin) return false; 00096 if (m_length != a.m_length) return false; 00097 if (m_id != a. m_id) return false; 00098 if (m_type != a.m_type) return false; 00099 if (m_name != a.m_name) return false; 00100 return true; 00101 } 00103 bool operator!=(const STOFFEntry &a) const 00104 { 00105 return !operator==(a); 00106 } 00107 00109 bool isParsed() const 00110 { 00111 return m_parsed; 00112 } 00114 void setParsed(bool ok=true) const 00115 { 00116 m_parsed = ok; 00117 } 00118 00120 void setType(std::string const &newType) 00121 { 00122 m_type=newType; 00123 } 00125 std::string const &type() const 00126 { 00127 return m_type; 00128 } 00130 bool hasType(std::string const &typ) const 00131 { 00132 return m_type == typ; 00133 } 00134 00136 void setName(std::string const &nam) 00137 { 00138 m_name=nam; 00139 } 00141 std::string const &name() const 00142 { 00143 return m_name; 00144 } 00146 bool hasName(std::string const &nam) const 00147 { 00148 return m_name == nam; 00149 } 00150 00152 int id() const 00153 { 00154 return m_id; 00155 } 00157 void setId(int newId) 00158 { 00159 m_id = newId; 00160 } 00161 00163 std::string const &extra() const 00164 { 00165 return m_extra; 00166 } 00168 void setExtra(std::string const &s) 00169 { 00170 m_extra = s; 00171 } 00172 00173 friend std::ostream &operator<< (std::ostream &o, STOFFEntry const &ent) 00174 { 00175 o << ent.m_type; 00176 if (ent.m_name.length()) o << "|" << ent.m_name; 00177 if (ent.m_id >= 0) o << "[" << ent.m_id << "]"; 00178 if (ent.m_extra.length()) o << "[" << ent.m_extra << "]"; 00179 return o; 00180 } 00181 00182 protected: 00183 long m_begin , m_length ; 00184 00186 std::string m_type; 00188 std::string m_name; 00190 int m_id; 00192 mutable bool m_parsed; 00194 std::string m_extra; 00195 }; 00196 00197 #endif 00198 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: