se2ez
se2ez::io Namespace Reference

Functions

const std::string resolvePath (const std::string &path)
 Resolves file paths to their canonical form. More...
 
const std::string loadFileToString (const std::string &path)
 Loads a file to a string. More...
 
const std::string runCommand (const std::string &cmd)
 Runs a command cmd and returns stdout as a string. More...
 
const std::pair< bool, YAML::Node > loadFileToYAML (const std::string &path)
 Loads a file to a YAML node. More...
 
void createDirectory (const std::string &dir)
 Creates a directory. More...
 
void createFile (std::ofstream &out, const std::string &file)
 Creates a file and opens an output stream. Creates directories if they do not exist. More...
 
const std::pair< bool, std::vector< std::string > > listDirectory (const std::string &directory)
 Lists of the contents of a directory. More...
 
boost::posix_time::ptime getDate ()
 Get the current time (up to milliseconds) More...
 
std::vector< std::stringtokenize (const std::string &string, const std::string &separators)
 Separates a string into tokens, based upon separators. More...
 
bool YAMLToFile (const YAML::Node &node, const std::string &file)
 Write the contents of a YAML node out to a potentially new file. More...
 
void sleep (double seconds)
 Have this thread sleep for some number of seconds. More...
 
bool isNode (const YAML::Node &node)
 Returns true if node is a valid YAML node. More...
 
Eigen::VectorXd toVector (const YAML::Node &node)
 Convert a sequence of doubles in YAML to an Eigen vector. More...
 
YAML::Node toVector (const Eigen::Ref< const Eigen::VectorXd > &vec)
 Convert a sequence of doubles in an Eigen vector to YAML. More...
 
template<typename... Args>
void throwParsingError (const YAML::Node &node, const std::string &fmt, Args &&... args)
 Convenience function to print out a YAML error message with line and column information. More...
 
RobotPtr loadRobot (const std::string &filename)
 Loads a robot from a YAML file. More...
 
bool loadStates (RobotPtr robot, const std::string &filename)
 Loads named robot states from a YAML file. More...
 

Function Documentation

◆ createDirectory()

void se2ez::io::createDirectory ( const std::string dir)

Creates a directory.

Parameters
[in]dirDirectory to create.

Definition at line 157 of file io.cpp.

◆ createFile()

void se2ez::io::createFile ( std::ofstream out,
const std::string file 
)

Creates a file and opens an output stream. Creates directories if they do not exist.

Parameters
[out]outOutput stream to initialize.
[in]fileFile to create and open.

Definition at line 162 of file io.cpp.

◆ getDate()

boost::posix_time::ptime se2ez::io::getDate ( )

Get the current time (up to milliseconds)

Returns
The time.

Definition at line 195 of file io.cpp.

◆ isNode()

bool se2ez::io::isNode ( const YAML::Node &  node)

Returns true if node is a valid YAML node.

Parameters
[in]nodeNode to check.
Returns
True if node is a YAML node.

Definition at line 258 of file yaml.cpp.

◆ listDirectory()

const std::pair< bool, std::vector< std::string > > se2ez::io::listDirectory ( const std::string directory)

Lists of the contents of a directory.

Parameters
[in]directoryDirectory to list.
Returns
A pair of a bool and a vector of strings of filenames of the directories contents. The first element will be true on success, false on failure. These filenames are absolute paths.

Definition at line 176 of file io.cpp.

◆ loadFileToString()

const std::string se2ez::io::loadFileToString ( const std::string path)

Loads a file to a string.

Parameters
[in]pathFile to load.
Returns
The loaded file, or "" on failure (file does not exist).

Definition at line 89 of file io.cpp.

◆ loadFileToYAML()

const std::pair< bool, YAML::Node > se2ez::io::loadFileToYAML ( const std::string path)

Loads a file to a YAML node.

Parameters
[in]pathFile to load.
Returns
A pair, where the first is true on success false on failure, and second is the YAML node.

Definition at line 123 of file io.cpp.

◆ loadRobot()

RobotPtr se2ez::io::loadRobot ( const std::string filename)

Loads a robot from a YAML file.

Parameters
[in]filenameThe filename to load.
Returns
A robot compiled from filename, and a nullptr on failure.

Definition at line 303 of file yaml.cpp.

◆ loadStates()

bool se2ez::io::loadStates ( RobotPtr  robot,
const std::string filename 
)

Loads named robot states from a YAML file.

Parameters
[in,out]robotRobot to load named states into.
[in]filenameThe filename to load.
Returns
True on success, false on failure.

Definition at line 326 of file yaml.cpp.

◆ resolvePath()

const std::string se2ez::io::resolvePath ( const std::string path)

Resolves file paths to their canonical form.

Parameters
[in]pathPath to resolve.
Returns
The canonical path, or "" on failure.

Definition at line 79 of file io.cpp.

◆ runCommand()

const std::string se2ez::io::runCommand ( const std::string cmd)

Runs a command cmd and returns stdout as a string.

Parameters
[in]cmdCommand to run.
Returns
Contents of stdout from cmd, or "" on failure.

Definition at line 106 of file io.cpp.

◆ sleep()

void se2ez::io::sleep ( double  seconds)

Have this thread sleep for some number of seconds.

Parameters
[in]secondsSeconds to sleep for.

Definition at line 207 of file io.cpp.

◆ throwParsingError()

template<typename... Args>
void se2ez::io::throwParsingError ( const YAML::Node &  node,
const std::string fmt,
Args &&...  args 
)

Convenience function to print out a YAML error message with line and column information.

Parameters
[in]nodeNode that was culprit.
[in]fmtFormat string for error message.
[in]argsArguments to format string.
Template Parameters
ArgsVariadic arguments for format string.
Exceptions
std::runtime_erroralways.

Definition at line 42 of file utility.h.

◆ tokenize()

std::vector< std::string > se2ez::io::tokenize ( const std::string string,
const std::string separators 
)

Separates a string into tokens, based upon separators.

Parameters
[in]stringString to tokenize.
[in]separatorsSeparators to split string on.
Returns
The tokenized string.

Definition at line 200 of file io.cpp.

◆ toVector() [1/2]

Eigen::VectorXd se2ez::io::toVector ( const YAML::Node &  node)

Convert a sequence of doubles in YAML to an Eigen vector.

Parameters
[in]nodeNode to parse.
Returns
The contents of the node as an Eigen vector.

Definition at line 282 of file yaml.cpp.

◆ toVector() [2/2]

YAML::Node se2ez::io::toVector ( const Eigen::Ref< const Eigen::VectorXd > &  vec)

Convert a sequence of doubles in an Eigen vector to YAML.

Parameters
[in]vecVector to convert
Returns
The contents of the node as a YAML node.

Definition at line 294 of file yaml.cpp.

◆ YAMLToFile()

bool se2ez::io::YAMLToFile ( const YAML::Node &  node,
const std::string file 
)

Write the contents of a YAML node out to a potentially new file.

Parameters
[in]nodeNode to write.
[in]fileFilename to open.
Returns
True on success, false otherwise.

Definition at line 143 of file io.cpp.