susumu.yata
null+****@clear*****
Thu Jul 17 10:36:16 JST 2014
susumu.yata 2014-07-17 10:36:16 +0900 (Thu, 17 Jul 2014) New Revision: a35408b2a8ed1dbacf4e6fe7e504ebb3c3c917b3 https://github.com/groonga/grnxx/commit/a35408b2a8ed1dbacf4e6fe7e504ebb3c3c917b3 Message: Support operation for Text. Modified files: lib/grnxx/expression.cpp Modified: lib/grnxx/expression.cpp (+50 -1) =================================================================== --- lib/grnxx/expression.cpp 2014-07-17 10:31:17 +0900 (cbf4a51) +++ lib/grnxx/expression.cpp 2014-07-17 10:36:16 +0900 (aee95ca) @@ -133,6 +133,35 @@ bool DatumNode<T>::evaluate(Error *error, const RecordSet &record_set) { } } +template <> +class DatumNode<Text> : public Node<Text> { + public: + explicit DatumNode(Text datum) + : Node<Text>(), + datum_(datum.data(), datum.size()) {} + virtual ~DatumNode() {} + + NodeType node_type() const { + return DATUM_NODE; + } + + bool evaluate(Error *error, const RecordSet &record_set); + + private: + std::string datum_; +}; + +bool DatumNode<Text>::evaluate(Error *error, const RecordSet &record_set) { + try { + this->values_.resize(record_set.size(), + Text(datum_.data(), datum_.size())); + return true; + } catch (...) { + GRNXX_ERROR_SET(error, NO_MEMORY, "Memory allocation failed"); + return false; + } +} + // -- RowIDNode -- class RowIDNode : public Node<Int> { @@ -463,6 +492,10 @@ bool ExpressionBuilder::push_datum(Error *error, const Datum &datum) { node.reset(new (nothrow) DatumNode<GeoPoint>(datum.force_geo_point())); break; } + case TEXT_DATA: { + node.reset(new (nothrow) DatumNode<Text>(datum.force_text())); + break; + } default: { // TODO: Other types are not supported yet. GRNXX_ERROR_SET(error, NOT_SUPPORTED_YET, "Not supported yet"); @@ -470,7 +503,7 @@ bool ExpressionBuilder::push_datum(Error *error, const Datum &datum) { } } if (!node) { - GRNXX_ERROR_SET(error, NO_MEMORY, "Not supported yet"); + GRNXX_ERROR_SET(error, NO_MEMORY, "Memory allocation failed"); return false; } stack_.push_back(std::move(node)); @@ -516,6 +549,10 @@ bool ExpressionBuilder::push_column(Error *error, String name) { node.reset(new (nothrow) ColumnNode<GeoPoint>(column)); break; } + case TEXT_DATA: { + node.reset(new (nothrow) ColumnNode<Text>(column)); + break; + } default: { // TODO: Not supported yet. GRNXX_ERROR_SET(error, NOT_SUPPORTED_YET, "Not supported yet"); @@ -665,6 +702,12 @@ bool ExpressionBuilder::push_equality_operator(Error *error) { functor, std::move(lhs), std::move(rhs))); break; } + case TEXT_DATA: { + typename T::template Functor<Text> functor; + node.reset(new (nothrow) BinaryNode<decltype(functor)>( + functor, std::move(lhs), std::move(rhs))); + break; + } // TODO: Support other types. default: { GRNXX_ERROR_SET(error, NOT_SUPPORTED_YET, "Not supported yet"); @@ -714,6 +757,12 @@ bool ExpressionBuilder::push_comparison_operator(Error *error) { functor, std::move(lhs), std::move(rhs))); break; } + case TEXT_DATA: { + typename T::template Functor<Text> functor; + node.reset(new (nothrow) BinaryNode<decltype(functor)>( + functor, std::move(lhs), std::move(rhs))); + break; + } // TODO: Support other comparable types. default: { GRNXX_ERROR_SET(error, NOT_SUPPORTED_YET, "Not supported yet"); -------------- next part -------------- HTML����������������������������... Download