From a621e6b86adfe8278d2e9c110eb8ef54e58c6abe Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Tue, 8 Oct 2019 22:07:48 -0500 Subject: hscript: Add StringKey helper class --- hscript/key.cc | 5 +++++ hscript/key.hh | 19 ++++++++++++++++++- hscript/user.cc | 0 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 hscript/user.cc diff --git a/hscript/key.cc b/hscript/key.cc index b5bbe31..bc71517 100644 --- a/hscript/key.cc +++ b/hscript/key.cc @@ -36,3 +36,8 @@ bool Horizon::Keys::BooleanKey::validate() const { /* Key will fail init if it is not valid, so this is always a no-op. */ return true; } + +bool Horizon::Keys::StringKey::validate() const { + /* Key will fail init if it is not valid, so this is always a no-op. */ + return true; +} diff --git a/hscript/key.hh b/hscript/key.hh index 1045592..44cbdf2 100644 --- a/hscript/key.hh +++ b/hscript/key.hh @@ -64,8 +64,8 @@ public: */ class BooleanKey : public Key { protected: - BooleanKey(int _line, bool my_value) : Key(_line), value(my_value) {} bool value; + BooleanKey(int _line, bool my_value) : Key(_line), value(my_value) {} /*! Parse a string into a boolean. * @param what The string to attempt parsing. @@ -86,6 +86,23 @@ public: bool validate() const override; }; + +/*! Base Key class that parses and handles single string values. */ +class StringKey : public Key { +protected: + std::string _value; + StringKey(int _line, std::string my_str) : Key(_line), _value(my_str) {} + +public: + /*! Retrieve the value of this key. */ + const std::string value() const { return this->_value; } + + /*! By default, key will be considered valid since it parsed. + * This method should be overridden when further consideration is needed. + */ + bool validate() const override; +}; + } } diff --git a/hscript/user.cc b/hscript/user.cc new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3-60-g2f50