From 6746da6edd7d9d50efe374eabbb79a3cac882d81 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 16 Jan 2017 18:02:50 -0500 Subject: Started structural rewrite The new object structure was designed to build on the existing WordNet structure, while also adding in all of the data that we get from other sources. More information about this can be found on the project wiki. The generator has already been completely rewritten to generate a datafile that uses the new structure. In addition, a number of indexes are created, which does double the size of the datafile, but also allows for much faster lookups. Finally, the new generator is written modularly and is a lot more readable than the old one. The verbly interface to the new object structure has mostly been completed, but has not been tested fully. There is a completely new search API which utilizes a lot of operator overloading; documentation on how to use it should go up at some point. Token processing and verb frames are currently unimplemented. Source for these have been left in the repository for now. --- generator/field.cpp | 193 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 generator/field.cpp (limited to 'generator/field.cpp') diff --git a/generator/field.cpp b/generator/field.cpp new file mode 100644 index 0000000..84b2f91 --- /dev/null +++ b/generator/field.cpp @@ -0,0 +1,193 @@ +#include "field.h" +#include +#include + +namespace verbly { + namespace generator { + + field::field(const field& other) + { + type_ = other.type_; + name_ = other.name_; + + switch (type_) + { + case type::integer: + { + integer_ = other.integer_; + + break; + } + + case type::string: + { + new(&string_) std::string(other.string_); + + break; + } + + case type::invalid: + { + break; + } + } + } + + field::field(field&& other) : field() + { + swap(*this, other); + } + + field& field::operator=(field other) + { + swap(*this, other); + + return *this; + } + + void swap(field& first, field& second) + { + using type = field::type; + + type tempType = first.type_; + std::string tempName = std::move(first.name_); + int tempInteger; + std::string tempString; + + switch (first.type_) + { + case type::integer: + { + tempInteger = first.integer_; + + break; + } + + case type::string: + { + tempString = std::move(tempString); + + break; + } + + case type::invalid: + { + break; + } + } + + first.~field(); + + first.type_ = second.type_; + first.name_ = std::move(second.name_); + + switch (second.type_) + { + case type::integer: + { + first.integer_ = second.integer_; + + break; + } + + case type::string: + { + new(&first.string_) std::string(std::move(second.string_)); + + break; + } + + case type::invalid: + { + break; + } + } + + second.~field(); + + second.type_ = tempType; + second.name_ = std::move(tempName); + + switch (tempType) + { + case type::integer: + { + second.integer_ = tempInteger; + + break; + } + + case type::string: + { + new(&second.string_) std::string(std::move(tempString)); + + break; + } + + case type::invalid: + { + break; + } + } + } + + field::~field() + { + switch (type_) + { + case type::string: + { + using string_type = std::string; + string_.~string_type(); + + break; + } + + case type::integer: + case type::invalid: + { + break; + } + } + } + + field::field( + std::string name, + int arg) : + type_(type::integer), + name_(name), + integer_(arg) + { + } + + int field::getInteger() const + { + if (type_ != type::integer) + { + throw std::domain_error("field::getInteger called on non-integer field"); + } + + return integer_; + } + + field::field( + std::string name, + std::string arg) : + type_(type::string), + name_(name) + { + new(&string_) std::string(arg); + } + + std::string field::getString() const + { + if (type_ != type::string) + { + throw std::domain_error("field::getString called on non-string field"); + } + + return string_; + } + + }; +}; -- cgit 1.4.1