Klang C++ 0.7.15
Language Reference (draft)
Loading...
Searching...
No Matches
klang::Generic::Graph< SIZE >

A line graph plotter. More...

#include <klang.h>

Classes

struct  Axes
 Graph axes (x/y) More...
 
struct  Axis
 Graph axis. More...
 
struct  Data
 Graph data. More...
 
struct  Point
 A data point. More...
 
struct  Series
 Data series. More...
 

Public Member Functions

virtual ~Graph ()
 
size_t capacity () const
 
void clear ()
 
Graph & operator() (double min, double max)
 
Graph::Series & operator[] (int index)
 
const Graph::Series & operator[] (int index) const
 
Graph & operator() (double x_min, double x_max, double y_min, double y_max)
 
 operator Series & ()
 
template<typename SIGNAL , typename... Args>
void plot (Generic::Function< SIGNAL, Args... > &function)
 Plot the given Function.
 
template<typename TYPE >
void plot (TYPE(*function)(TYPE))
 Plot the given function of x.
 
template<typename FUNCTION , typename... VALUES>
void plot (FUNCTION f, VALUES... values)
 Plot the given function for x plus additional arguments.
 
template<typename TYPE >
void add (TYPE y)
 Add a data point (incrementing x)
 
void add (const Point pt)
 Add a data point.
 
template<typename TYPE >
Graph & operator+= (TYPE y)
 Add a data point (incrementing x)
 
Graph & operator+= (const Point pt)
 Add a data point.
 
template<typename TYPE >
Graph & operator= (TYPE(*function)(TYPE))
 Plot the given function of x.
 
Graph & operator= (std::initializer_list< Point > values)
 Plot the given data points.
 
Graph & operator+= (std::initializer_list< Point > values)
 Plot the given data points.
 
template<typename... Args>
Graph & operator<< (Function< Args... > &function)
 Plot the given function for x plus additional arguments.
 
template<typename TYPE >
Graph & operator<< (TYPE &in)
 
template<typename TYPE >
Graph & operator<< (const TYPE &in)
 
const Axes & getAxes () const
 
void getAxes (Axes &axes) const
 
const Data & getData () const
 
bool isDirty () const
 
void setDirty (bool dirty)
 
void truncate (unsigned int count)
 

Protected Attributes

Axes axes
 
Data data
 
bool dirty = false
 

Detailed Description

template<int SIZE>
struct klang::Generic::Graph< SIZE >

Definition at line 3328 of file klang.h.

Constructor & Destructor Documentation

◆ ~Graph()

template<int SIZE>
virtual klang::Generic::Graph< SIZE >::~Graph ( )
inlinevirtual

Definition at line 3329 of file klang.h.

3329{};

Member Function Documentation

◆ add() [1/2]

template<int SIZE>
void klang::Generic::Graph< SIZE >::add ( const Point pt)
inline

Definition at line 3558 of file klang.h.

3558{ data[0].add(pt); dirty = true; }
void add(const TYPE &item)
Add the specified item to the end of the array.
Definition klang.h:318

References klang::Array< TYPE, CAPACITY >::add(), klang::Generic::Graph< SIZE >::data, and klang::Generic::Graph< SIZE >::dirty.

◆ add() [2/2]

◆ capacity()

template<int SIZE>
size_t klang::Generic::Graph< SIZE >::capacity ( ) const
inline

Definition at line 3331 of file klang.h.

3331{ return SIZE; }

◆ clear()

template<int SIZE>
void klang::Generic::Graph< SIZE >::clear ( )
inline

Definition at line 3453 of file klang.h.

3453 {
3454 dirty = true;
3455 axes.clear();
3456 for (int s = 0; s < GRAPH_SERIES; s++)
3457 data[s].clear();
3458 data.clear();
3459 }
void clear()
Clear the array contents. Only resets the item count, without wiping memory.
Definition klang.h:331

References klang::Generic::Graph< SIZE >::axes, klang::Array< TYPE, CAPACITY >::clear(), klang::Generic::Graph< SIZE >::Axes::clear(), klang::Generic::Graph< SIZE >::clear(), klang::Generic::Graph< SIZE >::data, and klang::Generic::Graph< SIZE >::dirty.

Referenced by klang::Generic::Graph< SIZE >::clear(), and klang::Generic::Graph< SIZE >::operator=().

◆ getAxes() [1/2]

template<int SIZE>
const Axes & klang::Generic::Graph< SIZE >::getAxes ( ) const
inline

Definition at line 3595 of file klang.h.

3595{ return axes; }

References klang::Generic::Graph< SIZE >::axes.

◆ getAxes() [2/2]

template<int SIZE>
void klang::Generic::Graph< SIZE >::getAxes ( Axes & axes) const
inline

Definition at line 3598 of file klang.h.

