OpenMPCD
Graph.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * Defines the Graph class.
4  */
5 
6 #ifndef OPENMPCD_GRAPH_HPP
7 #define OPENMPCD_GRAPH_HPP
8 
9 #include <OpenMPCD/Types.hpp>
10 
11 #include <deque>
12 #include <string>
13 
14 namespace OpenMPCD
15 {
16  /**
17  * Represents a 2D graph.
18  */
19  class Graph
20  {
21  public:
22  typedef std::deque<std::pair<FP, FP> > Container; ///< The type the data points are collected in.
23 
24  public:
25  /**
26  * Adds a data point.
27  * @param[in] x The x coordinate.
28  * @param[in] y The y coordinate.
29  */
30  void addPoint(const FP x, const FP y)
31  {
32  points.push_back(std::make_pair(x, y));
33  }
34 
35  /**
36  * Returns the data points.
37  */
38  const Container& getPoints() const
39  {
40  return points;
41  }
42 
43  /**
44  * Saves the graph data to the given file path.
45  * @param[in] path The file path to save to.
46  * @param[in] prependGnuplotCommands Set to true to prepend gnuplot commands,
47  * so that the resulting file can be plotted by calling gnuplot on it.
48  */
49  void save(const std::string& path, const bool prependGnuplotCommands) const;
50 
51  private:
52  Container points; ///< The data points.
53  };
54 }
55 
56 #endif
OpenMPCD::Graph::save
void save(const std::string &path, const bool prependGnuplotCommands) const
Saves the graph data to the given file path.
Definition: Graph.cpp:8
OpenMPCD::FP
double FP
Default floating point type.
Definition: Types.hpp:13
Types.hpp
OpenMPCD::Graph::addPoint
void addPoint(const FP x, const FP y)
Adds a data point.
Definition: Graph.hpp:30
OpenMPCD::Graph::Container
std::deque< std::pair< FP, FP > > Container
The type the data points are collected in.
Definition: Graph.hpp:22
OpenMPCD::Graph
Represents a 2D graph.
Definition: Graph.hpp:19
OpenMPCD::Graph::getPoints
const Container & getPoints() const
Returns the data points.
Definition: Graph.hpp:38