-rw-r--r-- | include/sitecing/sitecing_util.h | 87 |
1 files changed, 3 insertions, 84 deletions
diff --git a/include/sitecing/sitecing_util.h b/include/sitecing/sitecing_util.h index d1a6c4a..f642c74 100644 --- a/include/sitecing/sitecing_util.h +++ b/include/sitecing/sitecing_util.h @@ -1,14 +1,15 @@ #ifndef __SITECING_SITECING_UTIL_H #define __SITECING_SITECING_UTIL_H #include <sys/types.h> #include <string> #include <konforka/exception.h> +#include <konforka/util.h> /** * @file * @brief utility classes and functions. */ namespace sitecing { using namespace std; @@ -16,24 +17,17 @@ namespace sitecing { /** * Base class for utility exceptions. */ class utility_error : public konforka::exception { public: utility_error(const string& fi,const string& fu,int l,const string& w) : konforka::exception(fi,fu,l,w) { } }; - /** - * Restricted sequence encountered. - */ - class utility_restricted_sequence : public utility_error { - public: - utility_restricted_sequence(const string& fi,const string& fu,int l,const string& w) - : utility_error(fi,fu,l,w) { } - }; + /** * No prefix or suffix found to strip out. */ class utility_no_affix : public utility_error { public: utility_no_affix(const string& fi,const string& fu,int l,const string& w) : utility_error(fi,fu,l,w) { } }; @@ -50,26 +44,16 @@ namespace sitecing { */ class utility_no_suffix : public utility_no_affix { public: utility_no_suffix(const string& fi,const string& fu,int l,const string& w) : utility_no_affix(fi,fu,l,w) { } }; /** - * Went up beyond root. - * @todo TODO: wish I could remember the details -- document me. - */ - class utility_beyond_root : public utility_error { - public: - utility_beyond_root(const string& fi,const string& fu,int l,const string& w) - : utility_error(fi,fu,l,w) { } - }; - - /** * The file lock object. Released at the object destruction. */ class file_lock { public: /** * The file descriptor. */ int fd; @@ -210,97 +194,32 @@ namespace sitecing { void lock(); /** * Unlock it. */ void unlock(); }; /** - * normalize_path options enumeration. - * @see normalize_path() - */ - enum normalize_path_options { - /** - * Restrict the /../ sequence. - */ - restrict_dotdot = 1, - /** - * Strip out the leading slash. - */ - strip_leading_slash = 2, - /** - * Strip out the trailing slash. - */ - strip_trailing_slash = 4 - }; - /** - * combine_path options enumeration. - * @see combine_path() - */ - enum combine_path_options { - /** - * The origin is file. Otherwise it is directory. - */ - origin_is_file = 1, - /** - * Fail if we've gone up beyond root. - */ - fail_beyond_root = 2 - }; - - /** - * Normalize pathname by stripping duplicate slashes, etc. - * @param path the path name. - * @param opts options. - * @return the normalized path. - * @see normalize_path_options - * @todo TODO: document exceptions. - */ - string normalize_path(const string& path,int opts=(restrict_dotdot|strip_trailing_slash)); - /** * Strip prefix from the string. * @param str the string. * @param prefix prefix to strip. * @return the string without prefix. * @todo TODO: document exceptions. */ string strip_prefix(const string& str,const string& prefix); /** * Strip suffix from the string. * @param str the string. * @param suffix suffix to strip. * @return the string without suffix. * @todo TODO: document exceptions. */ string strip_suffix(const string& str,const string& suffix); - /** - * Get the directory part of the filename. - * @param filename the full file name. - * @return the directory part. - */ - string dir_name(const string& filename); - /** - * Combine path with the relative path. - * @param origin the origin. - * @param relative relative path to combine origin with. - * @param opts options. - * @return the pathc combined. - * @see combine_path_options - * @todo TODO: document exceptions. - */ - string combine_path(const string& origin,const string& relative,int opts=origin_is_file); - - /** - * Create directory and parent directories if needed. - * @param path the pathname. - * @param mode the mode for newly created directories. - */ - void make_path(const string& path,mode_t mode); - + /** * Change to the directory and pop back at object's destruction (e.g. when * the object goes out of scope). */ class auto_chdir { public: /** * Saved working directory. |