You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.3 KiB

4 years ago
4 years ago
4 years ago
4 years ago
  1. // Buffer.h
  2. #ifndef _Buffer_h_
  3. #define _Buffer_h_
  4. #include <fstream>
  5. #include <iomanip>
  6. #include <sstream>
  7. #include <iostream>
  8. #include <string>
  9. #include <vector>
  10. class Buffer
  11. {
  12. public:
  13. bool back();
  14. void display() const;
  15. const std::string & file_name() const { return file_name_; }
  16. bool go(int link);
  17. long max_links() {return v_links_.size(); };
  18. void move_to_next_page();
  19. void move_to_previous_page();
  20. bool open(const std::string & file_name, bool add_to_hist_ = true);
  21. void set_maximum_length(int l) { maximum_length_ = l; }
  22. void set_window_height(int h) { window_height_ = h; }
  23. private:
  24. std::size_t get_tag_(const std::string & line);
  25. void split_line(std::string str);
  26. std::string file_name_;
  27. std::vector<std::string> v_lines_;
  28. std::vector<std::pair<std::string, std::string>> v_links_;
  29. std::vector<std::string> v_hist_;
  30. std::vector<std::string>::iterator curr_link_itr = v_hist_.end();
  31. bool add_to_hist_ = 1;
  32. int ix_top_line_ = 0;
  33. int window_height_ = 0;
  34. int maximum_length_ = 0;
  35. };
  36. inline void Buffer::move_to_next_page()
  37. {
  38. ix_top_line_ += window_height_;
  39. if (ix_top_line_ >= v_lines_.size())
  40. ix_top_line_ -= window_height_;
  41. }
  42. inline void Buffer::move_to_previous_page()
  43. {
  44. ix_top_line_ -= window_height_;
  45. if (ix_top_line_ < 0)
  46. ix_top_line_ = 0;
  47. }
  48. #endif