| … | … | @@ -0,0 +1,61 @@ |
| 1 | /* |
| 2 | * LiteralValueOfLink.cc |
| 3 | * |
| 4 | * Copyright (C) 2015, 2018 Linas Vepstas |
| 5 | * |
| 6 | * Author: Linas Vepstas <linasvepstas@gmail.com> January 2009 |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU Affero General Public License v3 as |
| 10 | * published by the Free Software Foundation and including the |
| 11 | * exceptions at http://opencog.org/wiki/Licenses |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Affero General Public |
| 19 | * License along with this program; if not, write to: |
| 20 | * Free Software Foundation, Inc., |
| 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 22 | */ |
| 23 | |
| 24 | #include <opencog/atomspace/AtomSpace.h> |
| 25 | #include "LiteralValueOfLink.h" |
| 26 | |
| 27 | using namespace opencog; |
| 28 | |
| 29 | LiteralValueOfLink::LiteralValueOfLink(const HandleSeq&& oset, Type t) |
| 30 | : ValueOfLink(std::move(oset), t) |
| 31 | { |
| 32 | if (not nameserver().isA(t, LITERAL_VALUE_OF_LINK)) |
| 33 | { |
| 34 | const std::string& tname = nameserver().getTypeName(t); |
| 35 | throw InvalidParamException(TRACE_INFO, |
| 36 | "Expecting an LiteralValueOfLink, got %s", tname.c_str()); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | // --------------------------------------------------------------- |
| 41 | |
| 42 | /// When executed, this will return the value at the indicated key. |
| 43 | ValuePtr LiteralValueOfLink::execute(AtomSpace* as, bool silent) |
| 44 | { |
| 45 | ValuePtr pap(get_literal(as, silent)); |
| 46 | if (pap) return pap; |
| 47 | |
| 48 | // Oh no! Nothing was found! |
| 49 | if (silent) |
| 50 | throw SilentException(); |
| 51 | |
| 52 | throw InvalidParamException(TRACE_INFO, |
| 53 | "No value at key %s on atom %s", |
| 54 | ak->to_string().c_str(), ah->to_string().c_str()); |
| 55 | |
| 56 | return createVoidValue(); |
| 57 | } |
| 58 | |
| 59 | DEFINE_LINK_FACTORY(LiteralValueOfLink, LITERAL_VALUE_OF_LINK) |
| 60 | |
| 61 | /* ===================== END OF FILE ===================== */ |