WriteNowEntry.hxx
Go to the documentation of this file.
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
/* libmwaw
* Version: MPL 2.0 / LGPLv2+
*
* The contents of this file are subject to the Mozilla Public License Version
* 2.0 (the "License"); you may not use this file except in compliance with
* the License or as specified alternatively below. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* Major Contributor(s):
* Copyright (C) 2002 William Lachance (wrlach@gmail.com)
* Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
* Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
* Copyright (C) 2006, 2007 Andrew Ziem
* Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
*
*
* All Rights Reserved.
*
* For minor contributions see the git repository.
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
* in which case the provisions of the LGPLv2+ are applicable
* instead of those above.
*/
/*
* entry for WriteNow
*/
#ifndef WRITE_NOW_ENTRY
# define WRITE_NOW_ENTRY
#include <iostream>
#include <map>
#include <string>
#include "libmwaw_internal.hxx"
#include "MWAWEntry.hxx"
struct WriteNowEntry final : public MWAWEntry {
WriteNowEntry()
: MWAWEntry()
, m_fileType(-1)
{
for (auto &val : m_val) val=0;
}
WriteNowEntry(WriteNowEntry const &)=default;
WriteNowEntry &operator=(WriteNowEntry const &)=default;
WriteNowEntry &operator=(WriteNowEntry &&)=default;
~WriteNowEntry() final;
bool isZoneType() const
{
return m_fileType == 4 || m_fileType == 6;
}
bool isZone() const
{
return isZoneType() && valid();
}
friend std::ostream &operator<<(std::ostream &o, WriteNowEntry const &entry)
{
if (entry.type().length()) {
o << entry.type();
if (entry.id() >= 0) o << "[" << entry.id() << "]";
o << "=";
}
o << "[";
switch (entry.m_fileType) {
case 0x4:
o << "zone,";
break;
case 0x6:
o << "zone2,";
break;
case 0xc:
o << "none/data,";
break;
default:
o << "#type=" << entry.m_fileType << ",";
}
for (int i = 0; i < 4; i++) {
if (entry.m_val[i]) o << "v" << i << "=" << std::hex << entry.m_val[i] << std::dec << ",";
}
o << "],";
return o;
}
int m_fileType;
int m_val[4];
};
struct WriteNowEntryManager {
WriteNowEntryManager()
: m_posMap()
, m_typeMap() {}
WriteNowEntry get(long pos) const
{
auto it = m_posMap.find(pos);
if (it == m_posMap.end())
return WriteNowEntry();
return it->second;
}
bool add(WriteNowEntry const &entry)
{
if (!entry.valid()) return false;
if (m_posMap.find(entry.begin()) != m_posMap.end()) {
MWAW_DEBUG_MSG(("WriteNowEntryManager:add: an entry for this position already exists\n"));
return false;
}
auto it = m_posMap.insert(std::pair<long, WriteNowEntry>(entry.begin(), entry)).first;
m_typeMap.insert
(std::multimap<std::string, WriteNowEntry const *>::value_type(entry.type(), &(it->second)));
return true;
}
void reset()
{
m_posMap.clear();
m_typeMap.clear();
}
std::map<long, WriteNowEntry> m_posMap;
std::multimap<std::string, WriteNowEntry const *> m_typeMap;
};
#endif
MWAWEntry.hxx
MWAWEntry::type
std::string const & type() const
returns the type of the entry
Definition MWAWEntry.hxx:137
MWAWEntry::MWAWEntry
MWAWEntry()
constructor
Definition MWAWEntry.hxx:50
MWAWEntry::begin
long begin() const
returns the begin offset
Definition MWAWEntry.hxx:83
MWAWEntry::id
int id() const
returns the id
Definition MWAWEntry.hxx:164
MWAWEntry::valid
bool valid() const
returns true if the zone length is positive
Definition MWAWEntry.hxx:99
libmwaw_internal.hxx
MWAW_DEBUG_MSG
#define MWAW_DEBUG_MSG(M)
Definition libmwaw_internal.hxx:129
WriteNowEntryManager::WriteNowEntryManager
WriteNowEntryManager()
Definition WriteNowEntry.hxx:107
WriteNowEntryManager::m_typeMap
std::multimap< std::string, WriteNowEntry const * > m_typeMap
the list of entries
Definition WriteNowEntry.hxx:143
WriteNowEntryManager::reset
void reset()
reset the data
Definition WriteNowEntry.hxx:135
WriteNowEntryManager::get
WriteNowEntry get(long pos) const
return an entry for a position
Definition WriteNowEntry.hxx:112
WriteNowEntryManager::m_posMap
std::map< long, WriteNowEntry > m_posMap
the list of entries by position
Definition WriteNowEntry.hxx:141
WriteNowEntryManager::add
bool add(WriteNowEntry const &entry)
add a new entry
Definition WriteNowEntry.hxx:121
WriteNowEntry
class to store entry in a WriteNow document
Definition WriteNowEntry.hxx:48
WriteNowEntry::operator<<
friend std::ostream & operator<<(std::ostream &o, WriteNowEntry const &entry)
operator<<
Definition WriteNowEntry.hxx:72
WriteNowEntry::~WriteNowEntry
~WriteNowEntry() final
destructor
Definition WriteNowEntry.cxx:36
WriteNowEntry::m_fileType
int m_fileType
the file entry id
Definition WriteNowEntry.hxx:100
WriteNowEntry::isZone
bool isZone() const
returns true if this is a zone
Definition WriteNowEntry.hxx:67
WriteNowEntry::isZoneType
bool isZoneType() const
returns true if this entry store a zone
Definition WriteNowEntry.hxx:62
WriteNowEntry::WriteNowEntry
WriteNowEntry(WriteNowEntry const &)=default
WriteNowEntry::WriteNowEntry
WriteNowEntry()
construtor
Definition WriteNowEntry.hxx:50
WriteNowEntry::operator=
WriteNowEntry & operator=(WriteNowEntry &&)=default
WriteNowEntry::m_val
int m_val[4]
other values
Definition WriteNowEntry.hxx:102
WriteNowEntry::operator=
WriteNowEntry & operator=(WriteNowEntry const &)=default