// write_events.h - Don Yang (uguu.org) // // 06/10/11 #ifndef WRITE_EVENTS_H_ #define WRITE_EVENTS_H_ #include #include"load_events.h" #include"string_pool.h" using namespace std; class Animation { public: // Due to mingw brokenness, we can't portably define and print // 64bit integers easily. On the other hand, 2^31 milliseconds is // over 24 days long, so 32bits is not too bad. typedef long Millisecond; // A single event struct Event { // Timestamp of event. Millisecond start; // Duration of when this event is valid. That is, if we are at // a timestamp T where (start+duration)<=T, we can ignore this // event because it has already been obsoleted by another event. // // If zero, the event never expires. We really should be storing // INT64_MAX instead, but that will increase the output size, so // we store zero here and adjust the timestamps in output script. Millisecond duration; // Event type enum EventType { CURSOR = AllEvents::CompiledEvent::CURSOR, REPLACE = AllEvents::CompiledEvent::REPLACE, APPEND = AllEvents::CompiledEvent::APPEND, DELETE = AllEvents::CompiledEvent::DELETE, SLOW_CURSOR = AllEvents::CompiledEvent::SLOW_CURSOR }; int type; // CURSOR: unused, always 0. // REPLACE: output slot. // APPEND: output slot. // DELETE: line to be deleted. // SLOW_CURSOR: reference slot for finding base text and row. int slot; // CURSOR: unused. // REPLACE: text to replace output slot. // APPEND: text to be appended to output slot. // DELETE: unused, points at sentinel_string_. // SLOW_CURSOR: unused, points at sentinel_string_. StringPool::Item *text; // CURSOR: unused, always 0. // REPLACE: length of prefix text to replace the existing slot. // APPEND: length of suffix text to be appended. // DELETE: unused, always 0. // SLOW_CURSOR: cursor block width in bytes. int length; // CURSOR: unused, always 0. // REPLACE: unused, always 0. // APPEND: unused, always 0. // DELETE: unused, always 0. // SLOW_CURSOR: byte offset to cursor. int offset; // CURSOR: cursor row position. // REPLACE: unused, always 0. // APPEND: unused, always 0. // DELETE: unused, always 0. // SLOW_CURSOR: unused, always 0. int row; // CURSOR: cursor column position (bytes). // REPLACE: unused, always 0. // APPEND: unused, always 0. // DELETE: unused, always 0. // SLOW_CURSOR: cursor column position (bytes). int column; }; typedef vector EventList; // Initialize animation from list of compiled events Animation(const AllEvents::CompiledEventList &compiled_events, int max_file_size, int output_slot_count); ~Animation(); // Write output to opened file handle void Write(FILE *output) const; // Accessors inline const StringPool &strings() const { return strings_; } inline const EventList &events() const { return events_; } inline const Event &event(int index) const { return events_[index]; } private: // Copy all input events void CopyEvents(const AllEvents::CompiledEventList &compiled_events); // Set duration for all events void SetDurations(); // All shared strings StringPool strings_; // String referenced by cursor+delete events. This ensures that // all string references are not NULL. StringPool::Item sentinel_string_; // Event list, with timestamps converted to milliseconds. EventList events_; // Timestamp of last event. Millisecond max_event_time_; // Peak number of lines in the file during any point in time. const int max_file_size_; // Number of output slots at the end of all events. const int output_slot_count_; // No default constructor Animation(); }; #endif // WRITE_EVENTS_H_