Implementations of different problems
This commit is contained in:
@@ -40,7 +40,31 @@
|
||||
/** @def __METHOD_NAME__
|
||||
* @brief Get the name of the current method/function without the return type.
|
||||
* */
|
||||
#define __METHOD_NAME__ methodName(__PRETTY_FUNCTION__)
|
||||
#define __METHOD_NAME__ details::methodName(__PRETTY_FUNCTION__)
|
||||
|
||||
namespace details {
|
||||
/** @brief Takes in the __PRETTY_FUNCTION__ string and removes the return type.
|
||||
*
|
||||
* @details This function should only be used for the __METHOD_NAME__ macro,
|
||||
* since it takes the output from __PRETTY_FUNCTION__ and strips the return
|
||||
* type.
|
||||
*
|
||||
* @param pretty_function The string from __PRETTY_FUNCTION__
|
||||
*
|
||||
* @return std::string
|
||||
* */
|
||||
inline std::string methodName(const std::string &pretty_function)
|
||||
{
|
||||
size_t colons = pretty_function.find("::");
|
||||
size_t begin = pretty_function.substr(0, colons).rfind(" ") + 1;
|
||||
size_t end = pretty_function.rfind("(") - begin;
|
||||
|
||||
return pretty_function.substr(begin, end) + "()";
|
||||
}
|
||||
|
||||
} // namespace details
|
||||
|
||||
namespace utils {
|
||||
|
||||
/** @brief Turns a double into a string written in scientific format.
|
||||
*
|
||||
@@ -68,26 +92,6 @@ std::string scientific_format(double d, int width = 20, int prec = 10);
|
||||
std::string scientific_format(const std::vector<double> &v, int width = 20,
|
||||
int prec = 10);
|
||||
|
||||
|
||||
/** @brief Takes in the __PRETTY_FUNCTION__ string and removes the return type.
|
||||
*
|
||||
* @details This function should only be used for the __METHOD_NAME__ macro,
|
||||
* since it takes the output from __PRETTY_FUNCTION__ and strips the return
|
||||
* type.
|
||||
*
|
||||
* @param pretty_function The string from __PRETTY_FUNCTION__
|
||||
*
|
||||
* @return std::string
|
||||
* */
|
||||
static inline std::string methodName(const std::string &pretty_function)
|
||||
{
|
||||
size_t colons = pretty_function.find("::");
|
||||
size_t begin = pretty_function.substr(0, colons).rfind(" ") + 1;
|
||||
size_t end = pretty_function.rfind("(") - begin;
|
||||
|
||||
return pretty_function.substr(begin, end) + "()";
|
||||
}
|
||||
|
||||
/** @brief Make path given.
|
||||
*
|
||||
* @details This tries to be the equivalent to "mkdir -p" and creates a new
|
||||
@@ -100,4 +104,14 @@ static inline std::string methodName(const std::string &pretty_function)
|
||||
* */
|
||||
bool mkpath(std::string path, int mode = 0777);
|
||||
|
||||
/** @brief Get the directory name of the path
|
||||
*
|
||||
* @param path The path to use.
|
||||
*
|
||||
* @return string
|
||||
* */
|
||||
std::string dirname(const std::string &path);
|
||||
|
||||
} // namespace utils
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user