ScAddr findMainIdtf(ScMemoryContext & ctx, ScAddr const & elAddr, ScAddr const langAddr) { assert(elAddr.isValid()); assert(langAddr.isValid()); ScAddr result; ScIterator5Ptr it5 = ctx.iterator5( elAddr, SC_TYPE(sc_type_arc_common | sc_type_const), SC_TYPE(sc_type_link), SC_TYPE(sc_type_arc_pos_const_perm), Keynodes::nrel_main_idtf ); while (it5->next()) { if (ctx.helperCheckArc(langAddr, it5->value(2), sc_type_arc_pos_const_perm)) { result = it5->value(2); break; } } return result; }
sc_result ScAgentAction::run(ScAddr const & listenAddr, ScAddr const & startArcAddr) { ScAddr cmdAddr = mMemoryCtx.getEdgeTarget(startArcAddr); if (cmdAddr.isValid()) { if (mMemoryCtx.helperCheckArc(mCmdClassAddr, cmdAddr, sc_type_arc_pos_const_perm)) { mMemoryCtx.eraseElement(startArcAddr); ScAddr progressAddr = mMemoryCtx.createEdge(sc_type_arc_pos_const_perm, msCommandProgressdAddr, cmdAddr); assert(progressAddr.isValid()); ScAddr resultAddr = mMemoryCtx.createNode(sc_type_const | sc_type_node_struct); assert(resultAddr.isValid()); runImpl(cmdAddr, resultAddr); mMemoryCtx.eraseElement(progressAddr); ScAddr const commonArc = mMemoryCtx.createEdge(sc_type_const | sc_type_arc_common, cmdAddr, resultAddr); assert(commonArc.isValid()); ScAddr const arc = mMemoryCtx.createEdge(sc_type_arc_pos_const_perm, msNrelResult, commonArc); assert(arc.isValid()); mMemoryCtx.createEdge(sc_type_arc_pos_const_perm, msCommandFinishedAddr, cmdAddr); return SC_RESULT_OK; } } return SC_RESULT_ERROR; }
void setMass(ScMemoryContext & ctx, ScAddr const & objAddr, ScAddr const & valueAddr) { ScAddr massAddr; ScIterator5Ptr itMass = ctx.iterator5(objAddr, SC_TYPE(sc_type_arc_common | sc_type_const), SC_TYPE(sc_type_const | sc_type_node | sc_type_node_abstract), SC_TYPE(sc_type_arc_pos_const_perm), Keynodes::nrel_mass); /// TODO: check if there is a more than one result if (itMass->next()) { massAddr = itMass->value(2); } else { massAddr = ctx.createNode(sc_type_const | sc_type_node_abstract); assert(massAddr.isValid()); ScAddr arcCommon = ctx.createArc(sc_type_const | sc_type_arc_common, objAddr, massAddr); assert(arcCommon.isValid()); ScAddr arc = ctx.createArc(sc_type_arc_pos_const_perm, Keynodes::nrel_mass, arcCommon); assert(arc.isValid()); } ScIterator5Ptr itValue = ctx.iterator5(massAddr, SC_TYPE(sc_type_arc_pos_const_perm), SC_TYPE(sc_type_link), SC_TYPE(sc_type_arc_pos_const_perm), Keynodes::rrel_gram); if (itValue->next()) { ScAddr linkAddr = itValue->value(2); ScStream stream; bool res = ctx.getLinkContent(valueAddr, stream); assert(res); res = ctx.setLinkContent(linkAddr, stream); assert(res); } else { ScAddr arc = ctx.createArc(sc_type_arc_pos_const_perm, massAddr, valueAddr); assert(arc.isValid()); arc = ctx.createArc(sc_type_arc_pos_const_perm, Keynodes::rrel_gram, arc); assert(arc.isValid()); } }
bool addToSet(ScMemoryContext & ctx, ScAddr const & setAddr, ScAddr const & elAddr) { if (ctx.helperCheckArc(setAddr, elAddr, sc_type_arc_pos_const_perm)) return false; ScAddr arcAddr = ctx.createArc(sc_type_arc_pos_const_perm, setAddr, elAddr); assert(arcAddr.isValid()); return true; }
bool ScStruct::append(ScAddr const & elAddr, ScAddr const & attrAddr) { check_expr(mContext); if (!hasElement(elAddr)) { ScAddr const edge = mContext->createEdge(sc_type_arc_pos_const_perm, mAddr, elAddr); if (edge.isValid()) { ScAddr const edge2 = mContext->createEdge(sc_type_arc_pos_const_perm, attrAddr, edge); if (edge2.isValid()) return true; // cleanup mContext->eraseElement(edge); } } return false; }
bool ScMemoryContext::helperResolveSystemIdtf(std::string const & sysIdtf, ScAddr & outAddr, bool bForceCreation /*= false*/) { check_expr(isValid()); outAddr.reset(); bool result = helperFindBySystemIdtf(sysIdtf, outAddr); if (!result && bForceCreation) { outAddr = createNode(sc_type_const); if (outAddr.isValid()) result = helperSetSystemIdtf(sysIdtf, outAddr); } return result; }
ScIterator3Ptr createIterator(ScTemplateConstr3 const & constr) { ScTemplateItemValue const * values = constr.getValues(); ScTemplateItemValue const & value0 = values[0]; ScTemplateItemValue const & value1 = values[1]; ScTemplateItemValue const & value2 = values[2]; ScAddr const addr0 = resolveAddr(value0); ScAddr const addr1 = resolveAddr(value1); ScAddr const addr2 = resolveAddr(value2); if (addr0.isValid()) { if (addr2.isValid()) // F_A_F { return mContext.iterator3(addr0, *value1.mTypeValue.upConstType(), addr2); } else // F_A_A { return mContext.iterator3(addr0, *value1.mTypeValue.upConstType(), *value2.mTypeValue.upConstType()); } } else if (addr2.isValid()) // A_A_F { return mContext.iterator3(*value0.mTypeValue.upConstType(), *value1.mTypeValue.upConstType(), addr2); } else if (addr1.isValid()) // A_F_A { return mContext.iterator3(*value0.mTypeValue.upConstType(), addr1, *value2.mTypeValue.upConstType()); } else // unknown iterator type { error("Unknown iterator type"); } return ScIterator3Ptr(); }
std::string ScMemoryContext::helperGetSystemIdtf(ScAddr const & addr) { check_expr(isValid()); ScAddr idtfLink; if (sc_helper_get_system_identifier_link(mContext, *addr, &idtfLink.mRealAddr) == SC_RESULT_OK) { if (idtfLink.isValid()) { ScStream stream; if (getLinkContent(idtfLink, stream)) { std::string result; if (StreamConverter::streamToString(stream, result)) { return result; } } } } return std::string(""); }