NSStruct.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 NS_STRUCT
00035 #  define NS_STRUCT
00036 
00037 #include <iostream>
00038 #include <vector>
00039 
00040 #include "libmwaw_internal.hxx"
00041 
00042 #include "MWAWEntry.hxx"
00043 
00044 class NSParser;
00045 
00047 namespace NSStruct
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   }
00061   friend std::ostream &operator<< (std::ostream &o, Position const &pos);
00062 
00064   bool operator==(Position const &p2) const {
00065     return cmp(p2)==0;
00066   }
00068   bool operator!=(Position const &p2) const {
00069     return cmp(p2)!=0;
00070   }
00072   int cmp(Position const &p2) const {
00073     if (m_paragraph < p2.m_paragraph) return -1;
00074     if (m_paragraph > p2.m_paragraph) return 1;
00075     if (m_word < p2.m_word) return -1;
00076     if (m_word > p2.m_word) return 1;
00077     if (m_char < p2.m_char) return -1;
00078     if (m_char > p2.m_char) return 1;
00079     return 0;
00080   }
00082   int m_paragraph;
00084   int m_word;
00086   int m_char;
00087 
00089   struct Compare {
00091     bool operator()(Position const &p1, Position const &p2) const {
00092       return p1.cmp(p2) < 0;
00093     }
00094   };
00095 };
00096 
00098 // Internal: low level
00099 
00101 struct FootnoteInfo {
00103   FootnoteInfo() : m_flags(0), m_distToDocument(5), m_distSeparator(36),
00104     m_separatorLength(108), m_unknown(0) {
00105   }
00107   friend std::ostream &operator<< (std::ostream &o, FootnoteInfo const &fnote);
00108 
00110   bool endNotes() const {
00111     return (m_flags&0x8);
00112   }
00114   bool resetNumberOnNewPage() const {
00115     return (m_flags&0x8)==0 && (m_flags&0x10);
00116   }
00118   int m_flags;
00120   int m_distToDocument;
00122   int m_distSeparator;
00124   int m_separatorLength;
00126   int m_unknown;
00127 };
00128 
00130 struct RecursifData {
00131   struct Node;
00132   struct Info;
00134   RecursifData(NSStruct::ZoneType zone, NSStruct::VariableType vType=NSStruct::V_None, int level=0) :
00135     m_info(new Info(zone, vType)), m_level(level), m_childList() {
00136   }
00138   RecursifData(RecursifData const &orig) :
00139     m_info(orig.m_info), m_level(-1), m_childList() {
00140   }
00142   RecursifData &operator=(RecursifData const &orig) {
00143     if (this != &orig) {
00144       m_info = orig.m_info;
00145       m_level = orig.m_level;
00146       m_childList = orig.m_childList;
00147     }
00148     return *this;
00149   }
00151   bool read(NSParser &parser, MWAWEntry const &entry);
00152 
00154   shared_ptr<Info> m_info;
00156   int m_level;
00158   std::vector<Node> m_childList;
00159 
00161   struct Info {
00163     Info(NSStruct::ZoneType zType, NSStruct::VariableType vType=NSStruct::V_None) :
00164       m_zoneType(zType), m_variableType(vType) {
00165     }
00167     NSStruct::ZoneType m_zoneType;
00169     NSStruct::VariableType m_variableType;
00170   };
00172   struct Node {
00174     Node() : m_type(0), m_entry(), m_data() {
00175     }
00177     bool isLeaf() const {
00178       return !m_data;
00179     }
00180 
00182     int m_type;
00184     MWAWEntry m_entry;
00186     shared_ptr<RecursifData> m_data;
00187   };
00188 };
00189 }
00190 
00191 #endif
00192 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: