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

// Buffer.h
#ifndef _Buffer_h_
#define _Buffer_h_
#include <fstream>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <string>
#include <vector>
class Buffer
{
public:
bool back();
void display() const;
const std::string & file_name() const { return file_name_; }
bool go(int link);
long max_links() {return v_links_.size(); };
void move_to_next_page();
void move_to_previous_page();
bool open(const std::string & file_name, bool add_to_hist_ = true);
void set_maximum_length(int l) { maximum_length_ = l; }
void set_window_height(int h) { window_height_ = h; }
private:
std::size_t get_tag_(const std::string & line);
void split_line(std::string str);
std::string file_name_;
std::vector<std::string> v_lines_;
std::vector<std::pair<std::string, std::string>> v_links_;
std::vector<std::string> v_hist_;
std::vector<std::string>::iterator curr_link_itr = v_hist_.end();
bool add_to_hist_ = 1;
int ix_top_line_ = 0;
int window_height_ = 0;
int maximum_length_ = 0;
};
inline void Buffer::move_to_next_page()
{
ix_top_line_ += window_height_;
if (ix_top_line_ >= v_lines_.size())
ix_top_line_ -= window_height_;
}
inline void Buffer::move_to_previous_page()
{
ix_top_line_ -= window_height_;
if (ix_top_line_ < 0)
ix_top_line_ = 0;
}
#endif