1 #ifndef _library_rrdata__hpp__included__
2 #define _library_rrdata__hpp__included__
4 #define RRDATA_BYTES 32
21 * Create new all zero load ID.
25 * Create new load id from bytes.
27 * parameter b: 32 byte array containing the new ID.
29 instance(const unsigned char* b
) throw();
31 * Create load id from string (mainly intended for debugging).
33 instance(const std::string
& id
) throw();
37 unsigned char bytes
[RRDATA_BYTES
];
39 * Is this ID before another one?
41 * parameter i: Another ID.
42 * returns: True if this ID is before another one, false otherwise.
44 bool operator<(const struct instance
& i
) const throw();
45 bool operator<=(const struct instance
& i
) const throw() { return !(i
< *this); }
46 bool operator>=(const struct instance
& i
) const throw() { return !(*this < i
); }
47 bool operator>(const struct instance
& i
) const throw() { return (i
< *this); }
49 * Is this ID equal to another one?
51 * parameter i: Another ID.
52 * returns: True if this ID is equal to another one, false otherwise.
54 bool operator==(const struct instance
& i
) const throw();
55 bool operator!=(const struct instance
& i
) const throw() { return !(*this == i
); }
59 * returns: Copy of the ID before the increment.
61 const struct instance
operator++(int) throw();
65 * returns: Reference to this.
67 struct instance
& operator++() throw();
69 * Increment this ID by specified amount.
71 * returns: The incremented id.
73 struct instance
operator+(unsigned inc
) const throw();
77 * Returns: The difference, or UINT_MAX if too great.
79 unsigned operator-(const struct instance
& m
) const throw();
82 * State block for emergency save.
90 void init(const std::set
<std::pair
<instance
, instance
>>& obj
)
92 if(initialized
) return;
97 std::set
<std::pair
<instance
, instance
>>::const_iterator
next()
99 if(itr
== eitr
) return itr
;
104 return (itr
== eitr
);
109 segptr
= segend
= pred
= instance();
116 std::set
<std::pair
<instance
, instance
>>::const_iterator itr
;
117 std::set
<std::pair
<instance
, instance
>>::const_iterator eitr
;
122 rrdata_set() throw();
124 * Read the saved set of load IDs for specified project and switch to that project.
126 * parameter projectfile: The name of project backing file.
127 * parameter lazy: If true, just switch to project, don't read the IDs.
128 * throws std::bad_alloc: Not enough memory
130 void read_base(const std::string
& projectfile
, bool lazy
) throw(std::bad_alloc
);
134 bool is_lazy() throw() { return lazy_mode
; }
136 * Switch to no project, closing the load IDs.
138 void close() throw();
140 * Add new specified instance to current project.
142 * Not allowed if there is no project open.
144 * parameter i: The load ID to add.
146 void add(const struct instance
& i
) throw(std::bad_alloc
);
148 * Write compressed representation of current load ID set to stream.
150 * parameter strm: The stream to write to.
151 * returns: Rerecord count.
152 * throws std::bad_alloc: Not enough memory.
154 uint64_t write(std::vector
<char>& strm
) throw(std::bad_alloc
);
156 * Get size for compressed representation.
158 * Returns: The size of compressed representation.
159 * Note: Uses no memory.
161 uint64_t size_emerg() const throw();
163 * Write part of compressed representation to buffer.
165 * Parameter state: The state variable (initially, pass esave_state()).
166 * Parameter buf: The buffer to write to.
167 * Parameter bufsize: The buffer size (needs to be at least 36).
168 * Returns: The number of bytes written (0 if at the end).
169 * Note: Uses no memory.
171 size_t write_emerg(struct esave_state
& state
, char* buf
, size_t bufsize
) const throw();
173 * Load compressed representation of load ID set from stream and union it with current set to form new current
176 * parameter strm: The stream to read from.
177 * parameter dummy: If true, don't actually do it, just simulate.
178 * returns: Rerecord count.
179 * throws std::bad_alloc: Not enough memory.
181 uint64_t read(std::vector
<char>& strm
) throw(std::bad_alloc
);
183 * Load compressed representation of load ID set from stream, but don't do anything to it.
185 * parameter strm: The stream to read from.
186 * returns: Rerecord count.
187 * throws std::bad_alloc: Not enough memory.
189 static uint64_t count(std::vector
<char>& strm
) throw(std::bad_alloc
);
191 * Count number of rerecords.
193 * returns: Rerecord count.
195 uint64_t count() throw();
197 * Debugging functions.
199 std::string
debug_dump();
200 bool debug_add(const instance
& b
) { return _add(b
); }
201 void debug_add(const instance
& b
, const instance
& e
) { return _add(b
, e
); }
202 bool debug_in_set(const instance
& b
) { return _in_set(b
); }
203 bool debug_in_set(const instance
& b
, const instance
& e
) { return _in_set(b
, e
); }
204 uint64_t debug_nodecount(std::set
<std::pair
<instance
, instance
>>& set
);
206 bool _add(const instance
& b
);
207 void _add(const instance
& b
, const instance
& e
);
208 void _add(const instance
& b
, const instance
& e
, std::set
<std::pair
<instance
, instance
>>& set
,
210 bool _in_set(const instance
& b
) { return _in_set(b
, b
+ 1); }
211 bool _in_set(const instance
& b
, const instance
& e
);
212 uint64_t emerg_action(struct esave_state
& state
, char* buf
, size_t bufsize
, uint64_t& scount
) const;
214 std::set
<std::pair
<instance
, instance
>> data
;
215 std::ofstream ohandle
;
217 std::string current_projectfile
;
222 std::ostream
& operator<<(std::ostream
& os
, const struct rrdata_set::instance
& j
);