|
Antiprism 0.23
|
utility routines for maths operations. More...
#include <stdio.h>#include <stdlib.h>#include <string>#include <vector>#include "vec3d.h"#include "vec4d.h"#include "mat3d.h"#include "geom.h"#include "utils_ultragetopt.h"

Classes | |
| class | prog_opts |
| Command line processing. More... | |
Functions | |
| const char * | basename2 (const char *path) |
| Get the Basename. | |
| string | dots2underscores (string str) |
| Convert dots to underscores. | |
| bool | read_double (const char *str, double *f, char *errmsg=0) |
| Read a floating point number, which may be a mathematical expression, from a string. | |
| bool | read_double_noparse (const char *str, double *f, char *errmsg=0) |
| Read a floating point number from a string. | |
| bool | read_int (const char *str, int *i, char *errmsg=0) |
| Read an integer from a string. | |
| bool | read_double_list (vector< char * > &vals, vector< double > &nums, char *errmsg=0) |
| Read floating point numbers, which may be maththematical expressions, from a list of strings. | |
| bool | read_double_list_noparse (vector< char * > &vals, vector< double > &nums, char *errmsg=0) |
| Read floating point numbers from a list of strings. | |
| bool | read_double_list (char *str, vector< double > &nums, char *errmsg=0, int len=0, const char *sep=",") |
| Read floating point numbers, which may be mathematical expressions, listed in a single string. | |
| bool | read_double_list_noparse (char *str, vector< double > &nums, char *errmsg=0, int len=0, const char *sep=",") |
| Read floating point numbers listed in a single string. | |
| bool | read_int_list (vector< char * > &vals, vector< int > &nums, char *errmsg=0, bool is_index=false) |
| Read integers from a list of strings. | |
| bool | read_int_list (char *str, vector< int > &nums, char *errmsg=0, bool is_index=false, int len=0, const char *sep=",") |
| Read integers listed in a single string. | |
| bool | read_idx_list (char *str, vector< int > &nums, int num_idxs, bool allow_extra=false, char *errmsg=0) |
| Read index numbers listed in a single string. | |
| int | read_line (FILE *file, char **line) |
| Read a line of arbitrary length. | |
| int | split_line (char *line, vector< char * > &parts, const char *delims=0, bool strict=false) |
| Split a line into delimited parts. | |
| char * | clear_extra_whitespace (char *str) |
| Remove leading and trailing space, convert any whitespace to a single space. | |
| char * | to_resource_name (char *to, const char *from) |
| Convert to a normalised resource name. | |
| FILE * | open_sup_file (const char *fname, const char *subdir, string *alt_name=0, int *where=0, string *fpath=0) |
| Open a support file. | |
| string | msg_str (const char *fmt,...) |
| char * | copy_str (const char *str) |
| string | itostr (int i) |
| Convert an integer to a string. | |
| char * | itostr (char *buf, int i) |
| Convert an integer to a string. | |
| string | dtostr (double f, int sig_dgts=17) |
| Convert a floating point number to a string. | |
| char * | dtostr (char *buf, double f, int sig_dgts=17) |
| Convert a floating point number to a string. | |
| string | vtostr (vec3d v, const char *sep=", ", int sig_dgts=17) |
| Convert a coordinate vector to a string. | |
| char * | vtostr (char *buf, vec3d v, const char *sep=", ", int sig_dgts=17) |
| Convert a coordinate vector to a string. | |
| char * | vtostr (char *buf, vec4d v, const char *sep=", ", int sig_dgts=17) |
| Convert a coordinate vector to a string. | |
utility routines for maths operations.
| const char* basename2 | ( | const char * | path | ) |
Get the Basename.
Get the name of the file from a path. This is taken as the last part of the path after any '%\' or '/', otherwise the path is the file name.
| path | the path to the file. |
| char* clear_extra_whitespace | ( | char * | str | ) |
Remove leading and trailing space, convert any whitespace to a single space.
| str | the string to convert. |
| char* copy_str | ( | const char * | str | ) |
The copy is dynamically allocated and must be freed with free()
| str | the string to copy |
| string dots2underscores | ( | string | str | ) |
Convert dots to underscores.
| str | the string to convert. |
| string dtostr | ( | double | f, |
| int | sig_dgts = 17 |
||
| ) | [inline] |
Convert a floating point number to a string.
| f | the floating point number. |
| sig_dgts | the number of significant digits in the conversion, or if negative then the number of digits after the decimal point. |
| char * dtostr | ( | char * | buf, |
| double | f, | ||
| int | sig_dgts = 17 |
||
| ) | [inline] |
Convert a floating point number to a string.
| buf | a buffer to return the string. |
| f | the floating point number. |
| sig_dgts | the number of significant digits in the conversion, or if negative then the number of digits after the decimal point. |
| char * itostr | ( | char * | buf, |
| int | i | ||
| ) | [inline] |
Convert an integer to a string.
| buf | a buffer to return the string. |
| i | the integer. |
| string itostr | ( | int | i | ) | [inline] |
Convert an integer to a string.
| i | the integer. |
| string msg_str | ( | const char * | fmt, |
| ... | |||
| ) |
Converts the first MSG_SZ-1 characters of the C format string
| fmt | the formatted string |
| ... | the values for the format |
| FILE* open_sup_file | ( | const char * | fname, |
| const char * | subdir, | ||
| string * | alt_name = 0, |
||
| int * | where = 0, |
||
| string * | fpath = 0 |
||
| ) |
Open a support file.
Tries to open a file by its name, then tries to open it in $ANTIPRISM_DATA/sub_dir, finally tries to open it in sub_dir in the installation data directory.
| fname | the name of the file to open. |
| subdir | the data directory subdirectory to search in. |
| alt_name | a name that is found in an alt_names.txt file before a file with the name is found. |
| where | used to return the place that the file was found
|
| fpath | used to return the full path to the file that was found. |
| bool read_double | ( | const char * | str, |
| double * | f, | ||
| char * | errmsg = 0 |
||
| ) |
Read a floating point number, which may be a mathematical expression, from a string.
The string should only hold the floating point number or expression, but may have leading and trailing whitespace.
| str | the string holding the floating point number or expressions. |
| f | used to return the floating point number. |
| errmsg | an array at least MSG_SZ chars long to return any error message. |
| bool read_double_list | ( | char * | str, |
| vector< double > & | nums, | ||
| char * | errmsg = 0, |
||
| int | len = 0, |
||
| const char * | sep = "," |
||
| ) |
Read floating point numbers, which may be mathematical expressions, listed in a single string.
The numbers in the string should be comma separated, and may have leading and trailing whitespace.
| str | the string holding the comma-separated floating point numbers. |
| nums | used to return the floating point numbers. |
| errmsg | an array at least MSG_SZ chars long to return any error message. |
| len | the maximum total of numbers that should be in str, or if it is 0 then there is no maximum. |
| sep | the characters that can separate the numbers. |
len>0), otherwise false. and the error is detailed in errmsg. | bool read_double_list | ( | vector< char * > & | vals, |
| vector< double > & | nums, | ||
| char * | errmsg = 0 |
||
| ) |
Read floating point numbers, which may be maththematical expressions, from a list of strings.
The strings should only hold the floating point number, but may have leading and trailing whitespace.
| vals | the strings holding the floating point numbers. |
| nums | used to return the floating point numbers. |
| errmsg | an array at least MSG_SZ chars long to return any error message. |
| bool read_double_list_noparse | ( | char * | str, |
| vector< double > & | nums, | ||
| char * | errmsg = 0, |
||
| int | len = 0, |
||
| const char * | sep = "," |
||
| ) |
Read floating point numbers listed in a single string.
The numbers in the string should be comma separated, and may have leading and trailing whitespace.
| str | the string holding the comma-separated floating point numbers. |
| nums | used to return the floating point numbers. |
| errmsg | an array at least MSG_SZ chars long to return any error message. |
| len | the maximum total of numbers that should be in str, or if it is 0 then there is no maximum. |
| sep | the characters that can separate the numbers. |
len>0), otherwise false. and the error is detailed in errmsg. | bool read_double_list_noparse | ( | vector< char * > & | vals, |
| vector< double > & | nums, | ||
| char * | errmsg = 0 |
||
| ) |
Read floating point numbers from a list of strings.
The strings should only hold the floating point number, but may have leading and trailing whitespace.
| vals | the strings holding the floating point numbers. |
| nums | used to return the floating point numbers. |
| errmsg | an array at least MSG_SZ chars long to return any error message. |
| bool read_double_noparse | ( | const char * | str, |
| double * | f, | ||
| char * | errmsg = 0 |
||
| ) |
Read a floating point number from a string.
The string should only hold the floating point number, but may have leading and trailing whitespace.
| str | the string holding the floating point number. |
| f | used to return the floating point number. |
| errmsg | an array at least MSG_SZ chars long to return any error message. |
| bool read_idx_list | ( | char * | str, |
| vector< int > & | nums, | ||
| int | num_idxs, | ||
| bool | allow_extra = false, |
||
| char * | errmsg = 0 |
||
| ) |
Read index numbers listed in a single string.
The string consists of comma separated index number ranges, and may have leading and trailing whitespace. A number range is either a single number, or a sequential list indicated by two numbers seperated by '-'. If the numbers are not given they default to the first and last index number respectively.
| str | the string holding the comma-separated integers. |
| nums | used to return the integers. |
| num_idxs | index numbers with this value or higher are out of range |
| allow_extra | allow out-of-range index numbers, prefixed by an x or X, which are indexed relative to num_idxs, i.e. X0 = num_idxs. |
| errmsg | an array at least MSG_SZ chars long to return any error message. |
| bool read_int | ( | const char * | str, |
| int * | i, | ||
| char * | errmsg = 0 |
||
| ) |
Read an integer from a string.
The string should only hold the integer, but may have leading and trailing whitespace.
| str | the string holding the integer. |
| i | used to return the integer. |
| errmsg | an array at least MSG_SZ chars long to return any error message. |
| bool read_int_list | ( | vector< char * > & | vals, |
| vector< int > & | nums, | ||
| char * | errmsg = 0, |
||
| bool | is_index = false |
||
| ) |
Read integers from a list of strings.
The strings should only hold the integers, but may have leading and trailing whitespace.
| vals | the strings holding the integers. |
| nums | used to return the integers. |
| errmsg | an array at least MSG_SZ chars long to return any error message. |
| is_index | if true then the integers cannot be negative. |
| bool read_int_list | ( | char * | str, |
| vector< int > & | nums, | ||
| char * | errmsg = 0, |
||
| bool | is_index = false, |
||
| int | len = 0, |
||
| const char * | sep = "," |
||
| ) |
Read integers listed in a single string.
The numbers in the string should be comma separated, and may have leading and trailing whitespace.
| str | the string holding the comma-separated integers. |
| nums | used to return the integers. |
| errmsg | an array at least MSG_SZ chars long to return any error message. |
| is_index | if true then the integers cannot be negative. |
| len | the maximum total of numbers that should be in str, or if it is 0 then there is no maximum. |
| sep | the characters that can separate the numbers. |
len>0), otherwise false. and the error is detailed in errmsg. | int read_line | ( | FILE * | file, |
| char ** | line | ||
| ) |
Read a line of arbitrary length.
The caller is responsible for freeing the memory allocated to line after each read.
| file | the file stream to read from. |
| line | where the line is returned |
0 if the line was read correctly. -1 if memory for line could not be allocated. 1 if an final unterminated empty line was read. | int split_line | ( | char * | line, |
| vector< char * > & | parts, | ||
| const char * | delims = 0, |
||
| bool | strict = false |
||
| ) |
Split a line into delimited parts.
| line | the line to split (this will be modified). |
| parts | the parts of the split line. |
| delims | the characters to use as delimiters, if 0 then use whitespace characters. |
| strict | if true then treat every delimiter as a separator, returning null strings between adjacent delimiters, always returning at least one part. |
| char* to_resource_name | ( | char * | to, |
| const char * | from | ||
| ) |
Convert to a normalised resource name.
Remove leading and trailing space, convert any whitespace to a single space, make lowercase
| to | the string to convert (up to MSG_SZ-1 characters used.) |
| from | the string to convert (length MSG_SZ.) |
| char * vtostr | ( | char * | buf, |
| vec4d | v, | ||
| const char * | sep = ", ", |
||
| int | sig_dgts = 17 |
||
| ) | [inline] |
Convert a coordinate vector to a string.
| buf | a buffer to return the string. |
| v | the vector. |
| sep | the separator between the numbers. |
| sig_dgts | the number of significant digits in the conversion, or if negative then the number of digits after the decimal point. |
| string vtostr | ( | vec3d | v, |
| const char * | sep = ", ", |
||
| int | sig_dgts = 17 |
||
| ) | [inline] |
Convert a coordinate vector to a string.
| v | the vector. |
| sep | the separator between the numbers. |
| sig_dgts | the number of significant digits in the conversion, or if negative then the number of digits after the decimal point. |
| char * vtostr | ( | char * | buf, |
| vec3d | v, | ||
| const char * | sep = ", ", |
||
| int | sig_dgts = 17 |
||
| ) | [inline] |
Convert a coordinate vector to a string.
| buf | a buffer to return the string. |
| v | the vector. |
| sep | the separator between the numbers. |
| sig_dgts | the number of significant digits in the conversion, or if negative then the number of digits after the decimal point. |
1.7.3