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 
47 struct WriteNowEntry : public MWAWEntry {
49  {
50  for (int i = 0; i < 4; i++) m_val[i] = 0;
51  }
53  bool isZoneType() const
54  {
55  return m_fileType == 4 || m_fileType == 6;
56  }
58  bool isZone() const
59  {
60  return isZoneType() && valid();
61  }
63  friend std::ostream &operator<<(std::ostream &o, WriteNowEntry const &entry)
64  {
65  if (entry.type().length()) {
66  o << entry.type();
67  if (entry.id() >= 0) o << "[" << entry.id() << "]";
68  o << "=";
69  }
70  o << "[";
71  switch (entry.m_fileType) {
72  case 0x4:
73  o << "zone,";
74  break;
75  case 0x6:
76  o << "zone2,";
77  break;
78  case 0xc:
79  o << "none/data,";
80  break;
81  default:
82  o << "#type=" << entry.m_fileType << ",";
83  }
84  for (int i = 0; i < 4; i++) {
85  if (entry.m_val[i]) o << "v" << i << "=" << std::hex << entry.m_val[i] << std::dec << ",";
86  }
87  o << "],";
88  return o;
89  }
93  int m_val[4];
94 };
95 
99 
101  WriteNowEntry get(long pos) const
102  {
103  std::map<long, WriteNowEntry>::const_iterator it = m_posMap.find(pos);
104  if (it == m_posMap.end())
105  return WriteNowEntry();
106  return it->second;
107  }
108 
110  bool add(WriteNowEntry const &entry)
111  {
112  if (!entry.valid()) return false;
113  if (m_posMap.find(entry.begin()) != m_posMap.end()) {
114  MWAW_DEBUG_MSG(("WriteNowEntryManager:add: an entry for this position already exists\n"));
115  return false;
116  }
117  std::map<long, WriteNowEntry>::iterator it =
118  m_posMap.insert(std::pair<long, WriteNowEntry>(entry.begin(), entry)).first;
119  m_typeMap.insert
120  (std::multimap<std::string, WriteNowEntry const *>::value_type(entry.type(), &(it->second)));
121  return true;
122  }
123 
125  void reset()
126  {
127  m_posMap.clear();
128  m_typeMap.clear();
129  }
131  std::map<long, WriteNowEntry> m_posMap;
133  std::multimap<std::string, WriteNowEntry const *> m_typeMap;
134 };
135 
136 #endif
int m_val[4]
other values
Definition: WriteNowEntry.hxx:93
WriteNowEntryManager()
Definition: WriteNowEntry.hxx:98
bool valid() const
returns true if the zone length is positive
Definition: MWAWEntry.hxx:87
Definition: WriteNowEntry.hxx:47
bool add(WriteNowEntry const &entry)
add a new entry
Definition: WriteNowEntry.hxx:110
bool isZoneType() const
returns true if this entry store a zone
Definition: WriteNowEntry.hxx:53
WriteNowEntry()
Definition: WriteNowEntry.hxx:48
the manager of the entries
Definition: WriteNowEntry.hxx:97
std::multimap< std::string, WriteNowEntry const * > m_typeMap
the list of entries
Definition: WriteNowEntry.hxx:133
long begin() const
returns the begin offset
Definition: MWAWEntry.hxx:71
void reset()
reset the data
Definition: WriteNowEntry.hxx:125
#define MWAW_DEBUG_MSG(M)
Definition: libmwaw_internal.hxx:127
friend std::ostream & operator<<(std::ostream &o, WriteNowEntry const &entry)
operator<<
Definition: WriteNowEntry.hxx:63
std::map< long, WriteNowEntry > m_posMap
the list of entries by position
Definition: WriteNowEntry.hxx:131
bool isZone() const
returns true if this is a zone
Definition: WriteNowEntry.hxx:58
int id() const
returns the id
Definition: MWAWEntry.hxx:152
int m_fileType
the file entry id
Definition: WriteNowEntry.hxx:91
basic class to store an entry in a file This contained :
Definition: MWAWEntry.hxx:46
std::string const & type() const
returns the type of the entry
Definition: MWAWEntry.hxx:125

Generated on Thu Jul 9 2015 20:26:37 for libmwaw by doxygen 1.8.8