UUID AtomSpace_addNode( AtomSpace* this_ptr , const char* type , const char* name ) { Type t = classserver().getType(std::string(type)); if(t == NOTYPE) throw InvalidParamException(TRACE_INFO, "Invalid AtomType parameter '%s'.",type); return this_ptr->add_node(t,std::string(name)).value(); }
int AtomSpace_getNode( AtomSpace* this_ptr , const char* type , const char* name , UUID* uuid_out ) { Type t = classserver().getType(std::string(type)); if(t == NOTYPE) throw InvalidParamException(TRACE_INFO, "Invalid AtomType parameter '%s'.",type); Handle h = this_ptr->get_node(t,std::string(name)); *uuid_out = h.value(); return h == Handle::UNDEFINED; }
UUID AtomSpace_addLink( AtomSpace* this_ptr , const char* type , const UUID* outgoing , int size ) { Type t = classserver().getType(std::string(type)); if(t == NOTYPE) throw InvalidParamException(TRACE_INFO, "Invalid AtomType parameter '%s'.",type); HandleSeq oset; for(int i=0;i<size;i++) oset.push_back(Handle(outgoing[i])); return this_ptr->add_link(t,oset).value(); }
int FloatValue_toRaw(FloatValuePtr ptr , char** valuetype , double* parameters) { const std::string & type = classserver().getTypeName(ptr->get_type()); *valuetype = (char*) malloc(sizeof(char) * (type.length()+1)); if(! *valuetype) throw RuntimeException(TRACE_INFO,"Failed malloc."); std::strcpy(*valuetype, type.c_str()); const std::vector<double> val = ptr->value(); std::copy(val.begin(),val.end(),parameters); return 0; }
int AtomSpace_getLink( AtomSpace* this_ptr , const char* type , const UUID* outgoing , int size , UUID* uuid_out ) { Type t = classserver().getType(std::string(type)); if(t == NOTYPE) throw InvalidParamException(TRACE_INFO, "Invalid AtomType parameter '%s'.",type); HandleSeq oset; for(int i=0;i<size;i++) oset.push_back(Handle(outgoing[i])); Handle h = this_ptr->get_link(t,oset); *uuid_out = h.value(); return h == Handle::UNDEFINED; }
int AtomSpace_getAtomByUUID( AtomSpace* this_ptr , UUID uuid , int* node_or_link , char** type , char** name , UUID** out , int* out_len) { Handle h(uuid); if(!h) // Invalid UUID parameter. return -1; const std::string &str = classserver().getTypeName(h->getType()); *type = (char*) malloc(sizeof(char) * (str.length()+1)); if(! *type) throw RuntimeException(TRACE_INFO,"Failed malloc."); std::strcpy(*type, str.c_str()); NodePtr ptr = NodeCast(h); if(ptr){ // It is a node. *node_or_link = 1; const std::string &str = ptr->getName(); *name = (char*) malloc(sizeof(char) * (str.length()+1)); if(! *name) throw RuntimeException(TRACE_INFO,"Failed malloc."); std::strcpy(*name, str.c_str()); return 0; }else{ // It is a link. *node_or_link = 0; LinkPtr lnk = LinkCast(h); if(!lnk) throw RuntimeException(TRACE_INFO,"Error in cast Link."); *out_len = lnk->getArity(); *out = (UUID*) malloc(sizeof(UUID) * (*out_len)); if(! *out) throw RuntimeException(TRACE_INFO,"Failed malloc."); int i; for(i=0;i<(*out_len);i++) (*out)[i]=lnk->getOutgoingAtom(i).value(); return 0; } }
int AtomSpace_getAtomByHandle( AtomSpace* this_ptr , UUID handle , char** type , char** name , UUID** out , int* out_len) { Handle h(handle); if(!h) throw InvalidParamException(TRACE_INFO, "Invalid Handler parameter."); const std::string &str = classserver().getTypeName(h->getType()); (*type) = (char*) malloc(sizeof(char) * (str.length()+1)); if(!(*type)) throw RuntimeException(TRACE_INFO,"Failed malloc."); std::strcpy(*type, str.c_str()); NodePtr ptr = NodeCast(h); if(ptr){//It is a node. const std::string &str = ptr->getName(); (*name) = (char*) malloc(sizeof(char) * (str.length()+1)); if(!(*name)) throw RuntimeException(TRACE_INFO,"Failed malloc."); std::strcpy(*name, str.c_str()); return 1; }else{//It is a link. LinkPtr lnk = LinkCast(h); if(!lnk) throw RuntimeException(TRACE_INFO,"Error in cast Link."); *out_len=lnk->getArity(); (*out) = (UUID*) malloc(sizeof(UUID) * (*out_len)); if(!(*out)) throw RuntimeException(TRACE_INFO,"Failed malloc."); int i; for(i=0;i<(*out_len);i++) (*out)[i]=lnk->getOutgoingAtom(i).value(); return 0; } }
int FloatValue_setOnAtom( Handle* atom , Handle* key , const char* valuetype , double* parameters , int length) { Handle a = *atom; Handle k = *key; if(a == Handle::UNDEFINED || k == Handle::UNDEFINED) return -1; Type type = classserver().getType(std::string(valuetype)); std::vector<double> vec(parameters,parameters+length); ProtoAtomPtr ptr = createFloatValue(type,vec); if (ptr == NULL) return -1; a->setValue(k,ptr); return 0; }