diff options
author | Robin Burchell w00t@inspircd.org <Robin Burchell w00t@inspircd.org@5417fbe8-f217-4b02-8779-1006273d7864> | 2008-10-13 12:32:37 +0000 |
---|---|---|
committer | Robin Burchell w00t@inspircd.org <Robin Burchell w00t@inspircd.org@5417fbe8-f217-4b02-8779-1006273d7864> | 2008-10-13 12:32:37 +0000 |
commit | 2b0e9c3f5f0eb631619bc111764146553bcdf303 (patch) | |
tree | dc85f649a57bf72fc300808b36bee606daff9688 /include/hashcomp.h | |
parent | 3324e62bae6f04e4f16f113b2e3352fae242f405 (diff) |
Merge commit 'cbx/anopeng-config' into anopeng-config
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1429 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'include/hashcomp.h')
-rw-r--r-- | include/hashcomp.h | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/include/hashcomp.h b/include/hashcomp.h new file mode 100644 index 000000000..8d0b09ec2 --- /dev/null +++ b/include/hashcomp.h @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2002-2008 InspIRCd Development Team + * Copyright (C) 2008 Anope Team <info@anope.org> + * + * Please read COPYING and README for further details. + * + * These classes have been copied from InspIRCd and modified + * for use in Anope. + * + * $Id$ + * + */ + +#ifndef _HASHCOMP_H_ +#define _HASHCOMP_H_ + +#include <string> + +/** sepstream allows for splitting token seperated lists. + * Each successive call to sepstream::GetToken() returns + * the next token, until none remain, at which point the method returns + * an empty string. + */ +class sepstream +{ + private: + /** Original string. + */ + std::string tokens; + /** Last position of a seperator token + */ + std::string::iterator last_starting_position; + /** Current string position + */ + std::string::iterator n; + /** Seperator value + */ + char sep; + public: + /** Create a sepstream and fill it with the provided data + */ + sepstream(const std::string &source, char seperator); + virtual ~sepstream() { } + + /** Fetch the next token from the stream + * @param token The next token from the stream is placed here + * @return True if tokens still remain, false if there are none left + */ + virtual bool GetToken(std::string &token); + + /** Fetch the entire remaining stream, without tokenizing + * @return The remaining part of the stream + */ + virtual const std::string GetRemaining(); + + /** Returns true if the end of the stream has been reached + * @return True if the end of the stream has been reached, otherwise false + */ + virtual bool StreamEnd(); +}; + +/** A derived form of sepstream, which seperates on commas + */ +class commasepstream : public sepstream +{ + public: + /** Initialize with comma seperator + */ + commasepstream(const std::string &source) : sepstream(source, ',') { } +}; + +/** A derived form of sepstream, which seperates on spaces + */ +class spacesepstream : public sepstream +{ + public: + /** Initialize with space seperator + */ + spacesepstream(const std::string &source) : sepstream(source, ' ') { } +}; + +#endif |