3598 {
3599 if (!axes.x.valid()) {
3600 axes.x.clear();
3601 for (int s = 0; s < GRAPH_SERIES; s++)
3602 axes.x.from(data[s], &Point::x);
3603 if (!axes.y.valid() && axes.y.max != 0)
3604 axes.y.min = 0;
3605 }
3606 if (!axes.y.valid()) {
3607 axes.y.clear();
3608 for (int s = 0; s < GRAPH_SERIES; s++)
3609 axes.y.from(data[s], &Point::y);
3610 if (!axes.y.valid() && axes.y.max != 0)
3611 axes.y.min = 0;
3612 }
3613 }
void from(const Series &series, double Point::*axis)
Definition klang.h:3426

References klang::Generic::Graph< SIZE >::axes, klang::Generic::Graph< SIZE >::Axis::clear(), klang::Generic::Graph< SIZE >::data, klang::Generic::Graph< SIZE >::Axis::from(), klang::Generic::Graph< SIZE >::Axis::max, klang::Generic::Graph< SIZE >::Axis::min, klang::Generic::Graph< SIZE >::Axis::valid(), klang::Generic::Graph< SIZE >::Axes::x, klang::Generic::Graph< SIZE >::Point::x, klang::Generic::Graph< SIZE >::Axes::y, and klang::Generic::Graph< SIZE >::Point::y.

◆ getData()

template<int SIZE>
const Data & klang::Generic::Graph< SIZE >::getData ( ) const
inline

Definition at line 3615 of file klang.h.

3615{ return data; }

References klang::Generic::Graph< SIZE >::data.

◆ isDirty()

template<int SIZE>
bool klang::Generic::Graph< SIZE >::isDirty ( ) const
inline

Definition at line 3616 of file klang.h.

3616{ return dirty; }

References klang::Generic::Graph< SIZE >::dirty.

◆ operator Series &()

template<int SIZE>
klang::Generic::Graph< SIZE >::operator Series & ( )
inline

Definition at line 3506 of file klang.h.

3506 {
3507 dirty = true;
3508 return data[0];
3509 }

References klang::Generic::Graph< SIZE >::data, and klang::Generic::Graph< SIZE >::dirty.

◆ operator()() [1/2]

template<int SIZE>
Graph & klang::Generic::Graph< SIZE >::operator() ( double min,
double max )
inline

◆ operator()() [2/2]

template<int SIZE>
Graph & klang::Generic::Graph< SIZE >::operator() ( double x_min,
double x_max,
double y_min,
double y_max )
inline

◆ operator+=() [1/3]

template<int SIZE>
Graph & klang::Generic::Graph< SIZE >::operator+= ( const Point pt)
inline

Definition at line 3564 of file klang.h.

3564{ add(pt); return *this; }
void add(TYPE y)
Add a data point (incrementing x)
Definition klang.h:3556

References klang::Generic::Graph< SIZE >::add().

◆ operator+=() [2/3]

template<int SIZE>
Graph & klang::Generic::Graph< SIZE >::operator+= ( std::initializer_list< Point > values)
inline

Definition at line 3579 of file klang.h.

3579 {
3580 for (const auto& value : values)
3581 add(value);
3582 return *this;
3583 }

References klang::Generic::Graph< SIZE >::add().

◆ operator+=() [3/3]

template<int SIZE>
template<typename TYPE >
Graph & klang::Generic::Graph< SIZE >::operator+= ( TYPE y)
inline

Definition at line 3562 of file klang.h.

3562{ add(y); return *this; }

References klang::Generic::Graph< SIZE >::add().

Referenced by klang::Generic::Graph< SIZE >::operator=().

◆ operator<<() [1/3]

template<int SIZE>
template<typename TYPE >
Graph & klang::Generic::Graph< SIZE >::operator<< ( const TYPE & in)
inline

Definition at line 3592 of file klang.h.

3592{ add(in); return *this; } // without/after processing

References klang::Generic::Graph< SIZE >::add().

◆ operator<<() [2/3]

template<int SIZE>
template<typename... Args>
Graph & klang::Generic::Graph< SIZE >::operator<< ( Function< Args... > & function)
inline

Definition at line 3586 of file klang.h.

3586 {
3587 plot(function.with());
3588 return *this;
3589 }
void plot(Generic::Function< SIGNAL, Args... > &function)
Plot the given Function.
Definition klang.h:3513

References klang::Generic::Graph< SIZE >::plot(), and klang::Generic::Function< SIGNAL, Args >::with().

◆ operator<<() [3/3]

template<int SIZE>
template<typename TYPE >
Graph & klang::Generic::Graph< SIZE >::operator<< ( TYPE & in)
inline

Definition at line 3591 of file klang.h.

3591{ add(in); return *this; } // with processing

