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