NisusWrtStruct.hxx
Go to the documentation of this file.
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 NISUS_WRT_STRUCT
00035 #  define NISUS_WRT_STRUCT
00036 
00037 #include <iostream>
00038 #include <vector>
00039 
00040 #include "libmwaw_internal.hxx"
00041 
00042 #include "MWAWEntry.hxx"
00043 
00044 class NisusWrtParser;
00045 
00047 namespace NisusWrtStruct
00048 {
00050 enum ZoneType { Z_Main=0, Z_Footnote, Z_HeaderFooter };
00051 
00053 enum VariableType { V_None=0, V_Numbering, V_Variable, V_Version };
00054 
00056 struct Position {
00058   Position() : m_paragraph(0), m_word(0), m_char(0)
00059   {
00060   }
00062   friend std::ostream &operator<< (std::ostream &o, Position const &pos);
00063 
00065   bool operator==(Position const &p2) const
00066   {
00067     return cmp(p2)==0;
00068   }
00070   bool operator!=(Position const &p2) const
00071   {
00072     return cmp(p2)!=0;
00073   }
00075   int cmp(Position const &p2) const
00076   {
00077     if (m_paragraph < p2.m_paragraph) return -1;
00078     if (m_paragraph > p2.m_paragraph) return 1;
00079     if (m_word < p2.m_word) return -1;
00080     if (m_word > p2.m_word) return 1;
00081     if (m_char < p2.m_char) return -1;
00082     if (m_char > p2.m_char) return 1;
00083     return 0;
00084   }
00086   int m_paragraph;
00088   int m_word;
00090   int m_char;
00091 
00093   struct Compare {
00095     bool operator()(Position const &p1, Position const &p2) const
00096     {
00097       return p1.cmp(p2) < 0;
00098     }
00099   };
00100 };
00101 
00103 // Internal: low level
00104 
00106 struct FootnoteInfo {
00108   FootnoteInfo() : m_flags(0), m_distToDocument(5), m_distSeparator(36),
00109     m_separatorLength(108), m_unknown(0)
00110   {
00111   }
00113   friend std::ostream &operator<< (std::ostream &o, FootnoteInfo const &fnote);
00114 
00116   bool endNotes() const
00117   {
00118     return (m_flags&0x8);
00119   }
00121   bool resetNumberOnNewPage() const
00122   {
00123     return (m_flags&0x8)==0 && (m_flags&0x10);
00124   }
00126   int m_flags;
00128   int m_distToDocument;
00130   int m_distSeparator;
00132   int m_separatorLength;
00134   int m_unknown;
00135 };
00136 
00138 struct RecursifData {
00139   struct Node;
00140   struct Info;
00142   RecursifData(NisusWrtStruct::ZoneType zone, NisusWrtStruct::VariableType vType=NisusWrtStruct::V_None, int level=0) :
00143     m_info(new Info(zone, vType)), m_level(level), m_childList()
00144   {
00145   }
00147   RecursifData(RecursifData const &orig) :
00148     m_info(orig.m_info), m_level(-1), m_childList()
00149   {
00150   }
00152   RecursifData &operator=(RecursifData const &orig)
00153   {
00154     if (this != &orig) {
00155       m_info = orig.m_info;
00156       m_level = orig.m_level;
00157       m_childList = orig.m_childList;
00158     }
00159     return *this;
00160   }
00162   bool read(NisusWrtParser &parser, MWAWEntry const &entry);
00163 
00165   shared_ptr<Info> m_info;
00167   int m_level;
00169   std::vector<Node> m_childList;
00170 
00172   struct Info {
00174     Info(NisusWrtStruct::ZoneType zType, NisusWrtStruct::VariableType vType=NisusWrtStruct::V_None) :
00175       m_zoneType(zType), m_variableType(vType)
00176     {
00177     }
00179     NisusWrtStruct::ZoneType m_zoneType;
00181     NisusWrtStruct::VariableType m_variableType;
00182   };
00184   struct Node {
00186     Node() : m_type(0), m_entry(), m_data()
00187     {
00188     }
00190     bool isLeaf() const
00191     {
00192       return !m_data;
00193     }
00194 
00196     int m_type;
00198     MWAWEntry m_entry;
00200     shared_ptr<RecursifData> m_data;
00201   };
00202 };
00203 }
00204 
00205 #endif
00206 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: