mirror of
https://github.com/tdulcet/Table-and-Graph-Libs.git
synced 2025-05-05 21:41:12 +08:00
Fix ODR violations via function inlining (#5)
This commit is contained in:
parent
60728a7c44
commit
370dde9025
40
graphs.hpp
40
graphs.hpp
@ -168,9 +168,6 @@ namespace graphs
|
||||
bool check = true;
|
||||
};
|
||||
|
||||
const options defaultoptions;
|
||||
options histogram_defaultoptions;
|
||||
|
||||
template <typename T>
|
||||
constexpr size_t size(const T &array)
|
||||
{
|
||||
@ -179,7 +176,7 @@ namespace graphs
|
||||
|
||||
// Number of columns needed to represent the string
|
||||
// Adapted from: https://stackoverflow.com/a/31124065
|
||||
int strcol(const char *const str)
|
||||
inline int strcol(const char *const str)
|
||||
{
|
||||
size_t length = strlen(str);
|
||||
for (size_t i = 0; i < length; ++i)
|
||||
@ -224,7 +221,7 @@ namespace graphs
|
||||
// Word wrap
|
||||
// Source: https://gist.github.com/tdulcet/819821ca69501822ad3f84a060c640a0
|
||||
// Adapted from: https://stackoverflow.com/a/42016346 and https://stackoverflow.com/a/13094734
|
||||
string wrap(const char *const str, const size_t line_length)
|
||||
inline string wrap(const char *const str, const size_t line_length)
|
||||
{
|
||||
string words = str;
|
||||
string wrapped;
|
||||
@ -272,7 +269,7 @@ namespace graphs
|
||||
|
||||
// Auto-scale number to unit
|
||||
// Adapted from: https://github.com/coreutils/coreutils/blob/master/src/numfmt.c
|
||||
void outputunit(long double number, const units_type scale, ostringstream &strm)
|
||||
inline void outputunit(long double number, const units_type scale, ostringstream &strm)
|
||||
{
|
||||
unsigned x = 0;
|
||||
long double val = number;
|
||||
@ -353,7 +350,7 @@ namespace graphs
|
||||
}
|
||||
|
||||
// Convert fractions and constants to Unicode characters
|
||||
void outputfraction(const long double number, ostringstream &strm)
|
||||
inline void outputfraction(const long double number, ostringstream &strm)
|
||||
{
|
||||
bool output = false;
|
||||
|
||||
@ -403,7 +400,7 @@ namespace graphs
|
||||
strm << number;
|
||||
}
|
||||
|
||||
size_t outputlabel(const long double label, const units_type units, ostringstream &strm)
|
||||
inline size_t outputlabel(const long double label, const units_type units, ostringstream &strm)
|
||||
{
|
||||
strm.imbue(locale(""));
|
||||
|
||||
@ -451,7 +448,7 @@ namespace graphs
|
||||
}
|
||||
|
||||
// Output graph
|
||||
int graph(const size_t height, const size_t width, const long double xmin, const long double xmax, const long double ymin, const long double ymax, const vector<vector<unsigned short>> &array, const options &aoptions)
|
||||
inline int graph(const size_t height, const size_t width, const long double xmin, const long double xmax, const long double ymin, const long double ymax, const vector<vector<unsigned short>> &array, const options &aoptions)
|
||||
{
|
||||
if (!graphs::size(array))
|
||||
return 1;
|
||||
@ -777,7 +774,7 @@ namespace graphs
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int histogram(size_t height, size_t width, long double xmin, long double xmax, long double ymin, long double ymax, const T &aarray, /* const */ options &aoptions = histogram_defaultoptions)
|
||||
int histogram(size_t height, size_t width, long double xmin, long double xmax, long double ymin, long double ymax, const T &aarray, const options &aoptions = {})
|
||||
{
|
||||
if (!graphs::size(aarray))
|
||||
return 1;
|
||||
@ -869,14 +866,17 @@ namespace graphs
|
||||
for (size_t y = ay >= ymax ? 0 : yaxis - (ay / ystep); y < yaxis and y < height; ++y)
|
||||
aaarray[x][y] = acolor;
|
||||
}
|
||||
|
||||
aoptions.type = type_histogram;
|
||||
|
||||
|
||||
if (aoptions.type != type_histogram) {
|
||||
options hist_options = aoptions;
|
||||
hist_options.type = type_histogram;
|
||||
return graph(height, width, xmin, xmax, ymin, ymax, aaarray, hist_options);
|
||||
}
|
||||
return graph(height, width, xmin, xmax, ymin, ymax, aaarray, aoptions);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int histogram(size_t height, size_t width, long double xmin, long double xmax, long double ymin, long double ymax, const size_t rows, T *aarray, /* const */ options &aoptions = histogram_defaultoptions)
|
||||
int histogram(size_t height, size_t width, long double xmin, long double xmax, long double ymin, long double ymax, const size_t rows, T *aarray, const options &aoptions = {})
|
||||
{
|
||||
if (rows == 0)
|
||||
return 1;
|
||||
@ -889,7 +889,7 @@ namespace graphs
|
||||
|
||||
// Convert one or more arrays to graph and output
|
||||
template <typename T>
|
||||
int plots(size_t height, size_t width, long double xmin, long double xmax, long double ymin, long double ymax, const T &arrays, const options &aoptions = defaultoptions)
|
||||
int plots(size_t height, size_t width, long double xmin, long double xmax, long double ymin, long double ymax, const T &arrays, const options &aoptions = {})
|
||||
{
|
||||
if (!graphs::size(arrays))
|
||||
return 1;
|
||||
@ -1012,7 +1012,7 @@ namespace graphs
|
||||
|
||||
// Convert single array to graph and output
|
||||
template <typename T>
|
||||
int plot(size_t height, size_t width, long double xmin, long double xmax, long double ymin, long double ymax, const T &aarray, const options &aoptions = defaultoptions)
|
||||
int plot(size_t height, size_t width, long double xmin, long double xmax, long double ymin, long double ymax, const T &aarray, const options &aoptions = {})
|
||||
{
|
||||
const std::array<T, 1> aaarray = {aarray};
|
||||
|
||||
@ -1021,7 +1021,7 @@ namespace graphs
|
||||
|
||||
// Convert single array to graph and output
|
||||
template <typename T>
|
||||
int plot(size_t height, size_t width, long double xmin, long double xmax, long double ymin, long double ymax, const size_t rows, T **aarray, const options &aoptions = defaultoptions)
|
||||
int plot(size_t height, size_t width, long double xmin, long double xmax, long double ymin, long double ymax, const size_t rows, T **aarray, const options &aoptions = {})
|
||||
{
|
||||
if (rows == 0)
|
||||
return 1;
|
||||
@ -1036,7 +1036,7 @@ namespace graphs
|
||||
|
||||
// Convert one or more functions to graph and output
|
||||
template <typename T>
|
||||
int functions(size_t height, size_t width, const long double xmin, const long double xmax, const long double ymin, const long double ymax, const size_t numfunctions, function<T(T)> functions[], const options &aoptions = defaultoptions)
|
||||
int functions(size_t height, size_t width, const long double xmin, const long double xmax, const long double ymin, const long double ymax, const size_t numfunctions, function<T(T)> functions[], const options &aoptions = {})
|
||||
{
|
||||
const color_type color = aoptions.color;
|
||||
|
||||
@ -1125,7 +1125,7 @@ namespace graphs
|
||||
|
||||
// Convert single function to function array and output
|
||||
template <typename T>
|
||||
int function(size_t height, size_t width, const long double xmin, const long double xmax, const long double ymin, const long double ymax, const function<T(T)> &afunction, const options &aoptions = defaultoptions)
|
||||
int function(size_t height, size_t width, const long double xmin, const long double xmax, const long double ymin, const long double ymax, const function<T(T)> &afunction, const options &aoptions = {})
|
||||
{
|
||||
std::function<T(T)> afunctions[] = {afunction};
|
||||
|
||||
@ -1134,7 +1134,7 @@ namespace graphs
|
||||
|
||||
// Convert single function to function array and output
|
||||
template <typename T>
|
||||
int function(size_t height, size_t width, const long double xmin, const long double xmax, const long double ymin, const long double ymax, T afunction(T), const options &aoptions = defaultoptions)
|
||||
int function(size_t height, size_t width, const long double xmin, const long double xmax, const long double ymin, const long double ymax, T afunction(T), const options &aoptions = {})
|
||||
{
|
||||
std::function<T(T)> afunctions[] = {afunction};
|
||||
|
||||
|
16
tables.hpp
16
tables.hpp
@ -65,8 +65,6 @@ namespace tables
|
||||
bool check = true;
|
||||
};
|
||||
|
||||
const options defaultoptions;
|
||||
|
||||
template <typename T>
|
||||
constexpr size_t size(const T &array)
|
||||
{
|
||||
@ -75,7 +73,7 @@ namespace tables
|
||||
|
||||
// Number of columns needed to represent the string
|
||||
// Adapted from: https://stackoverflow.com/a/31124065
|
||||
int strcol(const char *str)
|
||||
inline int strcol(const char *str)
|
||||
{
|
||||
const string astr = regex_replace(str, ansi, "");
|
||||
str = astr.c_str();
|
||||
@ -123,7 +121,7 @@ namespace tables
|
||||
// Word wrap
|
||||
// Source: https://gist.github.com/tdulcet/819821ca69501822ad3f84a060c640a0
|
||||
// Adapted from: https://stackoverflow.com/a/42016346 and https://stackoverflow.com/a/13094734
|
||||
string wrap(const char *const str, const size_t line_length)
|
||||
inline string wrap(const char *const str, const size_t line_length)
|
||||
{
|
||||
string words = str;
|
||||
string wrapped;
|
||||
@ -352,7 +350,7 @@ namespace tables
|
||||
|
||||
// Convert array to char array and output as table
|
||||
template <typename T1, typename T2>
|
||||
int array(const T1 &aarray, T2 headerrow[] = nullptr, T2 headercolumn[] = nullptr, const options &aoptions = defaultoptions)
|
||||
int array(const T1 &aarray, T2 headerrow[] = nullptr, T2 headercolumn[] = nullptr, const options &aoptions = {})
|
||||
{
|
||||
if (!tables::size(aarray))
|
||||
return 1;
|
||||
@ -423,7 +421,7 @@ namespace tables
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int array(const size_t rows, const size_t columns, T **aarray, const char *const headerrow[] = nullptr, const char *const headercolumn[] = nullptr, const options &aoptions = defaultoptions)
|
||||
int array(const size_t rows, const size_t columns, T **aarray, const char *const headerrow[] = nullptr, const char *const headercolumn[] = nullptr, const options &aoptions = {})
|
||||
{
|
||||
vector<vector<T>> aaarray(rows, vector<T>(columns));
|
||||
for (size_t i = 0; i < rows; ++i)
|
||||
@ -460,7 +458,7 @@ namespace tables
|
||||
|
||||
// Convert one or more functions to array and output as table
|
||||
template <typename T>
|
||||
int functions(const long double xmin, const long double xmax, const long double xstep, const size_t numfunctions, function<T(T)> functions[], const options &aoptions = defaultoptions)
|
||||
int functions(const long double xmin, const long double xmax, const long double xstep, const size_t numfunctions, function<T(T)> functions[], const options &aoptions = {})
|
||||
{
|
||||
if (numfunctions == 0)
|
||||
return 1;
|
||||
@ -538,7 +536,7 @@ namespace tables
|
||||
|
||||
// Convert single function to array and output as table
|
||||
template <typename T>
|
||||
int function(const long double xmin, const long double xmax, const long double xstep, const function<T(T)> &afunction, const options &aoptions = defaultoptions)
|
||||
int function(const long double xmin, const long double xmax, const long double xstep, const function<T(T)> &afunction, const options &aoptions = {})
|
||||
{
|
||||
std::function<T(T)> afunctions[] = {afunction};
|
||||
|
||||
@ -547,7 +545,7 @@ namespace tables
|
||||
|
||||
// Convert single function to array and output as table
|
||||
template <typename T>
|
||||
int function(const long double xmin, const long double xmax, const long double xstep, T afunction(T), const options &aoptions = defaultoptions)
|
||||
int function(const long double xmin, const long double xmax, const long double xstep, T afunction(T), const options &aoptions = {})
|
||||
{
|
||||
std::function<T(T)> afunctions[] = {afunction};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user