From 38c17f093615a16a4b4ec6dc2b5d3edb5c1d3895 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 27 Sep 2018 21:40:52 -0400 Subject: More hkutil refactoring All database access goes through hatkirby::database now. verbly::token, verbly::statement::condition, and verbly::part have been converted to use mpark::variant now. verbly::binding has been deleted, and replaced with a mpark::variant typedef in statement.h. This means that the only remaining tagged union class is verbly::generator::part. refs #5 --- lib/token.h | 76 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 37 insertions(+), 39 deletions(-) (limited to 'lib/token.h') diff --git a/lib/token.h b/lib/token.h index ae7bf96..910a465 100644 --- a/lib/token.h +++ b/lib/token.h @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include "enums.h" #include "word.h" #include "part.h" @@ -22,23 +24,6 @@ namespace verbly { transform }; - // Copy & move constructors - - token(const token& other); - token(token&& other); - - // Assignment operator - - token& operator=(token other); - - // Swap - - friend void swap(token& first, token& second); - - // Destructor - - ~token(); - // Accessors type getType() const @@ -52,7 +37,8 @@ namespace verbly { bool isEmpty() const { - return ((type_ == type::utterance) && (utterance_.empty())); + return (type_ == type::utterance && + mpark::get(variant_).empty()); } // Word @@ -68,13 +54,13 @@ namespace verbly { token(std::string arg); token(const char* arg); - std::string getLiteral() const; + const std::string& getLiteral() const; // Part token(part arg); - part getPart() const; + const part& getPart() const; // Fillin @@ -128,7 +114,7 @@ namespace verbly { bool indefiniteArticle, casing capitalization) const; - enum class transform_type { + enum class transform_mode { separator, punctuation, indefinite_article, @@ -137,34 +123,46 @@ namespace verbly { }; token( - transform_type type, + transform_mode type, std::string param1, std::string param2, token inner); token( - transform_type type, + transform_mode type, casing param, token inner); - union { - struct { - word word_; - inflection category_; - } word_; - std::string literal_; - part part_; - std::set fillin_; - std::list utterance_; - struct { - transform_type type_; - std::string strParam_; - std::string strParam2_; - casing casingParam_; - std::unique_ptr inner_; - } transform_; + struct word_type { + word value; + inflection category; }; + + using literal_type = std::string; + + using fillin_type = std::set; + + using utterance_type = std::list; + + struct transform_type { + transform_mode type; + std::string strParam; + std::string strParam2; + casing casingParam; + hatkirby::recptr inner; + }; + + using variant_type = + mpark::variant< + word_type, + literal_type, + part, + fillin_type, + utterance_type, + transform_type>; + type type_; + variant_type variant_; }; std::ostream& operator<<(std::ostream& os, token::type type); -- cgit 1.4.1