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

Generated on Tue Mar 10 2015 17:32:09 for libmwaw by doxygen 1.8.5