Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef WN_MWAW_ENTRY
00038 # define WN_MWAW_ENTRY
00039
00040 #include <iostream>
00041 #include <map>
00042 #include <string>
00043
00044 #include "libmwaw_internal.hxx"
00045 #include "MWAWEntry.hxx"
00046
00047 struct WNEntry : public MWAWEntry {
00048 WNEntry() : MWAWEntry(), m_fileType(-1) {
00049 for (int i = 0; i < 4; i++) m_val[i] = 0;
00050 }
00052 bool isZoneType() const {
00053 return m_fileType == 4 || m_fileType == 6;
00054 }
00056 bool isZone() const {
00057 return isZoneType() && valid();
00058 }
00060 friend std::ostream &operator<<(std::ostream &o, WNEntry const &entry) {
00061 if (entry.type().length()) {
00062 o << entry.type();
00063 if (entry.id() >= 0) o << "[" << entry.id() << "]";
00064 o << "=";
00065 }
00066 o << "[";
00067 switch(entry.m_fileType) {
00068 case 0x4:
00069 o << "zone,";
00070 break;
00071 case 0x6:
00072 o << "zone2,";
00073 break;
00074 case 0xc:
00075 o << "none/data,";
00076 break;
00077 default:
00078 o << "#type=" << entry.m_fileType << ",";
00079 }
00080 for (int i = 0; i < 4; i++) {
00081 if (entry.m_val[i]) o << "v" << i << "=" << std::hex << entry.m_val[i] << std::dec << ",";
00082 }
00083 o << "],";
00084 return o;
00085 }
00087 int m_fileType;
00089 int m_val[4];
00090 };
00091
00093 struct WNEntryManager {
00094 WNEntryManager() : m_posMap(), m_typeMap() {}
00095
00097 WNEntry get(long pos) const {
00098 std::map<long, WNEntry>::const_iterator it = m_posMap.find(pos);
00099 if (it == m_posMap.end())
00100 return WNEntry();
00101 return it->second;
00102 }
00103
00105 bool add(WNEntry const &entry) {
00106 if (!entry.valid()) return false;
00107 if (m_posMap.find(entry.begin()) != m_posMap.end()) {
00108 MWAW_DEBUG_MSG(("WNEntryManager:add: an entry for this position already exists\n"));
00109 return false;
00110 }
00111 std::map<long, WNEntry>::iterator it =
00112 m_posMap.insert(std::pair<long, WNEntry>(entry.begin(), entry)).first;
00113 m_typeMap.insert
00114 (std::multimap<std::string, WNEntry const *>::value_type(entry.type(), &(it->second)));
00115 return true;
00116 }
00117
00119 void reset() {
00120 m_posMap.clear();
00121 m_typeMap.clear();
00122 }
00124 std::map<long, WNEntry> m_posMap;
00126 std::multimap<std::string, WNEntry const *> m_typeMap;
00127 };
00128
00129 #endif