Klang C++
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 ()
 
Graphoperator() (double min, double max)
 
Graph::Seriesoperator[] (int index)
 
const Graph::Seriesoperator[] (int index) const
 
Graphoperator() (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 >
Graphoperator+= (TYPE y)
 Add a data point (incrementing x)
 
Graphoperator+= (const Point pt)
 Add a data point.
 
template<typename TYPE >
Graphoperator= (TYPE(*function)(TYPE))
 Plot the given function of x.
 
Graphoperator= (std::initializer_list< Point > values)
 Plot the given data points.
 
Graphoperator+= (std::initializer_list< Point > values)
 Plot the given data points.
 
template<typename... Args>
Graphoperator<< (Function< Args... > &function)
 Plot the given function for x plus additional arguments.
 
template<typename TYPE >
Graphoperator<< (TYPE &in)
 
template<typename TYPE >
Graphoperator<< (const TYPE &in)
 
const AxesgetAxes () const
 
void getAxes (Axes &axes) const
 
const DatagetData () 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 1634 of file klang.h.

Constructor & Destructor Documentation

◆ ~Graph()

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

Definition at line 1635 of file klang.h.

1635{ };

Member Function Documentation

◆ add() [1/2]

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

Definition at line 1864 of file klang.h.

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

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

◆ add() [2/2]

template<int SIZE>
template<typename TYPE >
void klang::Generic::Graph< SIZE >::add ( TYPE y)
inline

Definition at line 1862 of file klang.h.

1862{ data[0].add(y); dirty = true; }

◆ capacity()

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

Definition at line 1637 of file klang.h.

1637{ return SIZE; }

◆ clear()

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

Definition at line 1759 of file klang.h.

1759 {
1760 dirty = true;
1761 axes.clear();
1762 for (int s = 0; s < GRAPH_SERIES; s++)
1763 data[s].clear();
1764 data.clear();
1765 }
void clear()
Clear the array contents. Only resets the item count, without wiping memory.
Definition klang.h:262

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

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

◆ getAxes() [1/2]

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

Definition at line 1901 of file klang.h.

1901{ 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 1904 of file klang.h.

1904 {
1905 if (!axes.x.valid()) {
1906 axes.x.clear();
1907 for (int s = 0; s < GRAPH_SERIES; s++)
1908 axes.x.from(data[s], &Point::x);
1909 if (!axes.y.valid() && axes.y.max != 0)
1910 axes.y.min = 0;
1911 }
1912 if (!axes.y.valid()) {
1913 axes.y.clear();
1914 for (int s = 0; s < GRAPH_SERIES; s++)
1915 axes.y.from(data[s], &Point::y);
1916 if (!axes.y.valid() && axes.y.max != 0)
1917 axes.y.min = 0;
1918 }
1919 }
void from(const Series &series, double Point::*axis)
Definition klang.h:1732

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

◆ getData()

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

Definition at line 1921 of file klang.h.

1921{ return data; }

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

◆ isDirty()

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

Definition at line 1922 of file klang.h.

1922{ return dirty; }

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

◆ operator Series &()

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

Definition at line 1812 of file klang.h.

1812 {
1813 dirty = true;
1814 return data[0];
1815 }

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

Definition at line 1790 of file klang.h.

1790 {
1791 dirty = true;
1792 axes.x.min = min; axes.x.max = max;
1793 return *this;
1794 }
TYPE1 max(TYPE1 a, TYPE2 b)
Return the minimum of two values.
Definition klang.h:215
TYPE1 min(TYPE1 a, TYPE2 b)
Return the minimum of two values.
Definition klang.h:212

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

◆ 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

Definition at line 1805 of file klang.h.

1805 {
1806 dirty = true;
1807 axes.x.min = x_min; axes.x.max = x_max;
1808 axes.y.min = y_min; axes.y.max = y_max;
1809 return *this;
1810 }

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

◆ operator+=() [1/3]

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

Definition at line 1870 of file klang.h.

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

◆ operator+=() [2/3]

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

Definition at line 1885 of file klang.h.

1885 {
1886 for (const auto& value : values)
1887 add(value);
1888 return *this;
1889 }

◆ operator+=() [3/3]

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

Definition at line 1868 of file klang.h.

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

◆ operator<<() [1/3]

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

Definition at line 1898 of file klang.h.

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

◆ operator<<() [2/3]

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

Definition at line 1892 of file klang.h.

1892 {
1893 plot(function.with());
1894 return *this;
1895 }
void plot(Generic::Function< SIGNAL, Args... > &function)
Plot the given Function.
Definition klang.h:1819

◆ operator<<() [3/3]

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

Definition at line 1897 of file klang.h.

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

◆ operator=() [1/2]

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

Definition at line 1880 of file klang.h.

1880 {
1881 clear(); return operator+=(values);
1882 }
Graph & operator+=(TYPE y)
Add a data point (incrementing x)
Definition klang.h:1868

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

◆ operator=() [2/2]

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

Definition at line 1874 of file klang.h.

1874 {
1875 plot(function);
1876 return *this;
1877 }

◆ operator[]() [1/2]

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

Definition at line 1796 of file klang.h.

1796 {
1797 dirty = true;
1798 return data[index];
1799 }

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 1801 of file klang.h.

1801 {
1802 return data[index];
1803 }

◆ 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 1847 of file klang.h.

1847 {
1848 thread_local static Function fun(f);
1849 Graph::Series* series = Graph::data.find((void*)fun);
1850 if (!series)
1851 series = Graph::data.add();
1852 if (series) {
1853 dirty = true;
1854 if (!axes.x.valid())
1855 axes.x = { -1, 1 };
1856 series->plot(fun.with(values...), axes.x);
1857 }
1858 }
Function() -> Function< signal, Args... >
Series * find(void *function)
Definition klang.h:1782

◆ plot() [2/3]

template<int SIZE>
template<typename SIGNAL , typename... Args>
void klang::Generic::Graph< SIZE >::plot ( Generic::Function< SIGNAL, Args... > & function)
inline

Definition at line 1819 of file klang.h.

1819 {
1820 Graph::Series* series = Graph::data.find((void*)function);
1821 if (!series)
1822 series = Graph::data.add();
1823 if (series) {
1824 dirty = true;
1825 if (!axes.x.valid())
1826 axes.x = { -1, 1 };
1827 series->plot(function, axes.x);
1828 }
1829 }

◆ plot() [3/3]

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

Definition at line 1833 of file klang.h.

1833 {
1834 Graph::Series* series = Graph::data.find((void*)function);
1835 if (!series)
1836 series = Graph::data.add();
1837 if (series) {
1838 dirty = true;
1839 if (!axes.x.valid())
1840 axes.x = { -1, 1 };
1841 series->plot(function, axes.x);
1842 }
1843 }

◆ setDirty()

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

Definition at line 1923 of file klang.h.

1923{ 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 1925 of file klang.h.

1925 {
1926 if (count < data.count)
1927 data.count = count;
1928
1929 for (int s = 0; s < GRAPH_SERIES; s++)
1930 if (count < data[s].count)
1931 data[s].count = count;
1932 }
unsigned int count
Definition klang.h:240

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

Member Data Documentation

◆ axes

◆ data

◆ dirty