mirror of
https://github.com/tdulcet/Table-and-Graph-Libs.git
synced 2025-05-05 21:41:12 +08:00
support c++14
This commit is contained in:
parent
4c4a70ad6d
commit
7165fd29da
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
@ -27,9 +27,9 @@ jobs:
|
||||
$CXX --version
|
||||
- name: Script
|
||||
run: |
|
||||
$CXX -std=c++17 -Wall -g -Og -fsanitize=address,undefined tables.cpp -o tables
|
||||
$CXX -std=c++14 -Wall -g -Og -fsanitize=address,undefined tables.cpp -o tables
|
||||
./tables
|
||||
$CXX -std=c++17 -Wall -g -Og -fsanitize=address,undefined graphs.cpp -o graphs
|
||||
$CXX -std=c++14 -Wall -g -Og -fsanitize=address,undefined graphs.cpp -o graphs
|
||||
./graphs
|
||||
- name: Cppcheck
|
||||
run: cppcheck --enable=all .
|
||||
|
@ -13,12 +13,12 @@ install:
|
||||
- sudo apt-get -yqq update
|
||||
- sudo apt-get -yqq install cppcheck
|
||||
script:
|
||||
- g++ -std=c++17 -Wall -g -Og -fsanitize=address,undefined tables.cpp -o gcc_tables
|
||||
- g++ -std=c++14 -Wall -g -Og -fsanitize=address,undefined tables.cpp -o gcc_tables
|
||||
- ./gcc_tables
|
||||
- g++ -std=c++17 -Wall -g -Og -fsanitize=address,undefined graphs.cpp -o gcc_graphs
|
||||
- g++ -std=c++14 -Wall -g -Og -fsanitize=address,undefined graphs.cpp -o gcc_graphs
|
||||
- ./gcc_graphs
|
||||
- clang++ -std=c++17 -Wall -g -Og -fsanitize=address,undefined,integer tables.cpp -o clang_tables
|
||||
- clang++ -std=c++14 -Wall -g -Og -fsanitize=address,undefined,integer tables.cpp -o clang_tables
|
||||
- ./clang_tables
|
||||
- clang++ -std=c++17 -Wall -g -Og -fsanitize=address,undefined,integer graphs.cpp -o clang_graphs
|
||||
- clang++ -std=c++14 -Wall -g -Og -fsanitize=address,undefined,integer graphs.cpp -o clang_graphs
|
||||
- ./clang_graphs
|
||||
- cppcheck --enable=all .
|
||||
|
14
README.md
14
README.md
@ -17,14 +17,14 @@ See the [python](python) directory for Python ports of the libraries.
|
||||
|
||||
### Usage
|
||||
|
||||
Requires support for C++17. See the [tables.hpp](tables.hpp) file for full usage information.
|
||||
Requires support for C++14. See the [tables.hpp](tables.hpp) file for full usage information.
|
||||
|
||||
Complete versions of all of the examples below and more can be found in the [tables.cpp](tables.cpp) file.
|
||||
|
||||
Compile with:
|
||||
|
||||
GCC: `g++ -std=c++17 -Wall -g -O3 tables.cpp -o tables`\
|
||||
Clang: `clang++ -std=c++17 -Wall -g -O3 tables.cpp -o tables`
|
||||
GCC: `g++ -std=c++14 -Wall -g -O3 tables.cpp -o tables`\
|
||||
Clang: `clang++ -std=c++14 -Wall -g -O3 tables.cpp -o tables`
|
||||
|
||||
Run with: `./tables`
|
||||
|
||||
@ -267,7 +267,7 @@ template <typename T>
|
||||
bool compare(const T &a, const T &b)
|
||||
{
|
||||
if (a[sortdimension] == b[sortdimension])
|
||||
for (int i = 0; i < size(a); ++i)
|
||||
for (int i = 0; i < tables::size(a); ++i)
|
||||
if (sortdimension != i and a[i] != b[i])
|
||||
return a[i] < b[i];
|
||||
|
||||
@ -512,13 +512,13 @@ Values:
|
||||
|
||||
### Usage
|
||||
|
||||
Requires support for C++17. See the [graphs.hpp](graphs.hpp) file for full usage information.
|
||||
Requires support for C++14. See the [graphs.hpp](graphs.hpp) file for full usage information.
|
||||
|
||||
Complete versions of all of the examples below and more can be found in the [graphs.cpp](graphs.cpp) file.
|
||||
|
||||
Compile with:
|
||||
GCC: `g++ -std=c++17 -Wall -g -O3 graphs.cpp -o graphs`\
|
||||
Clang: `clang++ -std=c++17 -Wall -g -O3 graphs.cpp -o graphs`
|
||||
GCC: `g++ -std=c++14 -Wall -g -O3 graphs.cpp -o graphs`\
|
||||
Clang: `clang++ -std=c++14 -Wall -g -O3 graphs.cpp -o graphs`
|
||||
|
||||
Run with: `./graphs`
|
||||
|
||||
|
18
graphs.cpp
18
graphs.cpp
@ -1,6 +1,6 @@
|
||||
// Teal Dulcet, CS546
|
||||
|
||||
// Compile: g++ -Wall -g -O3 -std=c++17 graphs.cpp -o graphs
|
||||
// Compile: g++ -Wall -g -O3 -std=c++14 graphs.cpp -o graphs
|
||||
|
||||
// Run: ./graphs
|
||||
|
||||
@ -68,7 +68,7 @@ int main()
|
||||
|
||||
graphs::options aoptions;
|
||||
|
||||
for (unsigned int k = 0; k < size(graphs::styles); ++k)
|
||||
for (unsigned int k = 0; k < graphs::size(graphs::styles); ++k)
|
||||
{
|
||||
aoptions.style = k;
|
||||
|
||||
@ -92,7 +92,7 @@ int main()
|
||||
|
||||
graphs::options aoptions;
|
||||
|
||||
for (unsigned int k = 0; k < size(graphs::styles); ++k)
|
||||
for (unsigned int k = 0; k < graphs::size(graphs::styles); ++k)
|
||||
{
|
||||
aoptions.style = k;
|
||||
|
||||
@ -108,7 +108,7 @@ int main()
|
||||
|
||||
graphs::options aoptions;
|
||||
|
||||
for (unsigned int k = 0; k < size(graphs::styles); ++k)
|
||||
for (unsigned int k = 0; k < graphs::size(graphs::styles); ++k)
|
||||
{
|
||||
aoptions.style = k;
|
||||
|
||||
@ -120,7 +120,7 @@ int main()
|
||||
{
|
||||
graphs::options aoptions;
|
||||
|
||||
for (unsigned int k = 0; k < size(graphs::styles); ++k)
|
||||
for (unsigned int k = 0; k < graphs::size(graphs::styles); ++k)
|
||||
{
|
||||
aoptions.style = k;
|
||||
|
||||
@ -133,7 +133,7 @@ int main()
|
||||
|
||||
graphs::options aoptions;
|
||||
|
||||
for (unsigned int k = 0; k < size(graphs::styles); ++k)
|
||||
for (unsigned int k = 0; k < graphs::size(graphs::styles); ++k)
|
||||
{
|
||||
aoptions.style = k;
|
||||
|
||||
@ -147,7 +147,7 @@ int main()
|
||||
|
||||
graphs::options aoptions;
|
||||
|
||||
for (unsigned int k = 0; k < size(graphs::styles); ++k)
|
||||
for (unsigned int k = 0; k < graphs::size(graphs::styles); ++k)
|
||||
{
|
||||
aoptions.style = k;
|
||||
|
||||
@ -162,7 +162,7 @@ int main()
|
||||
|
||||
graphs::options aoptions;
|
||||
|
||||
for (unsigned int k = 0; k < size(graphs::styles); ++k)
|
||||
for (unsigned int k = 0; k < graphs::size(graphs::styles); ++k)
|
||||
{
|
||||
aoptions.style = k;
|
||||
|
||||
@ -181,7 +181,7 @@ int main()
|
||||
aoptions.axisunitslabel = false;
|
||||
// graphs::options aoptions{.axisunitslabel = false};
|
||||
|
||||
for (unsigned int k = 0; k < size(graphs::styles); ++k)
|
||||
for (unsigned int k = 0; k < graphs::size(graphs::styles); ++k)
|
||||
{
|
||||
aoptions.style = k;
|
||||
|
||||
|
28
graphs.hpp
28
graphs.hpp
@ -55,6 +55,12 @@ namespace graphs
|
||||
|
||||
const options defaultoptions;
|
||||
|
||||
template <typename T>
|
||||
auto size(const T &array)
|
||||
{
|
||||
return distance(begin(array), end(array));
|
||||
}
|
||||
|
||||
// Number of columns needed to represent the string
|
||||
// Adapted from: https://stackoverflow.com/a/31124065
|
||||
int strcol(const char *const str)
|
||||
@ -159,7 +165,7 @@ namespace graphs
|
||||
long double intpart = 0;
|
||||
long double fractionpart = abs(modf(label, &intpart));
|
||||
|
||||
for (unsigned int i = 0; i < size(fractions) and !output; ++i)
|
||||
for (unsigned int i = 0; i < graphs::size(fractions) and !output; ++i)
|
||||
{
|
||||
if (abs(fractionpart - fractionvalues[i]) < DBL_EPSILON)
|
||||
{
|
||||
@ -217,7 +223,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)
|
||||
{
|
||||
if (!size(array))
|
||||
if (!graphs::size(array))
|
||||
return 1;
|
||||
|
||||
const bool border = aoptions.border;
|
||||
@ -226,7 +232,7 @@ namespace graphs
|
||||
const char *const title = aoptions.title;
|
||||
const unsigned int style = aoptions.style;
|
||||
|
||||
if (style >= size(styles))
|
||||
if (style >= graphs::size(styles))
|
||||
return 1;
|
||||
|
||||
if (height == 0)
|
||||
@ -492,12 +498,12 @@ namespace graphs
|
||||
template <typename T>
|
||||
int arrays(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)
|
||||
{
|
||||
if (!size(arrays))
|
||||
if (!graphs::size(arrays))
|
||||
return 1;
|
||||
|
||||
if (!all_of(begin(arrays), end(arrays), [](const auto &array)
|
||||
{ return all_of(begin(array), end(array), [](const auto &x)
|
||||
{ return size(x) == 2; }); }))
|
||||
{ return graphs::size(x) == 2; }); }))
|
||||
{
|
||||
cerr << "Error: The arrays must have two columns.";
|
||||
return 1;
|
||||
@ -505,7 +511,7 @@ namespace graphs
|
||||
|
||||
const unsigned int color = aoptions.color;
|
||||
|
||||
if (color >= size(colors))
|
||||
if (color >= graphs::size(colors))
|
||||
return 1;
|
||||
|
||||
struct winsize w;
|
||||
@ -571,12 +577,12 @@ namespace graphs
|
||||
|
||||
vector<vector<unsigned short>> aarray(width, vector<unsigned short>(height, 0));
|
||||
|
||||
for (unsigned int j = 0; j < size(arrays); ++j)
|
||||
for (unsigned int j = 0; j < graphs::size(arrays); ++j)
|
||||
{
|
||||
auto array = arrays[j];
|
||||
const unsigned int color = (j % (size(colors) - 2)) + 3;
|
||||
const unsigned int color = (j % (graphs::size(colors) - 2)) + 3;
|
||||
|
||||
for (unsigned int i = 0; i < size(array); ++i)
|
||||
for (unsigned int i = 0; i < graphs::size(array); ++i)
|
||||
{
|
||||
if (array[i][0] >= xmin and array[i][0] < xmax and array[i][1] >= ymin and array[i][1] < ymax)
|
||||
{
|
||||
@ -627,7 +633,7 @@ namespace graphs
|
||||
{
|
||||
const unsigned int color = aoptions.color;
|
||||
|
||||
if (color >= size(colors))
|
||||
if (color >= graphs::size(colors))
|
||||
return 1;
|
||||
|
||||
if (numfunctions == 0)
|
||||
@ -680,7 +686,7 @@ namespace graphs
|
||||
|
||||
for (unsigned int j = 0; j < numfunctions; ++j)
|
||||
{
|
||||
unsigned short acolor = numfunctions == 1 ? color + 1 : (j % (size(colors) - 2)) + 3;
|
||||
unsigned short acolor = numfunctions == 1 ? color + 1 : (j % (graphs::size(colors) - 2)) + 3;
|
||||
|
||||
for (long double i = 0; i < rows; i += 0.5)
|
||||
{
|
||||
|
38
tables.cpp
38
tables.cpp
@ -1,6 +1,6 @@
|
||||
// Teal Dulcet, CS546
|
||||
|
||||
// Compile: g++ -Wall -g -O3 -std=c++17 tables.cpp -o tables
|
||||
// Compile: g++ -Wall -g -O3 -std=c++14 tables.cpp -o tables
|
||||
|
||||
// Run: ./tables
|
||||
|
||||
@ -96,7 +96,7 @@ int main()
|
||||
|
||||
tables::options aoptions;
|
||||
|
||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
||||
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||
{
|
||||
aoptions.style = k;
|
||||
|
||||
@ -120,7 +120,7 @@ int main()
|
||||
|
||||
tables::options aoptions;
|
||||
|
||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
||||
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||
{
|
||||
aoptions.style = k;
|
||||
|
||||
@ -136,7 +136,7 @@ int main()
|
||||
|
||||
tables::options aoptions;
|
||||
|
||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
||||
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||
{
|
||||
aoptions.style = k;
|
||||
|
||||
@ -155,7 +155,7 @@ int main()
|
||||
|
||||
tables::options aoptions;
|
||||
|
||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
||||
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||
{
|
||||
aoptions.style = k;
|
||||
|
||||
@ -179,7 +179,7 @@ int main()
|
||||
|
||||
tables::options aoptions;
|
||||
|
||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
||||
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||
{
|
||||
aoptions.style = k;
|
||||
|
||||
@ -195,7 +195,7 @@ int main()
|
||||
|
||||
tables::options aoptions;
|
||||
|
||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
||||
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||
{
|
||||
aoptions.style = k;
|
||||
|
||||
@ -217,7 +217,7 @@ int main()
|
||||
aoptions.headercolumn = true;
|
||||
// tables::options aoptions{.headerrow = true, .headercolumn = true};
|
||||
|
||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
||||
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||
{
|
||||
aoptions.style = k;
|
||||
|
||||
@ -236,7 +236,7 @@ int main()
|
||||
aoptions.headercolumn = true;
|
||||
// tables::options aoptions{.headerrow = true, .headercolumn = true};
|
||||
|
||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
||||
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||
{
|
||||
aoptions.style = k;
|
||||
|
||||
@ -263,7 +263,7 @@ int main()
|
||||
aoptions.headercolumn = true;
|
||||
// tables::options aoptions{.headerrow = true, .headercolumn = true};
|
||||
|
||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
||||
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||
{
|
||||
aoptions.style = k;
|
||||
|
||||
@ -286,7 +286,7 @@ int main()
|
||||
vector<string> aheadercolumn(headerrow, headerrow + 1);
|
||||
aheadercolumn.insert(aheadercolumn.end(), headercolumn, headercolumn + columns - 1);
|
||||
|
||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
||||
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||
{
|
||||
{
|
||||
tables::options aoptions;
|
||||
@ -413,7 +413,7 @@ int main()
|
||||
aoptions.boolalpha = true;
|
||||
// tables::options aoptions{.boolalpha = true};
|
||||
|
||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
||||
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||
{
|
||||
aoptions.style = k;
|
||||
|
||||
@ -448,7 +448,7 @@ int main()
|
||||
|
||||
tables::options aoptions;
|
||||
|
||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
||||
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||
{
|
||||
aoptions.style = k;
|
||||
|
||||
@ -477,7 +477,7 @@ int main()
|
||||
|
||||
tables::options aoptions;
|
||||
|
||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
||||
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||
{
|
||||
aoptions.style = k;
|
||||
|
||||
@ -498,7 +498,7 @@ int main()
|
||||
|
||||
tables::options aoptions;
|
||||
|
||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
||||
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||
{
|
||||
aoptions.style = k;
|
||||
|
||||
@ -512,7 +512,7 @@ int main()
|
||||
aoptions.headerrow = true;
|
||||
// tables::options aoptions{.headerrow = true};
|
||||
|
||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
||||
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||
{
|
||||
aoptions.style = k;
|
||||
|
||||
@ -527,7 +527,7 @@ int main()
|
||||
aoptions.headerrow = true;
|
||||
// tables::options aoptions{.headerrow = true};
|
||||
|
||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
||||
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||
{
|
||||
aoptions.style = k;
|
||||
|
||||
@ -543,7 +543,7 @@ int main()
|
||||
aoptions.headerrow = true;
|
||||
// tables::options aoptions{.headerrow = true};
|
||||
|
||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
||||
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||
{
|
||||
aoptions.style = k;
|
||||
|
||||
@ -560,7 +560,7 @@ int main()
|
||||
aoptions.headerrow = true;
|
||||
// tables::options aoptions{.headerrow = true};
|
||||
|
||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
||||
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||
{
|
||||
aoptions.style = k;
|
||||
|
||||
|
20
tables.hpp
20
tables.hpp
@ -45,6 +45,12 @@ namespace tables
|
||||
|
||||
const options defaultoptions;
|
||||
|
||||
template <typename T>
|
||||
auto size(const T &array)
|
||||
{
|
||||
return distance(begin(array), end(array));
|
||||
}
|
||||
|
||||
// Number of columns needed to represent the string
|
||||
// Adapted from: https://stackoverflow.com/a/31124065
|
||||
int strcol(const char *str)
|
||||
@ -148,7 +154,7 @@ namespace tables
|
||||
template <typename T>
|
||||
int table(const vector<vector<basic_string<T>>> &array, const options &aoptions)
|
||||
{
|
||||
if (!size(array))
|
||||
if (!tables::size(array))
|
||||
return 1;
|
||||
|
||||
const bool headerrow = aoptions.headerrow;
|
||||
@ -159,7 +165,7 @@ namespace tables
|
||||
const char *const title = aoptions.title;
|
||||
const unsigned int style = aoptions.style;
|
||||
|
||||
if (style >= size(styles))
|
||||
if (style >= tables::size(styles))
|
||||
return 1;
|
||||
|
||||
const size_t rows = array.size();
|
||||
@ -322,17 +328,17 @@ namespace tables
|
||||
template <typename T1, typename T2>
|
||||
int array(const T1 &aarray, T2 headerrow[] = nullptr, T2 headercolumn[] = nullptr, const options &aoptions = defaultoptions)
|
||||
{
|
||||
if (!size(aarray))
|
||||
if (!tables::size(aarray))
|
||||
return 1;
|
||||
|
||||
unsigned int i = 0;
|
||||
unsigned int j = 0;
|
||||
|
||||
size_t rows = size(aarray);
|
||||
size_t columns = size(aarray[0]);
|
||||
size_t rows = tables::size(aarray);
|
||||
size_t columns = tables::size(aarray[0]);
|
||||
|
||||
if (!all_of(begin(aarray), end(aarray), [columns](auto &x)
|
||||
{ return size(x) == columns; }))
|
||||
{ return tables::size(x) == columns; }))
|
||||
{
|
||||
cerr << "Error: The rows of the array must have the same number of columns.";
|
||||
return 1;
|
||||
@ -451,7 +457,7 @@ namespace tables
|
||||
const char *const aheaderrow[] = {"x", "y"};
|
||||
// const char* const aheaderrow[] = {"", "x", "y"};
|
||||
|
||||
const size_t length = size(aheaderrow);
|
||||
const size_t length = tables::size(aheaderrow);
|
||||
|
||||
string *headerrow = new string[columns];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user