susumu.yata
null+****@clear*****
Thu Nov 13 14:54:23 JST 2014
susumu.yata 2014-11-13 14:54:23 +0900 (Thu, 13 Nov 2014) New Revision: 26f0f85d02367d9f6fd269926084a0fdec69b93a https://github.com/groonga/grnxx/commit/26f0f85d02367d9f6fd269926084a0fdec69b93a Message: Enable ConstantNode<Text>. (#104) Modified files: lib/grnxx/impl/expression.cpp Modified: lib/grnxx/impl/expression.cpp (+21 -33) =================================================================== --- lib/grnxx/impl/expression.cpp 2014-11-13 11:41:09 +0900 (915c53b) +++ lib/grnxx/impl/expression.cpp 2014-11-13 14:54:23 +0900 (939fe62) @@ -257,43 +257,31 @@ class ConstantNode<Float> : public TypedNode<Float> { Float value_; }; -//template <> -//class ConstantNode<Text> : public TypedNode<Text> { -// public: -// using Value = Text; - -// static unique_ptr<Node> create(Error *error, Value datum) { -// unique_ptr<ConstantNode> node(new (nothrow) ConstantNode); -// if (!node) { -// GRNXX_ERROR_SET(error, NO_MEMORY, "Memory allocation failed"); -// return nullptr; -// } -// if (!node->datum_.assign(error, datum)) { -// return nullptr; -// } -// return unique_ptr<Node>(node.release()); -// } +// TODO: Text will have ownership in future. +template <> +class ConstantNode<Text> : public TypedNode<Text> { + public: + using Value = Text; -// explicit ConstantNode() -// : TypedNode<Value>(), -// datum_() {} + explicit ConstantNode(const Value &value) + : TypedNode<Value>(), + value_() { + value_.assign(value.data(), value.size().value()); + } -// NodeType node_type() const { -// return CONSTANT_NODE; -// } + NodeType node_type() const { + return CONSTANT_NODE; + } -// bool evaluate(Error *, -// ArrayCRef<Record> records, -// ArrayRef<Value> results) { -// for (Int i = 0; i < records.size(); ++i) { -// results[i] = datum_; -// } -// return true; -// } + void evaluate(ArrayCRef<Record> records, ArrayRef<Value> results) { + for (size_t i = 0; i < records.size(); ++i) { + results[i] = Text(value_.data(), value_.size()); + } + } -// private: -// String datum_; -//}; + private: + String value_; +}; // -- RowIDNode -- -------------- next part -------------- HTML����������������������������...ダウンロード