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 WRITE_NOW_ENTRY
00038 # define WRITE_NOW_ENTRY
00039
00040 #include <iostream>
00041 #include <map>
00042 #include <string>
00043
00044 #include "libmwaw_internal.hxx"
00045 #include "MWAWEntry.hxx"
00046
00047 struct WriteNowEntry : public MWAWEntry {
00048 WriteNowEntry() : MWAWEntry(), m_fileType(-1)
00049 {
00050 for (int i = 0; i < 4; i++) m_val[i] = 0;
00051 }
00053 bool isZoneType() const
00054 {
00055 return m_fileType == 4 || m_fileType == 6;
00056 }
00058 bool isZone() const
00059 {
00060 return isZoneType() && valid();
00061 }
00063 friend std::ostream &operator<<(std::ostream &o, WriteNowEntry const &entry)
00064 {
00065 if (entry.type().length()) {
00066 o << entry.type();
00067 if (entry.id() >= 0) o << "[" << entry.id() << "]";
00068 o << "=";
00069 }
00070 o << "[";
00071 switch (entry.m_fileType) {
00072 case 0x4:
00073 o << "zone,";
00074 break;
00075 case 0x6:
00076 o << "zone2,";
00077 break;
00078 case 0xc:
00079 o << "none/data,";
00080 break;
00081 default:
00082 o << "#type=" << entry.m_fileType << ",";
00083 }
00084 for (int i = 0; i < 4; i++) {
00085 if (entry.m_val[i]) o << "v" << i << "=" << std::hex << entry.m_val[i] << std::dec << ",";
00086 }
00087 o << "],";
00088 return o;
00089 }
00091 int m_fileType;
00093 int m_val[4];
00094 };
00095
00097 struct WriteNowEntryManager {
00098 WriteNowEntryManager() : m_posMap(), m_typeMap() {}
00099
00101 WriteNowEntry get(long pos) const
00102 {
00103 std::map<long, WriteNowEntry>::const_iterator it = m_posMap.find(pos);
00104 if (it == m_posMap.end())
00105 return WriteNowEntry();
00106 return it->second;
00107 }
00108
00110 bool add(WriteNowEntry const &entry)
00111 {
00112 if (!entry.valid()) return false;
00113 if (m_posMap.find(entry.begin()) != m_posMap.end()) {
00114 MWAW_DEBUG_MSG(("WriteNowEntryManager:add: an entry for this position already exists\n"));
00115 return false;
00116 }
00117 std::map<long, WriteNowEntry>::iterator it =
00118 m_posMap.insert(std::pair<long, WriteNowEntry>(entry.begin(), entry)).first;
00119 m_typeMap.insert
00120 (std::multimap<std::string, WriteNowEntry const *>::value_type(entry.type(), &(it->second)));
00121 return true;
00122 }
00123
00125 void reset()
00126 {
00127 m_posMap.clear();
00128 m_typeMap.clear();
00129 }
00131 std::map<long, WriteNowEntry> m_posMap;
00133 std::multimap<std::string, WriteNowEntry const *> m_typeMap;
00134 };
00135
00136 #endif