|
[Rivet-svn] r4302 - trunk/include/Rivet/Toolsblackhole at projects.hepforge.org blackhole at projects.hepforge.orgThu May 23 11:43:58 BST 2013
Author: buckley Date: Thu May 23 11:43:58 2013 New Revision: 4302 Log: Adding Doxy comments and a couple of useful convenience functions to Utils.hh. Modified: trunk/include/Rivet/Tools/Utils.hh Modified: trunk/include/Rivet/Tools/Utils.hh ============================================================================== --- trunk/include/Rivet/Tools/Utils.hh Thu May 23 11:25:28 2013 (r4301) +++ trunk/include/Rivet/Tools/Utils.hh Thu May 23 11:43:58 2013 (r4302) @@ -3,6 +3,7 @@ #define RIVET_Utils_HH #include <Rivet/Math/Math.hh> +#include <Rivet/RivetBoost.hh> #include <cctype> #include <algorithm> #include <cerrno> @@ -11,7 +12,19 @@ namespace Rivet { - inline int nocase_cmp(const string& s1, const string& s2) { + /// @brief Convert any object to a string + /// + /// Just a convenience wrapper for the more general Boost lexical_cast + template <typename T> + inline std::string to_str(const T& x) { + return lexical_cast<string>(x); + } + + + /// Case-insensitive string comparison function + /// + /// @todo Replace with something from the Boost string library + inline int nocase_cmp(const std::string& s1, const std::string& s2) { string::const_iterator it1 = s1.begin(); string::const_iterator it2 = s2.begin(); while ( (it1 != s1.end()) && (it2 != s2.end()) ) { @@ -30,36 +43,50 @@ } - inline string toLower(const string& s) { + /// Case-insensitive string equality function + inline bool nocase_equals(const std::string& s1, const std::string& s2) { + return nocase_cmp(s1, s2) == 0; + } + + + /// Convert a string to lower-case + /// + /// @todo Replace with something from the Boost string library + inline std::string toLower(const std::string& s) { string out = s; transform(out.begin(), out.end(), out.begin(), (int(*)(int)) tolower); return out; } - inline string toUpper(const string& s) { + /// Convert a string to upper-case + /// + /// @todo Replace with something from the Boost string library + inline std::string toUpper(const std::string& s) { string out = s; std::transform(out.begin(), out.end(), out.begin(), (int(*)(int)) toupper); return out; } - inline bool startsWith(const string& s, const string& start) { + /// Check whether a string @a start is found at the start of @a s + inline bool startsWith(const std::string& s, const std::string& start) { if (s.length() < start.length()) return false; return s.substr(0, start.length()) == start; } /// Check whether a string @a end is found at the end of @a s - inline bool endsWith(const string& s, const string& end) { + inline bool endsWith(const std::string& s, const std::string& end) { if (s.length() < end.length()) return false; return s.substr(s.length() - end.length()) == end; } /// @brief Split a path string with colon delimiters. + /// /// Ignores zero-length substrings. Designed for getting elements of filesystem paths, naturally. - inline vector<string> pathsplit(const string& path) { + inline vector<std::string> pathsplit(const std::string& path) { const string delim = ":"; vector<string> dirs; string tmppath = path; @@ -76,9 +103,10 @@ /// @brief Join several filesystem paths together with a delimiter character. + /// /// Note that this does NOT join path elements together with a platform-portable /// directory delimiter, cf. the Python @c {os.path.join}! - inline string pathjoin(const vector<string>& paths) { + inline std::string pathjoin(const vector<std::string>& paths) { const string delim = ":"; string rtn; for (vector<string>::const_iterator is = paths.begin(); is != paths.end(); ++is) { @@ -93,10 +121,21 @@ #endif + #ifndef CEDARSTD #define CEDARSTD namespace std { + + /// @name Standard library enhancements + //@{ + + + /// @todo Add a "contains" function for vectors, maps and strings (returns bool rather than iterator) + + /// @todo Merge in nice ideas from mili: https://code.google.com/p/mili/ + + template <typename T> inline void operator+=(set<T>& s1, const set<T>& s2) { for (typename set<T>::const_iterator s = s2.begin(); s != s2.end(); ++s) { @@ -112,7 +151,7 @@ } template <typename T> - inline string join(const set<T>& s, const string& sep = " ") { + inline std::string join(const set<T>& s, const std::string& sep = " ") { stringstream out; bool first = false; for (typename set<T>::const_iterator it = s.begin(); it != s.end(); ++it) { @@ -142,7 +181,7 @@ } template <typename T> - inline string join(const vector<T>& v, const string& sep = " ") { + inline string join(const vector<T>& v, const std::string& sep = " ") { stringstream out; for (size_t i = 0; i < v.size(); ++i) { if (i != 0) out << sep; @@ -151,5 +190,8 @@ return out.str(); } + //@} + + } #endif
More information about the Rivet-svn mailing list |