References klang::Generic::Graph< SIZE >::add().

◆ operator=() [1/2]

template<int SIZE>
Graph & klang::Generic::Graph< SIZE >::operator= ( std::initializer_list< Point > values)
inline

Definition at line 3574 of file klang.h.

3574 {
3575 clear(); return operator+=(values);
3576 }
Graph & operator+=(TYPE y)
Add a data point (incrementing x)
Definition klang.h:3562

References klang::Generic::Graph< SIZE >::clear(), and klang::Generic::Graph< SIZE >::operator+=().

◆ operator=() [2/2]

template<int SIZE>
template<typename TYPE >
Graph & klang::Generic::Graph< SIZE >::operator= ( TYPE(* function )(TYPE))
inline

Definition at line 3568 of file klang.h.

3568 {
3569 plot(function);
3570 return *this;
3571 }

References klang::Generic::Graph< SIZE >::plot().

◆ operator[]() [1/2]

template<int SIZE>
Graph::Series & klang::Generic::Graph< SIZE >::operator[] ( int index)
inline

Definition at line 3490 of file klang.h.

3490 {
3491 dirty = true;
3492 return data[index];
3493 }

References klang::Generic::Graph< SIZE >::data, and klang::Generic::Graph< SIZE >::dirty.

◆ operator[]() [2/2]

template<int SIZE>
const Graph::Series & klang::Generic::Graph< SIZE >::operator[] ( int index) const
inline

Definition at line 3495 of file klang.h.

3495 {
3496 return data[index];
3497 }

References klang::Generic::Graph< SIZE >::data.

◆ plot() [1/3]

template<int SIZE>
template<typename FUNCTION , typename... VALUES>
void klang::Generic::Graph< SIZE >::plot ( FUNCTION f,
VALUES... values )
inline

Definition at line 3541 of file klang.h.

3541 {
3542 thread_local static Function fun(f);
3543 Graph::Series* series = Graph::data.find((void*)fun);
3544 if (!series)
3545 series = Graph::data.add();
3546 if (series) {
3547 dirty = true;
3548 if (!axes.x.valid())
3549 axes.x = { -1, 1 };
3550 series->plot(fun.with(values...), axes.x);
3551 }
3552 }
Function() -> Function< signal, Args... >
Series * find(void *function)
Definition klang.h:3476

References klang::Array< TYPE, CAPACITY >::add(), klang::Generic::Graph< SIZE >::axes, klang::Generic::Graph< SIZE >::data, klang::Generic::Graph< SIZE >::dirty, klang::Generic::Graph< SIZE >::Data::find(), klang::Generic::Graph< SIZE >::Series::plot(), klang::Generic::Graph< SIZE >::Axis::valid(), klang::Generic::Function< SIGNAL, Args >::with(), and klang::Generic::Graph< SIZE >::Axes::x.

◆ plot() [2/3]

◆ plot() [3/3]

template<int SIZE>
template<typename TYPE >
void klang::Generic::Graph< SIZE >::plot ( TYPE(* function )(TYPE))
inline

Definition at line 3527 of file klang.h.

3527 {
3528 Graph::Series* series = Graph::data.find((void*)function);
3529 if (!series)
3530 series = Graph::data.add();
3531 if (series) {
3532 dirty = true;
3533 if (!axes.x.valid())
3534 axes.x = { -1, 1 };
3535 series->plot(function, axes.x);
3536 }
3537 }

References klang::Array< TYPE, CAPACITY >::add(), klang::Generic::Graph< SIZE >::axes, klang::Generic::Graph< SIZE >::data, klang::Generic::Graph< SIZE >::dirty, klang::Generic::Graph< SIZE >::Data::find(), klang::Generic::Graph< SIZE >::Series::plot(), klang::Generic::Graph< SIZE >::Axis::valid(), and klang::Generic::Graph< SIZE >::Axes::x.

◆ setDirty()

template<int SIZE>
void klang::Generic::Graph< SIZE >::setDirty ( bool dirty)
inline

Definition at line 3617 of file klang.h.

3617{ Graph::dirty = dirty; }

References klang::Generic::Graph< SIZE >::dirty.

◆ truncate()

template<int SIZE>
void klang::Generic::Graph< SIZE >::truncate ( unsigned int count)
inline

Definition at line 3619 of file klang.h.

3619 {
3620 if (count < data.count)
3621 data.count = count;
3622
3623 for (int s = 0; s < GRAPH_SERIES; s++)
3624 if (count < data[s].count)
3625 data[s].count = count;
3626 }
unsigned int count
Definition klang.h:308

References klang::Array< TYPE, CAPACITY >::count, and klang::Generic::Graph< SIZE >::data.

Member Data Documentation

◆ axes

◆ data

◆ dirty