// Please refer to the COPYRIGHT file of the profiling package for details. // SPDX-License-Identifier: MIT #ifndef GAP_HELPER_PNFRE #define GAP_HELPER_PNFRE
// Yes, this is useful. It lets someone turn a GAP vector into a // vec1<Obj>, without having to worry about GAP vector functions // any more. template<> struct GAP_getter<Obj>
{ bool isa(Obj) const
{ returntrue; }
template<typename Con>
Con fill_container(Obj rec)
{ if(!(IS_SMALL_LIST(rec))) throw GAPException("Invalid attempt to read list"); int len = LEN_LIST(rec);
Con v; typedeftypename Con::value_type T;
GAP_getter<T> getter; for(int i = 1; i <= len; ++i)
{
v.push_back(getter(ELM_LIST(rec, i)));
} return v;
}
// This case, and next one, handle arrays with and without holes template<typename T> struct GAP_getter<vec1<T> >
{ bool isa(Obj recval) const
{ return IS_SMALL_LIST(recval); }
template<typename Con, typename T>
Con fill_optional_container(Obj rec)
{ if(!(IS_SMALL_LIST(rec))) throw GAPException("Invalid attempt to read list"); int len = LEN_LIST(rec);
Con v;
GAP_getter<T> getter; for(int i = 1; i <= len; ++i)
{ if(ISB_LIST(rec, i))
{ v.push_back(getter(ELM_LIST(rec, i))); } else
{ v.push_back(optional<T>()); }
} return v;
}
Obj GAP_get_rec(Obj rec, UInt n)
{ if(!IS_REC(rec)) throw GAPException("Invalid attempt to read record"); if(!ISB_REC(rec, n)) throw GAPException(std::string("Unable to read value from rec")); return ELM_REC(rec, n);
}
// This is a special method. It gets a boolean from a record, and assumes // it is 'false' if not present bool GAP_get_maybe_bool_rec(Obj rec, UInt n)
{ if(!IS_REC(rec)) throw GAPException("Invalid attempt to read record"); if(!ISB_REC(rec, n)) returnfalse;
Obj b = ELM_REC(rec, n); if(b == True) returntrue; if(b == False) returnfalse; throw GAPException("Record element is not a boolean");
}
Obj GAP_getGlobal(constchar* name)
{
UInt i = GVarName(name);
Obj o = VAL_GVAR(i); if(!o) throw GAPException("Missing global : " + std::string(name)); return o;
}
// We would use CALL_0ARGS and friends here, but in C++ // we have to be more explicit with the types of our functions.
Obj GAP_callFunction(GAPFunction fun)
{ return CALL_0ARGS(fun.getObj());
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.