WriteNowEntry.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2
3 /* libmwaw
4 * Version: MPL 2.0 / LGPLv2+
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 2.0 (the "License"); you may not use this file except in compliance with
8 * the License or as specified alternatively below. You may obtain a copy of
9 * the License at http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * Major Contributor(s):
17 * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
18 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
19 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
22 *
23 *
24 * All Rights Reserved.
25 *
26 * For minor contributions see the git repository.
27 *
28 * Alternatively, the contents of this file may be used under the terms of
29 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
30 * in which case the provisions of the LGPLv2+ are applicable
31 * instead of those above.
32 */
33
34 /*
35 * entry for WriteNow
36 */
37 #ifndef WRITE_NOW_ENTRY
38 # define WRITE_NOW_ENTRY
39
40 #include <iostream>
41 #include <map>
42 #include <string>
43
44 #include "libmwaw_internal.hxx"
45 #include "MWAWEntry.hxx"
46
48 struct WriteNowEntry final : public MWAWEntry {
50 WriteNowEntry()
51 : MWAWEntry()
52 , m_fileType(-1)
53 {
54 for (auto &val : m_val) val=0;
55 }
57 ~WriteNowEntry() final;
59 bool isZoneType() const
60 {
61 return m_fileType == 4 || m_fileType == 6;
62 }
64 bool isZone() const
65 {
66 return isZoneType() && valid();
67 }
69 friend std::ostream &operator<<(std::ostream &o, WriteNowEntry const &entry)
70 {
71 if (entry.type().length()) {
72 o << entry.type();
73 if (entry.id() >= 0) o << "[" << entry.id() << "]";
74 o << "=";
75 }
76 o << "[";
77 switch (entry.m_fileType) {
78 case 0x4:
79 o << "zone,";
80 break;
81 case 0x6:
82 o << "zone2,";
83 break;
84 case 0xc:
85 o << "none/data,";
86 break;
87 default:
88 o << "#type=" << entry.m_fileType << ",";
89 }
90 for (int i = 0; i < 4; i++) {
91 if (entry.m_val[i]) o << "v" << i << "=" << std::hex << entry.m_val[i] << std::dec << ",";
92 }
93 o << "],";
94 return o;
95 }
97 int m_fileType;
99 int m_val[4];
100 };
101
103 struct WriteNowEntryManager {
104 WriteNowEntryManager()
105 : m_posMap()
106 , m_typeMap() {}
107
109 WriteNowEntry get(long pos) const
110 {
111 auto it = m_posMap.find(pos);
112 if (it == m_posMap.end())
113 return WriteNowEntry();
114 return it->second;
115 }
116
118 bool add(WriteNowEntry const &entry)
119 {
120 if (!entry.valid()) return false;
121 if (m_posMap.find(entry.begin()) != m_posMap.end()) {
122 MWAW_DEBUG_MSG(("WriteNowEntryManager:add: an entry for this position already exists\n"));
123 return false;
124 }
125 auto it = m_posMap.insert(std::pair<long, WriteNowEntry>(entry.begin(), entry)).first;
126 m_typeMap.insert
127 (std::multimap<std::string, WriteNowEntry const *>::value_type(entry.type(), &(it->second)));
128 return true;
129 }
130
132 void reset()
133 {
134 m_posMap.clear();
135 m_typeMap.clear();
136 }
138 std::map<long, WriteNowEntry> m_posMap;
140 std::multimap<std::string, WriteNowEntry const *> m_typeMap;
141 };
142
143 #endif
WriteNowEntry::m_val
int m_val[4]
other values
Definition: WriteNowEntry.hxx:99
WriteNowEntryManager::WriteNowEntryManager
WriteNowEntryManager()
Definition: WriteNowEntry.hxx:104
WriteNowEntry
class to store entry in a WriteNow document
Definition: WriteNowEntry.hxx:48
WriteNowEntryManager::add
bool add(WriteNowEntry const &entry)
add a new entry
Definition: WriteNowEntry.hxx:118
MWAWEntry.hxx
libmwaw_internal.hxx
WriteNowEntry::WriteNowEntry
WriteNowEntry()
construtor
Definition: WriteNowEntry.hxx:50
MWAWEntry::type
std::string const & type() const
returns the type of the entry
Definition: MWAWEntry.hxx:135
WriteNowEntry::isZoneType
bool isZoneType() const
returns true if this entry store a zone
Definition: WriteNowEntry.hxx:59
WriteNowEntryManager
the manager of the entries
Definition: WriteNowEntry.hxx:103
WriteNowEntryManager::m_typeMap
std::multimap< std::string, WriteNowEntry const * > m_typeMap
the list of entries
Definition: WriteNowEntry.hxx:140
WriteNowEntry::~WriteNowEntry
~WriteNowEntry() final
destructor
Definition: WriteNowEntry.cxx:36
WriteNowEntryManager::reset
void reset()
reset the data
Definition: WriteNowEntry.hxx:132
WriteNowEntry::isZone
bool isZone() const
returns true if this is a zone
Definition: WriteNowEntry.hxx:64
MWAW_DEBUG_MSG
#define MWAW_DEBUG_MSG(M)
Definition: libmwaw_internal.hxx:129
WriteNowEntry::operator<<
friend std::ostream & operator<<(std::ostream &o, WriteNowEntry const &entry)
operator<<
Definition: WriteNowEntry.hxx:69
WriteNowEntryManager::m_posMap
std::map< long, WriteNowEntry > m_posMap
the list of entries by position
Definition: WriteNowEntry.hxx:138
MWAWEntry::valid
bool valid() const
returns true if the zone length is positive
Definition: MWAWEntry.hxx:97
MWAWEntry::id
int id() const
returns the id
Definition: MWAWEntry.hxx:162
WriteNowEntry::m_fileType
int m_fileType
the file entry id
Definition: WriteNowEntry.hxx:97
MWAWEntry
basic class to store an entry in a file This contained :
Definition: MWAWEntry.hxx:46
MWAWEntry::begin
long begin() const
returns the begin offset
Definition: MWAWEntry.hxx:81