#include #include #include class Color { private: int M_color; // GNUplot color index. int M_column; // The corresponding column. std::string M_label; // The corresponding label. protected: friend class Graph; Color(int color, int column, std::string const& label) : M_color(color), M_column(column), M_label(label) { } public: int get_color(void) const { return M_color; } int get_column(void) const { return M_column; } std::string const& get_label(void) const { return M_label; } void swap_column_with(Color& color) { std::swap(M_column, color.M_column); } friend bool operator==(Color const& color1, Color const& color2) { return color1.M_column == color2.M_column; } }; typedef std::list color_list_type; class DataPoint { private: int M_x; // x coordinate of data point. int M_y; // y coordinate of data point. color_list_type::const_iterator M_color; // The color & label to use for this data point. public: DataPoint(int x, int y, color_list_type::const_iterator const& color) : M_x(x), M_y(y), M_color(color) { } int get_x(void) const { return M_x; } int get_y(void) const { return M_y; } Color const& get_color(void) const { return *M_color; } friend bool operator<(DataPoint const& dp1, DataPoint const& dp2) { return dp1.M_x < dp2.M_x || (dp1.M_x == dp2.M_x && dp1.M_color->get_column() < dp2.M_color->get_column()); } }; class Graph { private: std::string M_basename; std::string M_title; int M_color_hint; int M_next_column; std::vector M_data; color_list_type M_colors; public: Graph(std::string const& basename, std::string const& title) : M_basename(basename), M_title(title), M_color_hint(0), M_next_column(0) { } std::string const& get_title(void) const { return M_title; } std::vector const& get_data(void) const { return M_data; } std::vector& get_data(void) { return M_data; } color_list_type const& get_colors(void) const { return M_colors; } bool add_point(int x, int y, int column); int add_point(int x, int y, std::string const& label, int color = -2); void swap_columns(int col1, int col2); void plot(void); private: int M_new_color(void); };