From a74c677c09774c02d3bc347525fb071f25d25697 Mon Sep 17 00:00:00 2001 From: Michael Krelin Date: Mon, 25 Apr 2005 16:27:12 +0000 Subject: 1. bumped version to 0.0.1 2. added utility functions extracted from sitecing --- (limited to 'include') diff --git a/include/Makefile.am b/include/Makefile.am index 3e043d3..5fbf85e 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -6,6 +6,7 @@ endif nobase_include_HEADERS = \ konforka/exception.h \ + konforka/util.h \ konforka/basic_wrapper.h konforka/responsible_wrapper.h \ konforka/resource_pile.h \ konforka/pointer_map.h \ diff --git a/include/konforka/util.h b/include/konforka/util.h new file mode 100644 index 0000000..c06edd9 --- a/dev/null +++ b/include/konforka/util.h @@ -0,0 +1,103 @@ +#ifndef __KONFORKA_UTIL_H +#define __KONFORKA_UTIL_H + +#include +#include +#include + +/** + * @file + * @brief miscellaneous utility stuff. + */ + +/** + * @brief The main konforka namespace. + */ +namespace konforka { + using std::string; + + class restricted_sequence_error : public konforka::exception { + public: + restricted_sequence_error(const string& fi,const string& fu,int l,const string& w) + : konforka::exception(fi,fu,l,w) { } + }; + + /** + * 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 + }; + + /** + * Normalize pathname by stripping duplicate slashes, etc. + * @param p the pathname. + * @param o options. + * @return the normalized path. + * @see normalize_path_options + * @todo TODO: document exceptions. + */ + string normalize_path(const string& p,int o=(restrict_dotdot|strip_trailing_slash)); + + /** + * Extract the directory part of the filename. + * @param p the pathname. + * @return the directory part. + */ + string dir_name(const string& p); + + class beyond_root_error : public konforka::exception { + public: + beyond_root_error(const string& fi,const string& fu,int l,const string& w) + : konforka::exception(fi,fu,l,w) { } + }; + + /** + * 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 + }; + + /** + * Combine path with the relative path. + * @param orig the origin. + * @param rel relative path to combine with. + * @param o options. + * @return the paths combined. + * @see combine_path_options + * @todo TODO: document exceptions. + */ + string combine_path(const string& orig,const string& rel,int o=origin_is_file); + + /** + * Create directory and parent directories if needed. + * @param p the pathname. + * @param m mode value for the newly created directories. + */ + void make_path(const string& p,mode_t m); + +} + + /* vim:set ft=cpp: */ +#endif /* __KONFORKA_UTIL_H */ -- cgit v0.9.0.2