WNEntry.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 /*
00035  * entry for WriteNow
00036  */
00037 #ifndef WN_MWAW_ENTRY
00038 #  define WN_MWAW_ENTRY
00039 
00040 #include <iostream>
00041 #include <map>
00042 #include <string>
00043 
00044 #include "libmwaw_internal.hxx"
00045 #include "MWAWEntry.hxx"
00046 
00047 struct WNEntry : public MWAWEntry {
00048   WNEntry() : MWAWEntry(), m_fileType(-1) {
00049     for (int i = 0; i < 4; i++) m_val[i] = 0;
00050   }
00052   bool isZoneType() const {
00053     return m_fileType == 4 || m_fileType == 6;
00054   }
00056   bool isZone() const {
00057     return isZoneType() && valid();
00058   }
00060   friend std::ostream &operator<<(std::ostream &o, WNEntry const &entry) {
00061     if (entry.type().length()) {
00062       o << entry.type();
00063       if (entry.id() >= 0) o << "[" << entry.id() << "]";
00064       o << "=";
00065     }
00066     o << "[";
00067     switch(entry.m_fileType) {
00068     case 0x4:
00069       o << "zone,";
00070       break;
00071     case 0x6:
00072       o << "zone2,";
00073       break;
00074     case 0xc:
00075       o << "none/data,";
00076       break;
00077     default:
00078       o << "#type=" << entry.m_fileType << ",";
00079     }
00080     for (int i = 0; i < 4; i++) {
00081       if (entry.m_val[i]) o << "v" << i << "=" << std::hex << entry.m_val[i] << std::dec << ",";
00082     }
00083     o << "],";
00084     return o;
00085   }
00087   int m_fileType;
00089   int m_val[4];
00090 };
00091 
00093 struct WNEntryManager {
00094   WNEntryManager() : m_posMap(), m_typeMap() {}
00095 
00097   WNEntry get(long pos) const {
00098     std::map<long, WNEntry>::const_iterator it = m_posMap.find(pos);
00099     if (it == m_posMap.end())
00100       return WNEntry();
00101     return it->second;
00102   }
00103 
00105   bool add(WNEntry const &entry) {
00106     if (!entry.valid()) return false;
00107     if (m_posMap.find(entry.begin()) != m_posMap.end()) {
00108       MWAW_DEBUG_MSG(("WNEntryManager:add: an entry for this position already exists\n"));
00109       return false;
00110     }
00111     std::map<long, WNEntry>::iterator it =
00112       m_posMap.insert(std::pair<long, WNEntry>(entry.begin(), entry)).first;
00113     m_typeMap.insert
00114     (std::multimap<std::string, WNEntry const *>::value_type(entry.type(), &(it->second)));
00115     return true;
00116   }
00117 
00119   void reset() {
00120     m_posMap.clear();
00121     m_typeMap.clear();
00122   }
00124   std::map<long, WNEntry> m_posMap;
00126   std::multimap<std::string, WNEntry const *> m_typeMap;
00127 };
00128 
00129 #endif