pdal::Utils
¶
:cpp:namespace:`pdal::Utils` is a set of utility functions.
-
namespace
pdal
::
Utils
¶ Typedefs
-
using
BacktraceEntries
= std::deque<BacktraceEntry>¶
Functions
-
std::string
toJSON
(const MetadataNode &m)¶
-
void
toJSON
(const MetadataNode &m, std::ostream &o)¶
-
std::ostream *
createFile
(const std::string &path, bool asBinary)¶ Create a file (may be on a supported remote filesystem).
- Return
Pointer to the created stream, or NULL.
- Parameters
path
: Path to file to create.asBinary
: Whether the file should be written in binary mode.
-
bool
isRemote
(const std::string &path)¶ Open a file (potentially on a remote filesystem).
- Return
Pointer to stream opened for input.
- Parameters
path
: Path (potentially remote) of file to open.asBinary
: Whether the file should be opened binary.
-
std::string
fetchRemote
(const std::string &path)¶
-
std::istream *
openFile
(const std::string &path, bool asBinary)¶
-
void
closeFile
(std::ostream *out)¶ Close an output stream.
- Parameters
out
: Stream to close.
-
void
closeFile
(std::istream *in)¶ Close an input stream.
- Parameters
out
: Stream to close.
-
bool
fileExists
(const std::string &path)¶ Check to see if a file exists.
- Return
Whether the file exists or not.
- Parameters
path
: Path to file.
-
double
computeHausdorff
(PointViewPtr srcView, PointViewPtr candView)¶
-
std::string
dllDir
()¶
-
void
printError
(const std::string &s)¶
-
MetadataNode
toMetadata
(const BOX2D &bounds)¶
-
MetadataNode
toMetadata
(const BOX3D &bounds)¶
-
int
openProgress
(const std::string &filename)¶
-
void
closeProgress
(int fd)¶
-
void
writeProgress
(int fd, const std::string &type, const std::string &text)¶
-
std::vector< std::string > PDAL_DLL maybeGlob (const std::string &path)
-
template<>
StatusWithReasonfromString
(const std::string &s, Eigen::MatrixXd &matrix)¶
-
template<>
StatusWithReasonfromString
(const std::string &s, SrsBounds &srsBounds)¶
-
template<typename
CONTAINER
, typenameVALUE
>
boolcontains
(const CONTAINER &cont, const VALUE &val)¶ Determine if a container contains a value.
- Return
true
if the value is in the container,false
otherwise.- Parameters
cont
: Container.val
: Value.
-
template<typename
KEY
, typenameVALUE
>
boolcontains
(const std::map<KEY, VALUE> &c, const KEY &v)¶ Determine if a map contains a key.
- Return
true
if the value is in the container,false
otherwise.- Parameters
c
: Map.v
: Key value.
-
template<typename
CONTAINER
, typenameVALUE
>
voidremove
(CONTAINER &cont, const VALUE &val)¶ Remove all instances of a value from a container.
- Parameters
cont
: Container.v
: Value to remove.
-
template<typename
CONTAINER
, typenamePREDICATE
>
voidremove_if
(CONTAINER &cont, PREDICATE p)¶ Remove all instances matching a unary predicate from a container.
- Parameters
cont
: Container.p
: Predicate indicating whether a value should be removed.
-
PDAL_DLL std::vector< std::string > backtrace ()
Generate a backtrace as a list of strings.
- Return
List of functions at the point of the call.
-
BacktraceEntries
backtraceImpl
()¶
-
template<class T> PDAL_DLL const T & clamp (const T &t, const T &minimum, const T &maximum)
Clamp value to given bounds.
Clamps the input value t to bounds specified by min and max. Used to ensure that row and column indices remain within valid bounds.
- Return
the value to clamped to the given bounds.
- Parameters
t
: the input value.min
: the lower bound.max
: the upper bound.
-
PDAL_DLL void random_seed (unsigned int seed)
Set a seed for random number generation.
- Parameters
seed
: Seed value.
-
PDAL_DLL double random (double minimum, double maximum)
Generate a random value in the range [minimum, maximum].
- Parameters
minimum
: Lower value of range for random number generation.maximum
: Upper value of range for random number generation.
-
PDAL_DLL bool compare_approx (double v1, double v2, double tolerance)
Determine if two values are within a particular range of each other.
- Parameters
v1
: First value to compare.v2
: Second value to compare.tolerance
: Maximum difference between v1 and v2
-
double
sround
(double r)¶ Round double value to nearest integral value.
- Return
Rounded value
- Parameters
r
: Value to round
-
std::string
tolower
(const std::string &s)¶ Convert a string to lowercase.
- Return
Converted string.
-
std::string
toupper
(const std::string &s)¶ Convert a string to uppercase.
- Return
Converted string.
-
bool
iequals
(const std::string &s, const std::string &s2)¶ Compare strings in a case-insensitive manner.
- Return
Whether the strings are equal.
- Parameters
s
: First string to compare.s2
: Second string to compare.
-
bool
startsWith
(const std::string &s, const std::string &prefix)¶ Determine if a string starts with a particular prefix.
- Return
Whether the string begins with the prefix.
- Parameters
s
: String to check for prefix.prefix
: Prefix to search for.
-
bool
endsWith
(const std::string &s, const std::string &postfix)¶ Determine if a string ends with a particular postfix.
- Return
Whether the string ends with the postfix.
- Parameters
s
: String to check for postfix.postfix
: Postfix to search for.
-
int
cksum
(char *buf, size_t size)¶ Generate a checksum that is the integer sum of the values of the bytes in a buffer.
- Return
Generated checksum.
- Parameters
buf
: Pointer to buffer.size
: Size of buffer.
-
PDAL_DLL int getenv (std::string const &name, std::string &val)
Fetch the value of an environment variable.
- Return
0 on success, -1 on failure
- Parameters
name
: Name of environment variable.name
: Value of the environment variable if it exists, empty otherwise.
-
PDAL_DLL int setenv (const std::string &env, const std::string &val)
Set the value of an environment variable.
- Return
0 on success, -1 on failure
- Parameters
env
: Name of environment variable.val
: Value of environment variable.
-
PDAL_DLL int unsetenv (const std::string &env)
Clear the value of an environment variable.
- Return
0 on success, -1 on failure
- Parameters
env
: Name of the environment variable to clear.
-
PDAL_DLL void eatwhitespace (std::istream &s)
Skip stream input until a non-space character is found.
- Parameters
s
: Stream to process.
-
PDAL_DLL void trimLeading (std::string &s)
Remove whitespace from the beginning of a string.
- Parameters
s
: String to be trimmed.
-
PDAL_DLL void trimTrailing (std::string &s)
Remove whitespace from the end of a string.
- Parameters
s
: String to be trimmed.
-
void
trim
(std::string &s)¶ Remove whitespace from the beginning and end of a string.
- Parameters
s
: String to be trimmed.
-
PDAL_DLL bool eatcharacter (std::istream &s, char x)
If specified character is at the current stream position, advance the stream position by 1.
- Return
true
if the character is at the current stream position,false
otherwise.- Parameters
s
: Stream to insect.x
: Character to check for.
-
PDAL_DLL std::string base64_encode (const unsigned char *buf, size_t size)
Convert a buffer to a string using base64 encoding.
- Return
Encoded buffer.
- Parameters
buf
: Pointer to buffer to encode.size
: Size of buffer.
-
std::string
base64_encode
(std::vector<uint8_t> const &bytes)¶ Convert a buffer to a string using base64 encoding.
- Return
Encoded buffer.
- Parameters
bytes
: Pointer to buffer to encode.
-
PDAL_DLL std::vector< uint8_t > base64_decode (std::string const &input)
Decode a base64-encoded string into a buffer.
- Return
Buffer containing decoded string.
- Parameters
input
: String to decode.
-
PDAL_DLL FILE * portable_popen (const std::string &command, const std::string &mode)
Start a process to run a command and open a pipe to which input can be written and from which output can be read.
- Return
Pointer to FILE for input/output from the subprocess.
- Parameters
command
: Command to run in subprocess. Either ‘r’, ‘w’ or ‘r+’ to specify if the pipe should be opened as read-only, write-only or read-write.
-
PDAL_DLL int portable_pclose (FILE *fp)
Close file opened with portable_popen.
- Return
0 on success, -1 on failure.
- Parameters
fp
: Pointer to file to close.
-
PDAL_DLL int run_shell_command (const std::string &cmd, std::string &output)
Create a subprocess and set the standard output of the command into the provided output string.
- Parameters
cmd
: Command to run.output
: String to which output from the command should be written,
-
PDAL_DLL std::string replaceAll (std::string input, const std::string &replaceWhat, const std::string &replaceWithWhat)
Replace all instances of one string found in the input with another value.
- Return
Modified version of input string.
- Parameters
input
: Input string to modify.replaceWhat
: Token to locate in input string.replaceWithWhat
: Replacement for found tokens.
-
PDAL_DLL std::vector< std::string > wordWrap (std::string const &inputString, size_t lineLength, size_t firstLength=0)
Break a string into a list of strings to not exceed a specified length.
Whitespace is condensed to a single space and each string is free of whitespace at the beginning and end when possible. Optionally, a line length for the first line can be different from subsequent lines.
- Return
List of substrings generated from the input string.
- Parameters
inputString
: String to split into substrings.lineLength
: Maximum length of substrings.firstLength
: When non-zero, the maximum length of the first substring. When zero, the first firstLength is assigned the value provided in lineLength.
-
PDAL_DLL std::vector< std::string > wordWrap2 (std::string const &inputString, size_t lineLength, size_t firstLength=0)
Break a string into a list of strings to not exceed a specified length.
The concatanation of the returned substrings will yield the original string. The algorithm attempts to break the original string such that each substring begins with a word.
- Return
List of substrings generated from the input string.
- Parameters
inputString
: String to split into substrings.lineLength
: Maximum length of substrings.firstLength
: When non-zero, the maximum length of the first substring. When zero, the first firstLength is assigned the value provided in lineLength.
-
PDAL_DLL std::string escapeJSON (const std::string &s)
Add escape characters or otherwise transform an input string so as to be a valid JSON string.
- Return
Valid JSON version of input string.
- Parameters
s
: Input string.
-
PDAL_DLL std::string demangle (const std::string &s)
Demangle a C++ symbol into readable form.
Demangle strings using the compiler-provided demangle function.
- Return
Demangled symbol.
- Return
Demangled string
- Parameters
s
: String to demangle.
- Parameters
[in] s
: String to be demangled.
-
PDAL_DLL int screenWidth ()
Return the screen width of an associated tty.
- Return
The tty screen width or 80 if on Windows or it can’t be determined.
-
PDAL_DLL std::string escapeNonprinting (const std::string &s)
Escape non-printing characters by using standard notation (i.e.
) or hex notation () as as necessary.
- Return
Copy of input string with non-printing characters converted to printable notation.
- Parameters
s
: String to modify.
-
PDAL_DLL double normalizeLongitude (double longitude)
Normalize longitude so that it’s between (-180, 180].
- Return
Normalized longitude.
- Parameters
longitude
: Longitude to normalize.
-
PDAL_DLL std::string hexDump (const char *buf, size_t count)
Convert an input buffer to a hexadecimal string representation similar to the output of the UNIX command ‘od’.
This is mostly used as an occasional debugging aid.
- Return
Buffer converted to hex string.
- Parameters
buf
: Point to buffer to dump.count
: Size of buffer.
-
template<typename PREDICATE> PDAL_DLL std::string::size_type extract (const std::string &s, std::string::size_type p, PREDICATE pred)
Count the number of characters in a string that meet a predicate.
- Return
Then number of characters matching the predicate.
- Parameters
s
: String in which to start counting characters.p
: Position in input string at which to start counting.pred
: Unary predicate that tests a character.
-
PDAL_DLL std::string::size_type extractSpaces (const std::string &s, std::string::size_type p)
Count the number of characters spaces in a string at a position.
- Return
Then number of space-y characters matching the predicate.
- Parameters
s
: String in which to start counting characters.p
: Position in input string at which to start counting.
-
template<typename PREDICATE> PDAL_DLL std::vector< std::string > split (const std::string &s, PREDICATE p)
Split a string into substrings based on a predicate.
Characters matching the predicate are discarded.
- Return
Substrings.
- Parameters
s
: String to split.p
: Unary predicate that returns true to indicate that a character is a split location.
-
template<typename PREDICATE> PDAL_DLL std::vector< std::string > split2 (const std::string &s, PREDICATE p)
Split a string into substrings.
Characters matching the predicate are discarded, as are empty strings otherwise produced by split().
- Return
Vector of substrings.
- Parameters
s
: String to split.p
: Predicate returns true if a char in a string is a split location.
-
PDAL_DLL std::vector< std::string > split (const std::string &s, char tChar)
Split a string into substrings based a splitting character.
The splitting characters are discarded.
- Return
Substrings.
- Parameters
s
: String to split.p
: Character indicating split positions.
-
PDAL_DLL std::vector< std::string > split2 (const std::string &s, char tChar)
Split a string into substrings based a splitting character.
The splitting characters are discarded as are empty strings otherwise produced by split().
- Return
Substrings.
- Parameters
s
: String to split.p
: Character indicating split positions.
-
PDAL_DLL std::vector< std::string > simpleWordexp (const std::string &s)
Perform shell-style word expansion (break a string into arguments).
This only does simple handling of quoted values and backslashes and doesn’t support fancier shell behavior. Use the real wordexp() if you need all that. The behavior of escaped values in a string was surprising to me, so try the shell first if you think you’ve found a problem.
- Return
List of arguments.
- Parameters
s
: Input string to parse.
-
template<typename
T
>
std::stringtypeidName
()¶ Return a string representation of a type specified by the template argument.
- Return
String representation of the type.
-
RedirectStream
redirect
(std::ostream &out, std::ostream &dst)¶ Redirect a stream to some other stream, by default a null stream.
- Return
Context for stream restoration (see restore()).
- Parameters
out
: Stream to redirect.dst
: Destination stream.
-
RedirectStream
redirect
(std::ostream &out)¶ Redirect a stream to a null stream.
- Return
Context for stream restoration (see restore()).
- Parameters
out
: Stream to redirect.
-
RedirectStream
redirect
(std::ostream &out, const std::string &file)¶ Redirect a stream to some file.
- Return
Context for stream restoration (see restore()).
- Parameters
out
: Stream to redirect.file
: Name of file where stream should be redirected.
-
void
restore
(std::ostream &out, RedirectStream &redir)¶ Restore a stream redirected with redirect().
- Parameters
out
: Stream to be restored.redir
: RedirectStream returned from corresponding redirect() call.
-
template<typename
T_OUT
>
boolinRange
(double in)¶ Determine whether a double value may be safely converted to the given output type without over/underflow.
If the output type is integral the input will be rounded before being tested.
- Return
Whether value can be safely converted to template type.
- Parameters
in
: Value to range test.
-
template<typename
T_IN
, typenameT_OUT
>
boolinRange
(T_IN in)¶ Determine whether a value may be safely converted to the given output type without over/underflow.
If the output type is integral and different from the input time, the value will be rounded before being tested.
- Return
Whether value can be safely converted to template type.
- Parameters
in
: Value to range test.
-
template<typename
T_IN
, typenameT_OUT
>
boolnumericCast
(T_IN in, T_OUT &out)¶ Convert a numeric value from one type to another.
Floating point values are rounded to the nearest integer before a conversion is attempted.
- Return
true
if the conversion was successful,false
if the datatypes/input value don’t allow conversion.- Parameters
in
: Value to convert.out
: Converted value.
-
template<>
boolnumericCast
(double in, float &out)¶ Convert a numeric value from double to float.
Specialization to handle NaN.
- Return
true
if the conversion was successful,false
if the datatypes/input value don’t allow conversion.- Parameters
in
: Value to convert.out
: Converted value.
-
template<typename
T
>
std::stringtoString
(const T &from)¶ Convert a value to its string representation by writing to a stringstream.
- Return
String representation.
- Parameters
from
: Value to convert.
-
std::string
toString
(bool from)¶ Convert a bool to a string.
-
std::string
toString
(double from, size_t precision = 10)¶ Convert a double to string with a precision of 10 decimal places.
- Return
String representation of numeric value.
- Parameters
from
: Value to convert.
-
std::string
toString
(float from)¶ Convert a float to string with a precision of 10 decimal places.
- Return
String representation of numeric value.
- Parameters
from
: Value to convert.
-
std::string
toString
(long long from)¶ Convert a long long int to string.
- Return
String representation of numeric value.
- Parameters
from
: Value to convert.
-
std::string
toString
(unsigned long from)¶ Convert an unsigned long long int to string.
- Return
String representation of numeric value.
- Parameters
from
: Value to convert.
-
std::string
toString
(long from)¶ Convert a long int to string.
- Return
String representation of numeric value.
- Parameters
from
: Value to convert.
-
std::string
toString
(unsigned int from)¶ Convert an unsigned int to string.
- Return
String representation of numeric value.
- Parameters
from
: Value to convert.
-
std::string
toString
(int from)¶ Convert an int to string.
- Return
String representation of numeric value.
- Parameters
from
: Value to convert.
-
std::string
toString
(unsigned short from)¶ Convert an unsigned short to string.
- Return
String representation of numeric value.
- Parameters
from
: Value to convert.
-
std::string
toString
(short from)¶ Convert a short int to string.
- Return
String representation of numeric value.
- Parameters
from
: Value to convert.
-
std::string
toString
(char from)¶ Convert a char (treated as numeric) to string.
- Return
String representation of numeric value.
- Parameters
from
: Value to convert.
-
std::string
toString
(unsigned char from)¶ Convert an unsigned char (treated as numeric) to string.
- Return
String representation of numeric value.
- Parameters
from
: Value to convert.
-
std::string
toString
(signed char from)¶ Convert a signed char (treated as numeric) to string.
- Return
String representation of numeric value.
- Parameters
from
: Value to convert.
-
template<typename
T
>
StatusWithReasonfromString
(const std::string &from, T *&to)¶
-
template<typename
T
>
StatusWithReasonfromString
(const std::string &from, T &to)¶ Convert a string to a value by reading from a string stream.
- Return
true
if the conversion was successful,false
otherwise.- Parameters
from
: String to convert.to
: Converted value.
-
template<>
StatusWithReasonfromString
(const std::string &from, std::string &to)¶
-
template<>
StatusWithReasonfromString
(const std::string &s, char &to)¶ Convert a numeric string to a char numeric value.
s String to convert.
- Return
true
if the conversion was successful,false
otherwise.- Parameters
to
: Converted numeric value.
-
template<>
StatusWithReasonfromString
(const std::string &s, unsigned char &to)¶ Convert a numeric string to an unsigned char numeric value.
s String to convert.
- Return
true
if the conversion was successful,false
otherwise.- Parameters
to
: Converted numeric value.
-
template<>
StatusWithReasonfromString
(const std::string &s, signed char &to)¶ Convert a numeric string to a signed char numeric value.
s String to convert.
- Return
true
if the conversion was successful,false
otherwise.- Parameters
to
: Converted numeric value.
-
template<>
StatusWithReasonfromString
(const std::string &s, double &d)¶ Specialization conversion from string to double to handle Nan.
- Return
true
if the conversion was successful,false
otherwise.- Parameters
s
: String to be converted.d
: Converted value.
-
template<typename
E
>
std::underlying_type<E>::typetoNative
(E e)¶ Return the argument cast to its underlying type.
Typically used on an enum.
- Return
Converted variable.
- Parameters
e
: Variable for which to find the underlying type.
-
template<>
StatusWithReasonfromString
(const std::string &from, pdal::i3s::Obb &obb)¶
-
template<>
StatusWithReasonfromString
(const std::string &from, pdal::expr::AssignStatement &stmt)¶
-
template<>
StatusWithReasonfromString
(const std::string &from, pdal::expr::ConditionalExpression &expr)¶
-
template<>
StatusWithReasonfromString
(const std::string &s, EptBounds &bounds)¶
Variables
-
const char
dynamicLibExtension
[] = ".so"¶
-
const char
dirSeparator
= '/'¶
-
const char
pathListSeparator
= ':'¶
-
class
StatusWithReason
¶ - #include <Utils.hpp>
-
using