summaryrefslogtreecommitdiff
path: root/include/anope.h
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2013-01-21 22:31:16 -0500
committerAdam <Adam@anope.org>2013-01-21 22:31:16 -0500
commitddaa001dafb5122e6e363e4acbbe6ce045b7b104 (patch)
tree0364a76606ac6e2881ebd663601ce260f7c1101e /include/anope.h
parent51c049e1a738e9124bab3961f35b830906517421 (diff)
Merge usefulness of Flags and Extensible classes into Extensible, made most flags we have juse strings instead of defines/enums
Diffstat (limited to 'include/anope.h')
-rw-r--r--include/anope.h110
1 files changed, 0 insertions, 110 deletions
diff --git a/include/anope.h b/include/anope.h
index 74f410e5d..1b978a8ba 100644
--- a/include/anope.h
+++ b/include/anope.h
@@ -762,114 +762,4 @@ template<typename T, typename O> inline T anope_dynamic_static_cast(O ptr)
#endif
}
-/*************************************************************************/
-
-/** Class with the ability to keep flags on items, they should extend from this
- * where T is an enum.
- */
-template<typename T> class Flags
-{
- std::vector<bool> flags_values;
- static const Anope::string *flags_strings;
-
- public:
- /** Add a flag to this item
- * @param value The flag
- */
- void SetFlag(T value)
- {
- if (value < 0)
- return;
-
- if (static_cast<unsigned>(value) >= flags_values.size())
- flags_values.resize(value + 1);
- flags_values[value] = true;
- }
-
- /** Remove a flag from this item
- * @param value The flag
- */
- void UnsetFlag(T value)
- {
- if (value >= 0 && static_cast<unsigned>(value) < flags_values.size())
- flags_values[value] = false;
- }
-
- /** Check if this item has a flag
- * @param value The flag
- * @return true or false
- */
- bool HasFlag(T value) const
- {
- if (value >= 0 && static_cast<unsigned>(value) < flags_values.size())
- return flags_values[value];
- return false;
- }
-
- /** Check how many flags are set
- * @return The number of flags set
- */
- size_t FlagCount() const
- {
- size_t c = 0;
- for (unsigned i = 0; i < flags_values.size(); ++i)
- if (flags_values[i])
- ++c;
- return c;
- }
-
- /** Unset all of the flags
- */
- void ClearFlags()
- {
- flags_values.clear();
- }
-
- static const Anope::string* GetFlagStrings()
- {
- return flags_strings;
- }
-
- Anope::string ToString() const
- {
- std::vector<Anope::string> v = ToVector();
- Anope::string flag_buf;
- for (unsigned i = 0; i < v.size(); ++i)
- flag_buf += v[i] + " ";
- flag_buf.trim();
- return flag_buf;
- }
-
- void FromString(const Anope::string &str)
- {
- spacesepstream sep(str);
- Anope::string buf;
- std::vector<Anope::string> v;
-
- while (sep.GetToken(buf))
- v.push_back(buf);
-
- FromVector(v);
- }
-
- std::vector<Anope::string> ToVector() const
- {
- std::vector<Anope::string> ret;
- for (unsigned i = 0; this->flags_strings && !this->flags_strings[i].empty(); ++i)
- if (this->HasFlag(static_cast<T>(i)))
- ret.push_back(this->flags_strings[i]);
- return ret;
- }
-
- void FromVector(const std::vector<Anope::string> &strings)
- {
- this->ClearFlags();
-
- for (unsigned i = 0; this->flags_strings && !this->flags_strings[i].empty(); ++i)
- for (unsigned j = 0; j < strings.size(); ++j)
- if (this->flags_strings[i] == strings[j])
- this->SetFlag(static_cast<T>(i));
- }
-};
-
#endif // ANOPE_H