本文整理汇总了C++中TypeError函数的典型用法代码示例。如果您正苦于以下问题:C++ TypeError函数的具体用法?C++ TypeError怎么用?C++ TypeError使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TypeError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: extra_kwargs
[[noreturn]]
static void extra_kwargs(FunctionSignature& signature, PyObject* kwargs, ssize_t num_pos_args) {
PyObject *key, *value;
ssize_t pos = 0;
while (PyDict_Next(kwargs, &pos, &key, &value)) {
if (!THPUtils_checkString(key)) {
throw TypeError("keywords must be strings");
}
auto param_idx = find_param(signature, key);
if (param_idx < 0) {
throw TypeError("%s() got an unexpected keyword argument '%s'",
signature.name.c_str(), THPUtils_unpackString(key).c_str());
}
if (param_idx < num_pos_args) {
throw TypeError("%s() got multiple values for argument '%s'",
signature.name.c_str(), THPUtils_unpackString(key).c_str());
}
}
// this should never be hit
throw TypeError("invalid keyword arguments");
}
示例2: create_Group
PyObject* create_Group(PyObject* args){
if (PySequence_Length(args) == 0){
throw TypeError("A group must contain at least one object");
}
// Use either the function arguments as the sequence of objects, or
// a single sequence-argument as the sequence. i.e. allow both
// Group(a, b, c, d) and Group([a,b,c,d])
PyObject* sequence = (PySequence_Length(args) == 1 &&
PySequence_Check(PySequence_GetItem(args, 0))) ?
PySequence_GetItem(args, 0) :
args;
const auto n = PySequence_Length(sequence);
// Prevent empty seguence arguments groups, i.e. Group([])
if (n == 0){
throw TypeError("A group must contain at least one object.");
}
objects_t faintObjects;
for (int i = 0; i != n; i++){
PyObject* object = PySequence_GetItem(sequence, i);
if (!PyObject_IsInstance(object, (PyObject*)&ShapeType)){
throw TypeError("Unsupported item in list");
}
faintObjects.push_back(proxy_shape(object));
}
Object* group = create_composite_object_raw(faintObjects, Ownership::OWNER);
return create_Shape(group);
}
示例3: getNumber2
Time Time::fromIso(const std::string& s)
{
Time ret;
const char* d = s.data();
try
{
if (s.size() == 12
&& d[2] == ':'
&& d[5] == ':'
&& d[8] == '.')
{
ret.set(getNumber2(d), getNumber2(d + 3), getNumber2(d + 6),
getNumber3(d + 9));
}
else if (s.size() == 8
&& d[2] == ':'
&& d[5] == ':')
{
ret.set(getNumber2(d), getNumber2(d + 3), getNumber2(d + 6));
}
else
throw TypeError();
}
catch (const TypeError&)
{
throw TypeError("failed to convert string \"" + s + "\" into time");
}
return ret;
}
示例4: extra_args
[[noreturn]]
static void extra_args(const FunctionSignature& signature, ssize_t nargs) {
auto max_pos_args = signature.max_pos_args;
auto min_args = signature.min_args;
if (min_args != max_pos_args) {
throw TypeError("%s() takes from %d to %d positional arguments but %d were given",
signature.name.c_str(), min_args, max_pos_args, nargs);
}
throw TypeError("%s() takes %d positional argument%s but %d %s given",
signature.name.c_str(),
max_pos_args, max_pos_args == 1 ? "" : "s",
nargs, nargs == 1 ? "was" : "were");
}
示例5: doArrayAssign
struct InstrSeq * doArrayAssign( char * name, struct ExprRes * index, struct ExprRes * val){
struct SymEntry *e;
if( global ){
e = FindName(locTable, name);
if( !e){
e = FindName(table, name);
}
}
else{
e = FindName(table, name);
}
struct Vtype * vtype = ((struct Vtype *)e->Attributes);
struct InstrSeq * code;
int reg = AvailTmpReg();
char * buffer;
if (!e){
WriteIndicator(GetCurrentColumn());
WriteMessage("Undeclared variable");
}
if(index->Type != TYPE_INT){
TypeError();
}
else if( val->Type != -1 && ((vtype->Type == TYPE_BOOLARR && val->Type != TYPE_BOOL) || (vtype->Type == TYPE_INTARR && val->Type != TYPE_INT ))){
TypeError();
}
buffer = RegOff(0, TmpRegName(reg));
code = val->Instrs;
AppendSeq(code, index->Instrs);
// change for locality later
if (! vtype->Local){
AppendSeq( code, GenInstr( NULL, "la", TmpRegName(reg), name, NULL));
}
else {
AppendSeq(code, GenInstr(NULL, "addi", TmpRegName(reg), "$sp", Imm(vtype->StackIndex)));
}
AppendSeq( code, GenInstr( NULL, "mul", TmpRegName(index->Reg), TmpRegName(index->Reg), "4"));
AppendSeq( code, GenInstr(NULL, "add", TmpRegName(reg), TmpRegName(reg), TmpRegName(index->Reg)));
AppendSeq( code, GenInstr(NULL, "sw", TmpRegName(val->Reg), buffer, NULL));
ReleaseTmpReg(val->Reg);
ReleaseTmpReg(index->Reg);
ReleaseTmpReg(reg);
free(val);
free(index);
return code;
}
示例6: Shape_get_text_height
/* method: "get_text_height(s)\n
Fixme!" */
static coord Shape_get_text_height(const Object& self){
auto txt = dynamic_cast<const ObjText*>(&self);
if (txt == nullptr){
throw TypeError("This object does not have text attributes.");
}
return txt->RowHeight();
}
示例7: doPrintsp
struct InstrSeq * doPrintsp(struct ExprRes * Expr){
if(Expr->Type != TYPE_INT){
TypeError();
}
struct InstrSeq * code;
code = Expr->Instrs;
char * end = GenLabel();
char * next = GenLabel();
int i = AvailTmpReg();
int one = AvailTmpReg();
AppendSeq(code, GenInstr(NULL, "addi", TmpRegName(one), "$0", "1"));
AppendSeq(code, GenInstr(NULL, "blt", TmpRegName(Expr->Reg), "$0", end));
AppendSeq(code, GenInstr(NULL, "li", TmpRegName(i), "0", NULL));
AppendSeq(code, GenInstr(next, NULL,NULL,NULL,NULL));
AppendSeq(code, GenInstr(NULL, "li", "$v0", "4", NULL));
AppendSeq(code, GenInstr(NULL, "la", "$a0", "_sp", NULL));
AppendSeq(code, GenInstr(NULL, "syscall", NULL, NULL,NULL));
AppendSeq(code, GenInstr(NULL, "addi", TmpRegName(i), TmpRegName(i), "1"));
AppendSeq(code, GenInstr(NULL, "blt", TmpRegName(i), TmpRegName(Expr->Reg), next));
AppendSeq(code, GenInstr(end, NULL,NULL,NULL,NULL));
ReleaseTmpReg(i);
ReleaseTmpReg(one);
ReleaseTmpReg(Expr->Reg);
free(Expr);
free(end);
free(next);
return code;
}
示例8: asgn_op
int asgn_op ( )
{
descriptor *src;
descriptor *dest;
int status;
src = pop ( );
dest = top ( );
src = deref (src);
if (!assignable (dest)) {
TypeError ("cannot assign to", NULL, dest, NULL, F_False);
RecycleData (src);
return 1;
}
dest = deref (dest);
src = CollapseMatrix (src);
status = AssignData (dest, &src);
RecycleData (src);
D_Temp (dest) = F_False;
return status;
}
示例9: TypeError
inline void
Node::append(Node* newNode) {
Array* a = dynamic_cast<Array*>(this);
if (!a)
throw TypeError("array expected");
a->a.push_back(newNode);
}
示例10: TypeError
void Exception::type_error(STATE, object_type type, Object* object,
const char* reason) {
// We code for TypeError being raised defensively, so it's ok, to raise it
// since someone close by will catch it and propogate it back to ruby
// properly.
throw TypeError(type, object, reason);
}
示例11: TypeError
//
// operator Value * Value
//
Value operator * (Value const &l, Value const &r)
{
if(l.v == ValueBase::Fixed && r.v == ValueBase::Fixed) return l.vFixed * r.vFixed;
if(l.v == ValueBase::Float && r.v == ValueBase::Float) return l.vFloat * r.vFloat;
throw TypeError();
}
示例12: SnapPoint_cf
Value*
SnapPoint_cf(Value** arg_list, int count)
{
check_arg_count_with_keys(SnapPoint, 1, count);
def_snap_types();
IPoint2 out;
IPoint2 loc = to_ipoint2(arg_list[0]);
Value *val = key_arg(snapType);
int flags = (val == &unsupplied) ? 0 : GetID(snapTypes, elements(snapTypes), val);
Value *snapPlane = key_arg(snapPlane);
Matrix3* plane = NULL;
if (snapPlane != &unsupplied) {
if (!snapPlane->is_kind_of(class_tag(Matrix3Value)))
throw TypeError (_T("snapPlane requires a Matrix3 value"), snapPlane);
Matrix3Value* mv = static_cast<Matrix3Value*>(snapPlane);
plane = new Matrix3(mv->m);
}
Point3 ret = MAXScript_interface->GetActiveViewExp().SnapPoint(loc, out, plane, flags);
if (plane != NULL)
delete plane;
return new Point3Value(ret);
}
示例13: PyTuple_GET_SIZE
void PythonArgParser::print_error(PyObject* args, PyObject* kwargs, PyObject* parsed_args[]) {
auto num_args = PyTuple_GET_SIZE(args) + (kwargs ? PyDict_Size(kwargs) : 0);
std::vector<int> plausible_idxs;
ssize_t i = 0;
for (auto& signature : signatures_) {
if (num_args >= signature.min_args && num_args <= signature.max_args && !signature.hidden) {
plausible_idxs.push_back(i);
}
i++;
}
if (plausible_idxs.size() == 1) {
auto& signature = signatures_[plausible_idxs[0]];
signature.parse(args, kwargs, parsed_args, true);
}
std::vector<std::string> options;
for (auto& signature : signatures_) {
if (!signature.hidden) {
options.push_back(signature.toString());
}
}
auto msg = torch::format_invalid_args(args, kwargs, function_name + "()", options);
throw TypeError("%s", msg.c_str());
}
示例14: TypeError
T object<Ops>::require() const
{
if (!check<T>())
throw TypeError(type());
return T(id());
}
示例15: getNumber2
inline unsigned short getNumber2(const char* s)
{
if (!std::isdigit(s[0])
|| !std::isdigit(s[1]))
throw TypeError();
return (s[0] - '0') * 10
+ (s[1] - '0');
}